1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /* Copyright(c) 2018-2019 Realtek Corporation
5 #include <linux/module.h>
13 #include "rtw8822c_table.h"
21 #define IQK_DONE_8822C 0xaa
23 static void rtw8822c_config_trx_mode(struct rtw_dev
*rtwdev
, u8 tx_path
,
24 u8 rx_path
, bool is_tx2_path
);
26 static void rtw8822ce_efuse_parsing(struct rtw_efuse
*efuse
,
27 struct rtw8822c_efuse
*map
)
29 ether_addr_copy(efuse
->addr
, map
->e
.mac_addr
);
32 static int rtw8822c_read_efuse(struct rtw_dev
*rtwdev
, u8
*log_map
)
34 struct rtw_efuse
*efuse
= &rtwdev
->efuse
;
35 struct rtw8822c_efuse
*map
;
38 map
= (struct rtw8822c_efuse
*)log_map
;
40 efuse
->rfe_option
= map
->rfe_option
;
41 efuse
->rf_board_option
= map
->rf_board_option
;
42 efuse
->crystal_cap
= map
->xtal_k
;
43 efuse
->channel_plan
= map
->channel_plan
;
44 efuse
->country_code
[0] = map
->country_code
[0];
45 efuse
->country_code
[1] = map
->country_code
[1];
46 efuse
->bt_setting
= map
->rf_bt_setting
;
47 efuse
->regd
= map
->rf_board_option
& 0x7;
48 efuse
->thermal_meter
[RF_PATH_A
] = map
->path_a_thermal
;
49 efuse
->thermal_meter
[RF_PATH_B
] = map
->path_b_thermal
;
50 efuse
->thermal_meter_k
=
51 (map
->path_a_thermal
+ map
->path_b_thermal
) >> 1;
52 efuse
->power_track_type
= (map
->tx_pwr_calibrate_rate
>> 4) & 0xf;
54 for (i
= 0; i
< 4; i
++)
55 efuse
->txpwr_idx_table
[i
] = map
->txpwr_idx_table
[i
];
57 switch (rtw_hci_type(rtwdev
)) {
58 case RTW_HCI_TYPE_PCIE
:
59 rtw8822ce_efuse_parsing(efuse
, map
);
69 static void rtw8822c_header_file_init(struct rtw_dev
*rtwdev
, bool pre
)
71 rtw_write32_set(rtwdev
, REG_3WIRE
, BIT_3WIRE_TX_EN
| BIT_3WIRE_RX_EN
);
72 rtw_write32_set(rtwdev
, REG_3WIRE
, BIT_3WIRE_PI_ON
);
73 rtw_write32_set(rtwdev
, REG_3WIRE2
, BIT_3WIRE_TX_EN
| BIT_3WIRE_RX_EN
);
74 rtw_write32_set(rtwdev
, REG_3WIRE2
, BIT_3WIRE_PI_ON
);
77 rtw_write32_clr(rtwdev
, REG_ENCCK
, BIT_CCK_OFDM_BLK_EN
);
79 rtw_write32_set(rtwdev
, REG_ENCCK
, BIT_CCK_OFDM_BLK_EN
);
82 static void rtw8822c_dac_backup_reg(struct rtw_dev
*rtwdev
,
83 struct rtw_backup_info
*backup
,
84 struct rtw_backup_info
*backup_rf
)
89 u32 rf_addr
[DACK_RF_8822C
] = {0x8f};
90 u32 addrs
[DACK_REG_8822C
] = {0x180c, 0x1810, 0x410c, 0x4110,
91 0x1c3c, 0x1c24, 0x1d70, 0x9b4,
92 0x1a00, 0x1a14, 0x1d58, 0x1c38,
93 0x1e24, 0x1e28, 0x1860, 0x4160};
95 for (i
= 0; i
< DACK_REG_8822C
; i
++) {
97 backup
[i
].reg
= addrs
[i
];
98 backup
[i
].val
= rtw_read32(rtwdev
, addrs
[i
]);
101 for (path
= 0; path
< DACK_PATH_8822C
; path
++) {
102 for (i
= 0; i
< DACK_RF_8822C
; i
++) {
104 val
= rtw_read_rf(rtwdev
, path
, reg
, RFREG_MASK
);
105 backup_rf
[path
* i
+ i
].reg
= reg
;
106 backup_rf
[path
* i
+ i
].val
= val
;
111 static void rtw8822c_dac_restore_reg(struct rtw_dev
*rtwdev
,
112 struct rtw_backup_info
*backup
,
113 struct rtw_backup_info
*backup_rf
)
119 rtw_restore_reg(rtwdev
, backup
, DACK_REG_8822C
);
121 for (path
= 0; path
< DACK_PATH_8822C
; path
++) {
122 for (i
= 0; i
< DACK_RF_8822C
; i
++) {
123 val
= backup_rf
[path
* i
+ i
].val
;
124 reg
= backup_rf
[path
* i
+ i
].reg
;
125 rtw_write_rf(rtwdev
, path
, reg
, RFREG_MASK
, val
);
130 static void rtw8822c_rf_minmax_cmp(struct rtw_dev
*rtwdev
, u32 value
,
133 if (value
>= 0x200) {
159 static void __rtw8822c_dac_iq_sort(struct rtw_dev
*rtwdev
, u32
*v1
, u32
*v2
)
161 if (*v1
>= 0x200 && *v2
>= 0x200) {
164 } else if (*v1
< 0x200 && *v2
< 0x200) {
167 } else if (*v1
< 0x200 && *v2
>= 0x200) {
172 static void rtw8822c_dac_iq_sort(struct rtw_dev
*rtwdev
, u32
*iv
, u32
*qv
)
176 for (i
= 0; i
< DACK_SN_8822C
- 1; i
++) {
177 for (j
= 0; j
< (DACK_SN_8822C
- 1 - i
) ; j
++) {
178 __rtw8822c_dac_iq_sort(rtwdev
, &iv
[j
], &iv
[j
+ 1]);
179 __rtw8822c_dac_iq_sort(rtwdev
, &qv
[j
], &qv
[j
+ 1]);
184 static void rtw8822c_dac_iq_offset(struct rtw_dev
*rtwdev
, u32
*vec
, u32
*val
)
190 for (i
= 10; i
< DACK_SN_8822C
- 10; i
++) {
192 m
= (0x400 - vec
[i
]) + m
;
199 t
= t
/ (DACK_SN_8822C
- 20);
202 t
= t
/ (DACK_SN_8822C
- 20);
210 static u32
rtw8822c_get_path_write_addr(u8 path
)
229 static u32
rtw8822c_get_path_read_addr(u8 path
)
248 static bool rtw8822c_dac_iq_check(struct rtw_dev
*rtwdev
, u32 value
)
252 if ((value
>= 0x200 && (0x400 - value
) > 0x64) ||
253 (value
< 0x200 && value
> 0x64)) {
255 rtw_dbg(rtwdev
, RTW_DBG_RFK
, "[DACK] Error overflow\n");
261 static void rtw8822c_dac_cal_iq_sample(struct rtw_dev
*rtwdev
, u32
*iv
, u32
*qv
)
266 while (i
< DACK_SN_8822C
&& cnt
< 10000) {
268 temp
= rtw_read32_mask(rtwdev
, 0x2dbc, 0x3fffff);
269 iv
[i
] = (temp
& 0x3ff000) >> 12;
270 qv
[i
] = temp
& 0x3ff;
272 if (rtw8822c_dac_iq_check(rtwdev
, iv
[i
]) &&
273 rtw8822c_dac_iq_check(rtwdev
, qv
[i
]))
278 static void rtw8822c_dac_cal_iq_search(struct rtw_dev
*rtwdev
,
280 u32
*i_value
, u32
*q_value
)
282 u32 i_max
= 0, q_max
= 0, i_min
= 0, q_min
= 0;
283 u32 i_delta
, q_delta
;
292 for (i
= 0; i
< DACK_SN_8822C
; i
++) {
293 rtw8822c_rf_minmax_cmp(rtwdev
, iv
[i
], &i_min
, &i_max
);
294 rtw8822c_rf_minmax_cmp(rtwdev
, qv
[i
], &q_min
, &q_max
);
297 if (i_max
< 0x200 && i_min
< 0x200)
298 i_delta
= i_max
- i_min
;
299 else if (i_max
>= 0x200 && i_min
>= 0x200)
300 i_delta
= i_max
- i_min
;
302 i_delta
= i_max
+ (0x400 - i_min
);
304 if (q_max
< 0x200 && q_min
< 0x200)
305 q_delta
= q_max
- q_min
;
306 else if (q_max
>= 0x200 && q_min
>= 0x200)
307 q_delta
= q_max
- q_min
;
309 q_delta
= q_max
+ (0x400 - q_min
);
311 rtw_dbg(rtwdev
, RTW_DBG_RFK
,
312 "[DACK] i: min=0x%08x, max=0x%08x, delta=0x%08x\n",
313 i_min
, i_max
, i_delta
);
314 rtw_dbg(rtwdev
, RTW_DBG_RFK
,
315 "[DACK] q: min=0x%08x, max=0x%08x, delta=0x%08x\n",
316 q_min
, q_max
, q_delta
);
318 rtw8822c_dac_iq_sort(rtwdev
, iv
, qv
);
320 if (i_delta
> 5 || q_delta
> 5) {
321 temp
= rtw_read32_mask(rtwdev
, 0x2dbc, 0x3fffff);
322 iv
[0] = (temp
& 0x3ff000) >> 12;
323 qv
[0] = temp
& 0x3ff;
324 temp
= rtw_read32_mask(rtwdev
, 0x2dbc, 0x3fffff);
325 iv
[DACK_SN_8822C
- 1] = (temp
& 0x3ff000) >> 12;
326 qv
[DACK_SN_8822C
- 1] = temp
& 0x3ff;
330 } while (cnt
++ < 100);
332 rtw8822c_dac_iq_offset(rtwdev
, iv
, i_value
);
333 rtw8822c_dac_iq_offset(rtwdev
, qv
, q_value
);
336 static void rtw8822c_dac_cal_rf_mode(struct rtw_dev
*rtwdev
,
337 u32
*i_value
, u32
*q_value
)
339 u32 iv
[DACK_SN_8822C
], qv
[DACK_SN_8822C
];
342 rf_a
= rtw_read_rf(rtwdev
, RF_PATH_A
, 0x0, RFREG_MASK
);
343 rf_b
= rtw_read_rf(rtwdev
, RF_PATH_B
, 0x0, RFREG_MASK
);
345 rtw_dbg(rtwdev
, RTW_DBG_RFK
, "[DACK] RF path-A=0x%05x\n", rf_a
);
346 rtw_dbg(rtwdev
, RTW_DBG_RFK
, "[DACK] RF path-B=0x%05x\n", rf_b
);
348 rtw8822c_dac_cal_iq_sample(rtwdev
, iv
, qv
);
349 rtw8822c_dac_cal_iq_search(rtwdev
, iv
, qv
, i_value
, q_value
);
352 static void rtw8822c_dac_bb_setting(struct rtw_dev
*rtwdev
)
354 rtw_write32_mask(rtwdev
, 0x1d58, 0xff8, 0x1ff);
355 rtw_write32_mask(rtwdev
, 0x1a00, 0x3, 0x2);
356 rtw_write32_mask(rtwdev
, 0x1a14, 0x300, 0x3);
357 rtw_write32(rtwdev
, 0x1d70, 0x7e7e7e7e);
358 rtw_write32_mask(rtwdev
, 0x180c, 0x3, 0x0);
359 rtw_write32_mask(rtwdev
, 0x410c, 0x3, 0x0);
360 rtw_write32(rtwdev
, 0x1b00, 0x00000008);
361 rtw_write8(rtwdev
, 0x1bcc, 0x3f);
362 rtw_write32(rtwdev
, 0x1b00, 0x0000000a);
363 rtw_write8(rtwdev
, 0x1bcc, 0x3f);
364 rtw_write32_mask(rtwdev
, 0x1e24, BIT(31), 0x0);
365 rtw_write32_mask(rtwdev
, 0x1e28, 0xf, 0x3);
368 static void rtw8822c_dac_cal_adc(struct rtw_dev
*rtwdev
,
369 u8 path
, u32
*adc_ic
, u32
*adc_qc
)
371 struct rtw_dm_info
*dm_info
= &rtwdev
->dm_info
;
372 u32 ic
= 0, qc
= 0, temp
= 0;
377 rtw_dbg(rtwdev
, RTW_DBG_RFK
, "[DACK] ADCK path(%d)\n", path
);
379 base_addr
= rtw8822c_get_path_write_addr(path
);
393 rtw_write32_mask(rtwdev
, base_addr
+ 0x30, BIT(30), 0x0);
394 if (path
== RF_PATH_B
)
395 rtw_write32(rtwdev
, base_addr
+ 0x30, 0x30db8041);
396 rtw_write32(rtwdev
, base_addr
+ 0x60, 0xf0040ff0);
397 rtw_write32(rtwdev
, base_addr
+ 0x0c, 0xdff00220);
398 rtw_write32(rtwdev
, base_addr
+ 0x10, 0x02dd08c4);
399 rtw_write32(rtwdev
, base_addr
+ 0x0c, 0x10000260);
400 rtw_write_rf(rtwdev
, RF_PATH_A
, 0x0, RFREG_MASK
, 0x10000);
401 rtw_write_rf(rtwdev
, RF_PATH_B
, 0x0, RFREG_MASK
, 0x10000);
402 for (i
= 0; i
< 10; i
++) {
403 rtw_dbg(rtwdev
, RTW_DBG_RFK
, "[DACK] ADCK count=%d\n", i
);
404 rtw_write32(rtwdev
, 0x1c3c, path_sel
+ 0x8003);
405 rtw_write32(rtwdev
, 0x1c24, 0x00010002);
406 rtw8822c_dac_cal_rf_mode(rtwdev
, &ic
, &qc
);
407 rtw_dbg(rtwdev
, RTW_DBG_RFK
,
408 "[DACK] before: i=0x%x, q=0x%x\n", ic
, qc
);
410 /* compensation value */
419 temp
= (ic
& 0x3ff) | ((qc
& 0x3ff) << 10);
420 rtw_write32(rtwdev
, base_addr
+ 0x68, temp
);
421 dm_info
->dack_adck
[path
] = temp
;
422 rtw_dbg(rtwdev
, RTW_DBG_RFK
, "[DACK] ADCK 0x%08x=0x08%x\n",
423 base_addr
+ 0x68, temp
);
424 /* check ADC DC offset */
425 rtw_write32(rtwdev
, 0x1c3c, path_sel
+ 0x8103);
426 rtw8822c_dac_cal_rf_mode(rtwdev
, &ic
, &qc
);
427 rtw_dbg(rtwdev
, RTW_DBG_RFK
,
428 "[DACK] after: i=0x%08x, q=0x%08x\n", ic
, qc
);
433 if (ic
< 5 && qc
< 5)
438 rtw_write32(rtwdev
, 0x1c3c, 0x00000003);
439 rtw_write32(rtwdev
, base_addr
+ 0x0c, 0x10000260);
440 rtw_write32(rtwdev
, base_addr
+ 0x10, 0x02d508c4);
442 /* release pull low switch on IQ path */
443 rtw_write_rf(rtwdev
, path
, 0x8f, BIT(13), 0x1);
446 static void rtw8822c_dac_cal_step1(struct rtw_dev
*rtwdev
, u8 path
)
448 struct rtw_dm_info
*dm_info
= &rtwdev
->dm_info
;
452 base_addr
= rtw8822c_get_path_write_addr(path
);
453 read_addr
= rtw8822c_get_path_read_addr(path
);
455 rtw_write32(rtwdev
, base_addr
+ 0x68, dm_info
->dack_adck
[path
]);
456 rtw_write32(rtwdev
, base_addr
+ 0x0c, 0xdff00220);
457 if (path
== RF_PATH_A
) {
458 rtw_write32(rtwdev
, base_addr
+ 0x60, 0xf0040ff0);
459 rtw_write32(rtwdev
, 0x1c38, 0xffffffff);
461 rtw_write32(rtwdev
, base_addr
+ 0x10, 0x02d508c5);
462 rtw_write32(rtwdev
, 0x9b4, 0xdb66db00);
463 rtw_write32(rtwdev
, base_addr
+ 0xb0, 0x0a11fb88);
464 rtw_write32(rtwdev
, base_addr
+ 0xbc, 0x0008ff81);
465 rtw_write32(rtwdev
, base_addr
+ 0xc0, 0x0003d208);
466 rtw_write32(rtwdev
, base_addr
+ 0xcc, 0x0a11fb88);
467 rtw_write32(rtwdev
, base_addr
+ 0xd8, 0x0008ff81);
468 rtw_write32(rtwdev
, base_addr
+ 0xdc, 0x0003d208);
469 rtw_write32(rtwdev
, base_addr
+ 0xb8, 0x60000000);
471 rtw_write32(rtwdev
, base_addr
+ 0xbc, 0x000aff8d);
473 rtw_write32(rtwdev
, base_addr
+ 0xb0, 0x0a11fb89);
474 rtw_write32(rtwdev
, base_addr
+ 0xcc, 0x0a11fb89);
476 rtw_write32(rtwdev
, base_addr
+ 0xb8, 0x62000000);
477 rtw_write32(rtwdev
, base_addr
+ 0xd4, 0x62000000);
479 if (!check_hw_ready(rtwdev
, read_addr
+ 0x08, 0x7fff80, 0xffff) ||
480 !check_hw_ready(rtwdev
, read_addr
+ 0x34, 0x7fff80, 0xffff))
481 rtw_err(rtwdev
, "failed to wait for dack ready\n");
482 rtw_write32(rtwdev
, base_addr
+ 0xb8, 0x02000000);
484 rtw_write32(rtwdev
, base_addr
+ 0xbc, 0x0008ff87);
485 rtw_write32(rtwdev
, 0x9b4, 0xdb6db600);
486 rtw_write32(rtwdev
, base_addr
+ 0x10, 0x02d508c5);
487 rtw_write32(rtwdev
, base_addr
+ 0xbc, 0x0008ff87);
488 rtw_write32(rtwdev
, base_addr
+ 0x60, 0xf0000000);
491 static void rtw8822c_dac_cal_step2(struct rtw_dev
*rtwdev
,
492 u8 path
, u32
*ic_out
, u32
*qc_out
)
495 u32 ic
, qc
, ic_in
, qc_in
;
497 base_addr
= rtw8822c_get_path_write_addr(path
);
498 rtw_write32_mask(rtwdev
, base_addr
+ 0xbc, 0xf0000000, 0x0);
499 rtw_write32_mask(rtwdev
, base_addr
+ 0xc0, 0xf, 0x8);
500 rtw_write32_mask(rtwdev
, base_addr
+ 0xd8, 0xf0000000, 0x0);
501 rtw_write32_mask(rtwdev
, base_addr
+ 0xdc, 0xf, 0x8);
503 rtw_write32(rtwdev
, 0x1b00, 0x00000008);
504 rtw_write8(rtwdev
, 0x1bcc, 0x03f);
505 rtw_write32(rtwdev
, base_addr
+ 0x0c, 0xdff00220);
506 rtw_write32(rtwdev
, base_addr
+ 0x10, 0x02d508c5);
507 rtw_write32(rtwdev
, 0x1c3c, 0x00088103);
509 rtw8822c_dac_cal_rf_mode(rtwdev
, &ic_in
, &qc_in
);
513 /* compensation value */
522 ic
= (0x400 - ic
) * 2 * 6 / 5;
529 qc
= (0x400 - qc
) * 2 * 6 / 5;
536 rtw_dbg(rtwdev
, RTW_DBG_RFK
, "[DACK] before i=0x%x, q=0x%x\n", ic_in
, qc_in
);
537 rtw_dbg(rtwdev
, RTW_DBG_RFK
, "[DACK] after i=0x%x, q=0x%x\n", ic
, qc
);
540 static void rtw8822c_dac_cal_step3(struct rtw_dev
*rtwdev
, u8 path
,
541 u32 adc_ic
, u32 adc_qc
,
542 u32
*ic_in
, u32
*qc_in
,
543 u32
*i_out
, u32
*q_out
)
550 base_addr
= rtw8822c_get_path_write_addr(path
);
551 read_addr
= rtw8822c_get_path_read_addr(path
);
555 rtw_write32(rtwdev
, base_addr
+ 0x0c, 0xdff00220);
556 rtw_write32(rtwdev
, base_addr
+ 0x10, 0x02d508c5);
557 rtw_write32(rtwdev
, 0x9b4, 0xdb66db00);
558 rtw_write32(rtwdev
, base_addr
+ 0xb0, 0x0a11fb88);
559 rtw_write32(rtwdev
, base_addr
+ 0xbc, 0xc008ff81);
560 rtw_write32(rtwdev
, base_addr
+ 0xc0, 0x0003d208);
561 rtw_write32_mask(rtwdev
, base_addr
+ 0xbc, 0xf0000000, ic
& 0xf);
562 rtw_write32_mask(rtwdev
, base_addr
+ 0xc0, 0xf, (ic
& 0xf0) >> 4);
563 rtw_write32(rtwdev
, base_addr
+ 0xcc, 0x0a11fb88);
564 rtw_write32(rtwdev
, base_addr
+ 0xd8, 0xe008ff81);
565 rtw_write32(rtwdev
, base_addr
+ 0xdc, 0x0003d208);
566 rtw_write32_mask(rtwdev
, base_addr
+ 0xd8, 0xf0000000, qc
& 0xf);
567 rtw_write32_mask(rtwdev
, base_addr
+ 0xdc, 0xf, (qc
& 0xf0) >> 4);
568 rtw_write32(rtwdev
, base_addr
+ 0xb8, 0x60000000);
570 rtw_write32_mask(rtwdev
, base_addr
+ 0xbc, 0xe, 0x6);
572 rtw_write32(rtwdev
, base_addr
+ 0xb0, 0x0a11fb89);
573 rtw_write32(rtwdev
, base_addr
+ 0xcc, 0x0a11fb89);
575 rtw_write32(rtwdev
, base_addr
+ 0xb8, 0x62000000);
576 rtw_write32(rtwdev
, base_addr
+ 0xd4, 0x62000000);
578 if (!check_hw_ready(rtwdev
, read_addr
+ 0x24, 0x07f80000, ic
) ||
579 !check_hw_ready(rtwdev
, read_addr
+ 0x50, 0x07f80000, qc
))
580 rtw_err(rtwdev
, "failed to write IQ vector to hardware\n");
581 rtw_write32(rtwdev
, base_addr
+ 0xb8, 0x02000000);
583 rtw_write32_mask(rtwdev
, base_addr
+ 0xbc, 0xe, 0x3);
584 rtw_write32(rtwdev
, 0x9b4, 0xdb6db600);
586 /* check DAC DC offset */
587 temp
= ((adc_ic
+ 0x10) & 0x3ff) | (((adc_qc
+ 0x10) & 0x3ff) << 10);
588 rtw_write32(rtwdev
, base_addr
+ 0x68, temp
);
589 rtw_write32(rtwdev
, base_addr
+ 0x10, 0x02d508c5);
590 rtw_write32(rtwdev
, base_addr
+ 0x60, 0xf0000000);
591 rtw8822c_dac_cal_rf_mode(rtwdev
, &ic
, &qc
);
595 ic
= 0x400 - (0x10 - ic
);
600 qc
= 0x400 - (0x10 - qc
);
613 rtw_dbg(rtwdev
, RTW_DBG_RFK
,
614 "[DACK] after DACK i=0x%x, q=0x%x\n", *i_out
, *q_out
);
617 static void rtw8822c_dac_cal_step4(struct rtw_dev
*rtwdev
, u8 path
)
619 u32 base_addr
= rtw8822c_get_path_write_addr(path
);
621 rtw_write32(rtwdev
, base_addr
+ 0x68, 0x0);
622 rtw_write32(rtwdev
, base_addr
+ 0x10, 0x02d508c4);
623 rtw_write32_mask(rtwdev
, base_addr
+ 0xbc, 0x1, 0x0);
624 rtw_write32_mask(rtwdev
, base_addr
+ 0x30, BIT(30), 0x1);
627 static void rtw8822c_dac_cal_backup_vec(struct rtw_dev
*rtwdev
,
628 u8 path
, u8 vec
, u32 w_addr
, u32 r_addr
)
630 struct rtw_dm_info
*dm_info
= &rtwdev
->dm_info
;
634 if (WARN_ON(vec
>= 2))
637 for (i
= 0; i
< DACK_MSBK_BACKUP_NUM
; i
++) {
638 rtw_write32_mask(rtwdev
, w_addr
, 0xf0000000, i
);
639 val
= (u16
)rtw_read32_mask(rtwdev
, r_addr
, 0x7fc0000);
640 dm_info
->dack_msbk
[path
][vec
][i
] = val
;
644 static void rtw8822c_dac_cal_backup_path(struct rtw_dev
*rtwdev
, u8 path
)
650 if (WARN_ON(path
>= 2))
653 /* backup I vector */
654 w_addr
= rtw8822c_get_path_write_addr(path
) + 0xb0;
655 r_addr
= rtw8822c_get_path_read_addr(path
) + 0x10;
656 rtw8822c_dac_cal_backup_vec(rtwdev
, path
, 0, w_addr
, r_addr
);
658 /* backup Q vector */
659 w_addr
= rtw8822c_get_path_write_addr(path
) + 0xb0 + w_off
;
660 r_addr
= rtw8822c_get_path_read_addr(path
) + 0x10 + r_off
;
661 rtw8822c_dac_cal_backup_vec(rtwdev
, path
, 1, w_addr
, r_addr
);
664 static void rtw8822c_dac_cal_backup_dck(struct rtw_dev
*rtwdev
)
666 struct rtw_dm_info
*dm_info
= &rtwdev
->dm_info
;
669 val
= (u8
)rtw_read32_mask(rtwdev
, REG_DCKA_I_0
, 0xf0000000);
670 dm_info
->dack_dck
[RF_PATH_A
][0][0] = val
;
671 val
= (u8
)rtw_read32_mask(rtwdev
, REG_DCKA_I_1
, 0xf);
672 dm_info
->dack_dck
[RF_PATH_A
][0][1] = val
;
673 val
= (u8
)rtw_read32_mask(rtwdev
, REG_DCKA_Q_0
, 0xf0000000);
674 dm_info
->dack_dck
[RF_PATH_A
][1][0] = val
;
675 val
= (u8
)rtw_read32_mask(rtwdev
, REG_DCKA_Q_1
, 0xf);
676 dm_info
->dack_dck
[RF_PATH_A
][1][1] = val
;
678 val
= (u8
)rtw_read32_mask(rtwdev
, REG_DCKB_I_0
, 0xf0000000);
679 dm_info
->dack_dck
[RF_PATH_B
][0][0] = val
;
680 val
= (u8
)rtw_read32_mask(rtwdev
, REG_DCKB_I_1
, 0xf);
681 dm_info
->dack_dck
[RF_PATH_B
][1][0] = val
;
682 val
= (u8
)rtw_read32_mask(rtwdev
, REG_DCKB_Q_0
, 0xf0000000);
683 dm_info
->dack_dck
[RF_PATH_B
][0][1] = val
;
684 val
= (u8
)rtw_read32_mask(rtwdev
, REG_DCKB_Q_1
, 0xf);
685 dm_info
->dack_dck
[RF_PATH_B
][1][1] = val
;
688 static void rtw8822c_dac_cal_backup(struct rtw_dev
*rtwdev
)
692 temp
[0] = rtw_read32(rtwdev
, 0x1860);
693 temp
[1] = rtw_read32(rtwdev
, 0x4160);
694 temp
[2] = rtw_read32(rtwdev
, 0x9b4);
697 rtw_write32(rtwdev
, 0x9b4, 0xdb66db00);
699 /* backup path-A I/Q */
700 rtw_write32_clr(rtwdev
, 0x1830, BIT(30));
701 rtw_write32_mask(rtwdev
, 0x1860, 0xfc000000, 0x3c);
702 rtw8822c_dac_cal_backup_path(rtwdev
, RF_PATH_A
);
704 /* backup path-B I/Q */
705 rtw_write32_clr(rtwdev
, 0x4130, BIT(30));
706 rtw_write32_mask(rtwdev
, 0x4160, 0xfc000000, 0x3c);
707 rtw8822c_dac_cal_backup_path(rtwdev
, RF_PATH_B
);
709 rtw8822c_dac_cal_backup_dck(rtwdev
);
710 rtw_write32_set(rtwdev
, 0x1830, BIT(30));
711 rtw_write32_set(rtwdev
, 0x4130, BIT(30));
713 rtw_write32(rtwdev
, 0x1860, temp
[0]);
714 rtw_write32(rtwdev
, 0x4160, temp
[1]);
715 rtw_write32(rtwdev
, 0x9b4, temp
[2]);
718 static void rtw8822c_dac_cal_restore_dck(struct rtw_dev
*rtwdev
)
720 struct rtw_dm_info
*dm_info
= &rtwdev
->dm_info
;
723 rtw_write32_set(rtwdev
, REG_DCKA_I_0
, BIT(19));
724 val
= dm_info
->dack_dck
[RF_PATH_A
][0][0];
725 rtw_write32_mask(rtwdev
, REG_DCKA_I_0
, 0xf0000000, val
);
726 val
= dm_info
->dack_dck
[RF_PATH_A
][0][1];
727 rtw_write32_mask(rtwdev
, REG_DCKA_I_1
, 0xf, val
);
729 rtw_write32_set(rtwdev
, REG_DCKA_Q_0
, BIT(19));
730 val
= dm_info
->dack_dck
[RF_PATH_A
][1][0];
731 rtw_write32_mask(rtwdev
, REG_DCKA_Q_0
, 0xf0000000, val
);
732 val
= dm_info
->dack_dck
[RF_PATH_A
][1][1];
733 rtw_write32_mask(rtwdev
, REG_DCKA_Q_1
, 0xf, val
);
735 rtw_write32_set(rtwdev
, REG_DCKB_I_0
, BIT(19));
736 val
= dm_info
->dack_dck
[RF_PATH_B
][0][0];
737 rtw_write32_mask(rtwdev
, REG_DCKB_I_0
, 0xf0000000, val
);
738 val
= dm_info
->dack_dck
[RF_PATH_B
][0][1];
739 rtw_write32_mask(rtwdev
, REG_DCKB_I_1
, 0xf, val
);
741 rtw_write32_set(rtwdev
, REG_DCKB_Q_0
, BIT(19));
742 val
= dm_info
->dack_dck
[RF_PATH_B
][1][0];
743 rtw_write32_mask(rtwdev
, REG_DCKB_Q_0
, 0xf0000000, val
);
744 val
= dm_info
->dack_dck
[RF_PATH_B
][1][1];
745 rtw_write32_mask(rtwdev
, REG_DCKB_Q_1
, 0xf, val
);
748 static void rtw8822c_dac_cal_restore_prepare(struct rtw_dev
*rtwdev
)
750 rtw_write32(rtwdev
, 0x9b4, 0xdb66db00);
752 rtw_write32_mask(rtwdev
, 0x18b0, BIT(27), 0x0);
753 rtw_write32_mask(rtwdev
, 0x18cc, BIT(27), 0x0);
754 rtw_write32_mask(rtwdev
, 0x41b0, BIT(27), 0x0);
755 rtw_write32_mask(rtwdev
, 0x41cc, BIT(27), 0x0);
757 rtw_write32_mask(rtwdev
, 0x1830, BIT(30), 0x0);
758 rtw_write32_mask(rtwdev
, 0x1860, 0xfc000000, 0x3c);
759 rtw_write32_mask(rtwdev
, 0x18b4, BIT(0), 0x1);
760 rtw_write32_mask(rtwdev
, 0x18d0, BIT(0), 0x1);
762 rtw_write32_mask(rtwdev
, 0x4130, BIT(30), 0x0);
763 rtw_write32_mask(rtwdev
, 0x4160, 0xfc000000, 0x3c);
764 rtw_write32_mask(rtwdev
, 0x41b4, BIT(0), 0x1);
765 rtw_write32_mask(rtwdev
, 0x41d0, BIT(0), 0x1);
767 rtw_write32_mask(rtwdev
, 0x18b0, 0xf00, 0x0);
768 rtw_write32_mask(rtwdev
, 0x18c0, BIT(14), 0x0);
769 rtw_write32_mask(rtwdev
, 0x18cc, 0xf00, 0x0);
770 rtw_write32_mask(rtwdev
, 0x18dc, BIT(14), 0x0);
772 rtw_write32_mask(rtwdev
, 0x18b0, BIT(0), 0x0);
773 rtw_write32_mask(rtwdev
, 0x18cc, BIT(0), 0x0);
774 rtw_write32_mask(rtwdev
, 0x18b0, BIT(0), 0x1);
775 rtw_write32_mask(rtwdev
, 0x18cc, BIT(0), 0x1);
777 rtw8822c_dac_cal_restore_dck(rtwdev
);
779 rtw_write32_mask(rtwdev
, 0x18c0, 0x38000, 0x7);
780 rtw_write32_mask(rtwdev
, 0x18dc, 0x38000, 0x7);
781 rtw_write32_mask(rtwdev
, 0x41c0, 0x38000, 0x7);
782 rtw_write32_mask(rtwdev
, 0x41dc, 0x38000, 0x7);
784 rtw_write32_mask(rtwdev
, 0x18b8, BIT(26) | BIT(25), 0x1);
785 rtw_write32_mask(rtwdev
, 0x18d4, BIT(26) | BIT(25), 0x1);
787 rtw_write32_mask(rtwdev
, 0x41b0, 0xf00, 0x0);
788 rtw_write32_mask(rtwdev
, 0x41c0, BIT(14), 0x0);
789 rtw_write32_mask(rtwdev
, 0x41cc, 0xf00, 0x0);
790 rtw_write32_mask(rtwdev
, 0x41dc, BIT(14), 0x0);
792 rtw_write32_mask(rtwdev
, 0x41b0, BIT(0), 0x0);
793 rtw_write32_mask(rtwdev
, 0x41cc, BIT(0), 0x0);
794 rtw_write32_mask(rtwdev
, 0x41b0, BIT(0), 0x1);
795 rtw_write32_mask(rtwdev
, 0x41cc, BIT(0), 0x1);
797 rtw_write32_mask(rtwdev
, 0x41b8, BIT(26) | BIT(25), 0x1);
798 rtw_write32_mask(rtwdev
, 0x41d4, BIT(26) | BIT(25), 0x1);
801 static bool rtw8822c_dac_cal_restore_wait(struct rtw_dev
*rtwdev
,
802 u32 target_addr
, u32 toggle_addr
)
807 rtw_write32_mask(rtwdev
, toggle_addr
, BIT(26) | BIT(25), 0x0);
808 rtw_write32_mask(rtwdev
, toggle_addr
, BIT(26) | BIT(25), 0x2);
810 if (rtw_read32_mask(rtwdev
, target_addr
, 0xf) == 0x6)
813 } while (cnt
++ < 100);
818 static bool rtw8822c_dac_cal_restore_path(struct rtw_dev
*rtwdev
, u8 path
)
820 struct rtw_dm_info
*dm_info
= &rtwdev
->dm_info
;
823 u32 w_i
, r_i
, w_q
, r_q
;
827 w_i
= rtw8822c_get_path_write_addr(path
) + 0xb0;
828 r_i
= rtw8822c_get_path_read_addr(path
) + 0x08;
829 w_q
= rtw8822c_get_path_write_addr(path
) + 0xb0 + w_off
;
830 r_q
= rtw8822c_get_path_read_addr(path
) + 0x08 + r_off
;
832 if (!rtw8822c_dac_cal_restore_wait(rtwdev
, r_i
, w_i
+ 0x8))
835 for (i
= 0; i
< DACK_MSBK_BACKUP_NUM
; i
++) {
836 rtw_write32_mask(rtwdev
, w_i
+ 0x4, BIT(2), 0x0);
837 value
= dm_info
->dack_msbk
[path
][0][i
];
838 rtw_write32_mask(rtwdev
, w_i
+ 0x4, 0xff8, value
);
839 rtw_write32_mask(rtwdev
, w_i
, 0xf0000000, i
);
840 rtw_write32_mask(rtwdev
, w_i
+ 0x4, BIT(2), 0x1);
843 rtw_write32_mask(rtwdev
, w_i
+ 0x4, BIT(2), 0x0);
845 if (!rtw8822c_dac_cal_restore_wait(rtwdev
, r_q
, w_q
+ 0x8))
848 for (i
= 0; i
< DACK_MSBK_BACKUP_NUM
; i
++) {
849 rtw_write32_mask(rtwdev
, w_q
+ 0x4, BIT(2), 0x0);
850 value
= dm_info
->dack_msbk
[path
][1][i
];
851 rtw_write32_mask(rtwdev
, w_q
+ 0x4, 0xff8, value
);
852 rtw_write32_mask(rtwdev
, w_q
, 0xf0000000, i
);
853 rtw_write32_mask(rtwdev
, w_q
+ 0x4, BIT(2), 0x1);
855 rtw_write32_mask(rtwdev
, w_q
+ 0x4, BIT(2), 0x0);
857 rtw_write32_mask(rtwdev
, w_i
+ 0x8, BIT(26) | BIT(25), 0x0);
858 rtw_write32_mask(rtwdev
, w_q
+ 0x8, BIT(26) | BIT(25), 0x0);
859 rtw_write32_mask(rtwdev
, w_i
+ 0x4, BIT(0), 0x0);
860 rtw_write32_mask(rtwdev
, w_q
+ 0x4, BIT(0), 0x0);
865 static bool __rtw8822c_dac_cal_restore(struct rtw_dev
*rtwdev
)
867 if (!rtw8822c_dac_cal_restore_path(rtwdev
, RF_PATH_A
))
870 if (!rtw8822c_dac_cal_restore_path(rtwdev
, RF_PATH_B
))
876 static bool rtw8822c_dac_cal_restore(struct rtw_dev
*rtwdev
)
878 struct rtw_dm_info
*dm_info
= &rtwdev
->dm_info
;
881 /* sample the first element for both path's IQ vector */
882 if (dm_info
->dack_msbk
[RF_PATH_A
][0][0] == 0 &&
883 dm_info
->dack_msbk
[RF_PATH_A
][1][0] == 0 &&
884 dm_info
->dack_msbk
[RF_PATH_B
][0][0] == 0 &&
885 dm_info
->dack_msbk
[RF_PATH_B
][1][0] == 0)
888 temp
[0] = rtw_read32(rtwdev
, 0x1860);
889 temp
[1] = rtw_read32(rtwdev
, 0x4160);
890 temp
[2] = rtw_read32(rtwdev
, 0x9b4);
892 rtw8822c_dac_cal_restore_prepare(rtwdev
);
893 if (!check_hw_ready(rtwdev
, 0x2808, 0x7fff80, 0xffff) ||
894 !check_hw_ready(rtwdev
, 0x2834, 0x7fff80, 0xffff) ||
895 !check_hw_ready(rtwdev
, 0x4508, 0x7fff80, 0xffff) ||
896 !check_hw_ready(rtwdev
, 0x4534, 0x7fff80, 0xffff))
899 if (!__rtw8822c_dac_cal_restore(rtwdev
)) {
900 rtw_err(rtwdev
, "failed to restore dack vectors\n");
904 rtw_write32_mask(rtwdev
, 0x1830, BIT(30), 0x1);
905 rtw_write32_mask(rtwdev
, 0x4130, BIT(30), 0x1);
906 rtw_write32(rtwdev
, 0x1860, temp
[0]);
907 rtw_write32(rtwdev
, 0x4160, temp
[1]);
908 rtw_write32_mask(rtwdev
, 0x18b0, BIT(27), 0x1);
909 rtw_write32_mask(rtwdev
, 0x18cc, BIT(27), 0x1);
910 rtw_write32_mask(rtwdev
, 0x41b0, BIT(27), 0x1);
911 rtw_write32_mask(rtwdev
, 0x41cc, BIT(27), 0x1);
912 rtw_write32(rtwdev
, 0x9b4, temp
[2]);
917 static void rtw8822c_rf_dac_cal(struct rtw_dev
*rtwdev
)
919 struct rtw_backup_info backup_rf
[DACK_RF_8822C
* DACK_PATH_8822C
];
920 struct rtw_backup_info backup
[DACK_REG_8822C
];
921 u32 ic
= 0, qc
= 0, i
;
922 u32 i_a
= 0x0, q_a
= 0x0, i_b
= 0x0, q_b
= 0x0;
923 u32 ic_a
= 0x0, qc_a
= 0x0, ic_b
= 0x0, qc_b
= 0x0;
924 u32 adc_ic_a
= 0x0, adc_qc_a
= 0x0, adc_ic_b
= 0x0, adc_qc_b
= 0x0;
926 if (rtw8822c_dac_cal_restore(rtwdev
))
929 /* not able to restore, do it */
931 rtw8822c_dac_backup_reg(rtwdev
, backup
, backup_rf
);
933 rtw8822c_dac_bb_setting(rtwdev
);
936 rtw8822c_dac_cal_adc(rtwdev
, RF_PATH_A
, &adc_ic_a
, &adc_qc_a
);
937 for (i
= 0; i
< 10; i
++) {
938 rtw8822c_dac_cal_step1(rtwdev
, RF_PATH_A
);
939 rtw8822c_dac_cal_step2(rtwdev
, RF_PATH_A
, &ic
, &qc
);
943 rtw8822c_dac_cal_step3(rtwdev
, RF_PATH_A
, adc_ic_a
, adc_qc_a
,
944 &ic
, &qc
, &i_a
, &q_a
);
946 if (ic
< 5 && qc
< 5)
949 rtw8822c_dac_cal_step4(rtwdev
, RF_PATH_A
);
952 rtw8822c_dac_cal_adc(rtwdev
, RF_PATH_B
, &adc_ic_b
, &adc_qc_b
);
953 for (i
= 0; i
< 10; i
++) {
954 rtw8822c_dac_cal_step1(rtwdev
, RF_PATH_B
);
955 rtw8822c_dac_cal_step2(rtwdev
, RF_PATH_B
, &ic
, &qc
);
959 rtw8822c_dac_cal_step3(rtwdev
, RF_PATH_B
, adc_ic_b
, adc_qc_b
,
960 &ic
, &qc
, &i_b
, &q_b
);
962 if (ic
< 5 && qc
< 5)
965 rtw8822c_dac_cal_step4(rtwdev
, RF_PATH_B
);
967 rtw_write32(rtwdev
, 0x1b00, 0x00000008);
968 rtw_write32_mask(rtwdev
, 0x4130, BIT(30), 0x1);
969 rtw_write8(rtwdev
, 0x1bcc, 0x0);
970 rtw_write32(rtwdev
, 0x1b00, 0x0000000a);
971 rtw_write8(rtwdev
, 0x1bcc, 0x0);
973 rtw8822c_dac_restore_reg(rtwdev
, backup
, backup_rf
);
975 /* backup results to restore, saving a lot of time */
976 rtw8822c_dac_cal_backup(rtwdev
);
978 rtw_dbg(rtwdev
, RTW_DBG_RFK
, "[DACK] path A: ic=0x%x, qc=0x%x\n", ic_a
, qc_a
);
979 rtw_dbg(rtwdev
, RTW_DBG_RFK
, "[DACK] path B: ic=0x%x, qc=0x%x\n", ic_b
, qc_b
);
980 rtw_dbg(rtwdev
, RTW_DBG_RFK
, "[DACK] path A: i=0x%x, q=0x%x\n", i_a
, q_a
);
981 rtw_dbg(rtwdev
, RTW_DBG_RFK
, "[DACK] path B: i=0x%x, q=0x%x\n", i_b
, q_b
);
984 static void rtw8822c_rf_x2_check(struct rtw_dev
*rtwdev
)
989 x2k_busy
= rtw_read_rf(rtwdev
, RF_PATH_A
, 0xb8, BIT(15));
991 rtw_write_rf(rtwdev
, RF_PATH_A
, 0xb8, RFREG_MASK
, 0xC4440);
992 rtw_write_rf(rtwdev
, RF_PATH_A
, 0xba, RFREG_MASK
, 0x6840D);
993 rtw_write_rf(rtwdev
, RF_PATH_A
, 0xb8, RFREG_MASK
, 0x80440);
998 static void rtw8822c_set_power_trim(struct rtw_dev
*rtwdev
, s8 bb_gain
[2][8])
1000 #define RF_SET_POWER_TRIM(_path, _seq, _idx) \
1002 rtw_write_rf(rtwdev, _path, 0x33, RFREG_MASK, _seq); \
1003 rtw_write_rf(rtwdev, _path, 0x3f, RFREG_MASK, \
1004 bb_gain[_path][_idx]); \
1008 for (path
= 0; path
< rtwdev
->hal
.rf_path_num
; path
++) {
1009 rtw_write_rf(rtwdev
, path
, 0xee, BIT(19), 1);
1010 RF_SET_POWER_TRIM(path
, 0x0, 0);
1011 RF_SET_POWER_TRIM(path
, 0x1, 1);
1012 RF_SET_POWER_TRIM(path
, 0x2, 2);
1013 RF_SET_POWER_TRIM(path
, 0x3, 2);
1014 RF_SET_POWER_TRIM(path
, 0x4, 3);
1015 RF_SET_POWER_TRIM(path
, 0x5, 4);
1016 RF_SET_POWER_TRIM(path
, 0x6, 5);
1017 RF_SET_POWER_TRIM(path
, 0x7, 6);
1018 RF_SET_POWER_TRIM(path
, 0x8, 7);
1019 RF_SET_POWER_TRIM(path
, 0x9, 3);
1020 RF_SET_POWER_TRIM(path
, 0xa, 4);
1021 RF_SET_POWER_TRIM(path
, 0xb, 5);
1022 RF_SET_POWER_TRIM(path
, 0xc, 6);
1023 RF_SET_POWER_TRIM(path
, 0xd, 7);
1024 RF_SET_POWER_TRIM(path
, 0xe, 7);
1025 rtw_write_rf(rtwdev
, path
, 0xee, BIT(19), 0);
1027 #undef RF_SET_POWER_TRIM
1030 static void rtw8822c_power_trim(struct rtw_dev
*rtwdev
)
1032 u8 pg_pwr
= 0xff, i
, path
, idx
;
1033 s8 bb_gain
[2][8] = {};
1034 u16 rf_efuse_2g
[3] = {PPG_2GL_TXAB
, PPG_2GM_TXAB
, PPG_2GH_TXAB
};
1035 u16 rf_efuse_5g
[2][5] = {{PPG_5GL1_TXA
, PPG_5GL2_TXA
, PPG_5GM1_TXA
,
1036 PPG_5GM2_TXA
, PPG_5GH1_TXA
},
1037 {PPG_5GL1_TXB
, PPG_5GL2_TXB
, PPG_5GM1_TXB
,
1038 PPG_5GM2_TXB
, PPG_5GH1_TXB
} };
1041 for (i
= 0; i
< ARRAY_SIZE(rf_efuse_2g
); i
++) {
1042 rtw_read8_physical_efuse(rtwdev
, rf_efuse_2g
[i
], &pg_pwr
);
1043 if (pg_pwr
== EFUSE_READ_FAIL
)
1046 bb_gain
[RF_PATH_A
][i
] = FIELD_GET(PPG_2G_A_MASK
, pg_pwr
);
1047 bb_gain
[RF_PATH_B
][i
] = FIELD_GET(PPG_2G_B_MASK
, pg_pwr
);
1050 for (i
= 0; i
< ARRAY_SIZE(rf_efuse_5g
[0]); i
++) {
1051 for (path
= 0; path
< rtwdev
->hal
.rf_path_num
; path
++) {
1052 rtw_read8_physical_efuse(rtwdev
, rf_efuse_5g
[path
][i
],
1054 if (pg_pwr
== EFUSE_READ_FAIL
)
1057 idx
= i
+ ARRAY_SIZE(rf_efuse_2g
);
1058 bb_gain
[path
][idx
] = FIELD_GET(PPG_5G_MASK
, pg_pwr
);
1062 rtw8822c_set_power_trim(rtwdev
, bb_gain
);
1064 rtw_write32_mask(rtwdev
, REG_DIS_DPD
, DIS_DPD_MASK
, DIS_DPD_RATEALL
);
1067 static void rtw8822c_thermal_trim(struct rtw_dev
*rtwdev
)
1069 u16 rf_efuse
[2] = {PPG_THERMAL_A
, PPG_THERMAL_B
};
1070 u8 pg_therm
= 0xff, thermal
[2] = {0}, path
;
1072 for (path
= 0; path
< rtwdev
->hal
.rf_path_num
; path
++) {
1073 rtw_read8_physical_efuse(rtwdev
, rf_efuse
[path
], &pg_therm
);
1074 if (pg_therm
== EFUSE_READ_FAIL
)
1076 /* Efuse value of BIT(0) shall be move to BIT(3), and the value
1077 * of BIT(1) to BIT(3) should be right shifted 1 bit.
1079 thermal
[path
] = FIELD_GET(GENMASK(3, 1), pg_therm
);
1080 thermal
[path
] |= FIELD_PREP(BIT(3), pg_therm
& BIT(0));
1081 rtw_write_rf(rtwdev
, path
, 0x43, RF_THEMAL_MASK
, thermal
[path
]);
1085 static void rtw8822c_pa_bias(struct rtw_dev
*rtwdev
)
1087 u16 rf_efuse_2g
[2] = {PPG_PABIAS_2GA
, PPG_PABIAS_2GB
};
1088 u16 rf_efuse_5g
[2] = {PPG_PABIAS_5GA
, PPG_PABIAS_5GB
};
1089 u8 pg_pa_bias
= 0xff, path
;
1091 for (path
= 0; path
< rtwdev
->hal
.rf_path_num
; path
++) {
1092 rtw_read8_physical_efuse(rtwdev
, rf_efuse_2g
[path
],
1094 if (pg_pa_bias
== EFUSE_READ_FAIL
)
1096 pg_pa_bias
= FIELD_GET(PPG_PABIAS_MASK
, pg_pa_bias
);
1097 rtw_write_rf(rtwdev
, path
, 0x60, RF_PABIAS_2G_MASK
, pg_pa_bias
);
1099 for (path
= 0; path
< rtwdev
->hal
.rf_path_num
; path
++) {
1100 rtw_read8_physical_efuse(rtwdev
, rf_efuse_5g
[path
],
1102 pg_pa_bias
= FIELD_GET(PPG_PABIAS_MASK
, pg_pa_bias
);
1103 rtw_write_rf(rtwdev
, path
, 0x60, RF_PABIAS_5G_MASK
, pg_pa_bias
);
1107 static void rtw8822c_rf_init(struct rtw_dev
*rtwdev
)
1109 rtw8822c_rf_dac_cal(rtwdev
);
1110 rtw8822c_rf_x2_check(rtwdev
);
1111 rtw8822c_thermal_trim(rtwdev
);
1112 rtw8822c_power_trim(rtwdev
);
1113 rtw8822c_pa_bias(rtwdev
);
1116 static void rtw8822c_pwrtrack_init(struct rtw_dev
*rtwdev
)
1118 struct rtw_dm_info
*dm_info
= &rtwdev
->dm_info
;
1121 for (path
= RF_PATH_A
; path
< RTW_RF_PATH_MAX
; path
++) {
1122 dm_info
->delta_power_index
[path
] = 0;
1123 ewma_thermal_init(&dm_info
->avg_thermal
[path
]);
1124 dm_info
->thermal_avg
[path
] = 0xff;
1127 dm_info
->pwr_trk_triggered
= false;
1128 dm_info
->thermal_meter_k
= rtwdev
->efuse
.thermal_meter_k
;
1131 static void rtw8822c_phy_set_param(struct rtw_dev
*rtwdev
)
1133 struct rtw_dm_info
*dm_info
= &rtwdev
->dm_info
;
1134 struct rtw_hal
*hal
= &rtwdev
->hal
;
1136 u8 cck_gi_u_bnd_msb
= 0;
1137 u8 cck_gi_u_bnd_lsb
= 0;
1138 u8 cck_gi_l_bnd_msb
= 0;
1139 u8 cck_gi_l_bnd_lsb
= 0;
1142 /* power on BB/RF domain */
1143 rtw_write8_set(rtwdev
, REG_SYS_FUNC_EN
,
1144 BIT_FEN_BB_GLB_RST
| BIT_FEN_BB_RSTB
);
1145 rtw_write8_set(rtwdev
, REG_RF_CTRL
,
1146 BIT_RF_EN
| BIT_RF_RSTB
| BIT_RF_SDM_RSTB
);
1147 rtw_write32_set(rtwdev
, REG_WLRF1
, BIT_WLRF1_BBRF_EN
);
1149 /* disable low rate DPD */
1150 rtw_write32_mask(rtwdev
, REG_DIS_DPD
, DIS_DPD_MASK
, DIS_DPD_RATEALL
);
1152 /* pre init before header files config */
1153 rtw8822c_header_file_init(rtwdev
, true);
1155 rtw_phy_load_tables(rtwdev
);
1157 crystal_cap
= rtwdev
->efuse
.crystal_cap
& 0x7f;
1158 rtw_write32_mask(rtwdev
, REG_ANAPAR_XTAL_0
, 0xfffc00,
1159 crystal_cap
| (crystal_cap
<< 7));
1161 /* post init after header files config */
1162 rtw8822c_header_file_init(rtwdev
, false);
1164 is_tx2_path
= false;
1165 rtw8822c_config_trx_mode(rtwdev
, hal
->antenna_tx
, hal
->antenna_rx
,
1167 rtw_phy_init(rtwdev
);
1169 cck_gi_u_bnd_msb
= (u8
)rtw_read32_mask(rtwdev
, 0x1a98, 0xc000);
1170 cck_gi_u_bnd_lsb
= (u8
)rtw_read32_mask(rtwdev
, 0x1aa8, 0xf0000);
1171 cck_gi_l_bnd_msb
= (u8
)rtw_read32_mask(rtwdev
, 0x1a98, 0xc0);
1172 cck_gi_l_bnd_lsb
= (u8
)rtw_read32_mask(rtwdev
, 0x1a70, 0x0f000000);
1174 dm_info
->cck_gi_u_bnd
= ((cck_gi_u_bnd_msb
<< 4) | (cck_gi_u_bnd_lsb
));
1175 dm_info
->cck_gi_l_bnd
= ((cck_gi_l_bnd_msb
<< 4) | (cck_gi_l_bnd_lsb
));
1177 rtw8822c_rf_init(rtwdev
);
1178 rtw8822c_pwrtrack_init(rtwdev
);
1180 rtw_bf_phy_init(rtwdev
);
1183 #define WLAN_TXQ_RPT_EN 0x1F
1184 #define WLAN_SLOT_TIME 0x09
1185 #define WLAN_PIFS_TIME 0x1C
1186 #define WLAN_SIFS_CCK_CONT_TX 0x0A
1187 #define WLAN_SIFS_OFDM_CONT_TX 0x0E
1188 #define WLAN_SIFS_CCK_TRX 0x0A
1189 #define WLAN_SIFS_OFDM_TRX 0x10
1190 #define WLAN_NAV_MAX 0xC8
1191 #define WLAN_RDG_NAV 0x05
1192 #define WLAN_TXOP_NAV 0x1B
1193 #define WLAN_CCK_RX_TSF 0x30
1194 #define WLAN_OFDM_RX_TSF 0x30
1195 #define WLAN_TBTT_PROHIBIT 0x04 /* unit : 32us */
1196 #define WLAN_TBTT_HOLD_TIME 0x064 /* unit : 32us */
1197 #define WLAN_DRV_EARLY_INT 0x04
1198 #define WLAN_BCN_CTRL_CLT0 0x10
1199 #define WLAN_BCN_DMA_TIME 0x02
1200 #define WLAN_BCN_MAX_ERR 0xFF
1201 #define WLAN_SIFS_CCK_DUR_TUNE 0x0A
1202 #define WLAN_SIFS_OFDM_DUR_TUNE 0x10
1203 #define WLAN_SIFS_CCK_CTX 0x0A
1204 #define WLAN_SIFS_CCK_IRX 0x0A
1205 #define WLAN_SIFS_OFDM_CTX 0x0E
1206 #define WLAN_SIFS_OFDM_IRX 0x0E
1207 #define WLAN_EIFS_DUR_TUNE 0x40
1208 #define WLAN_EDCA_VO_PARAM 0x002FA226
1209 #define WLAN_EDCA_VI_PARAM 0x005EA328
1210 #define WLAN_EDCA_BE_PARAM 0x005EA42B
1211 #define WLAN_EDCA_BK_PARAM 0x0000A44F
1213 #define WLAN_RX_FILTER0 0xFFFFFFFF
1214 #define WLAN_RX_FILTER2 0xFFFF
1215 #define WLAN_RCR_CFG 0xE400220E
1216 #define WLAN_RXPKT_MAX_SZ 12288
1217 #define WLAN_RXPKT_MAX_SZ_512 (WLAN_RXPKT_MAX_SZ >> 9)
1219 #define WLAN_AMPDU_MAX_TIME 0x70
1220 #define WLAN_RTS_LEN_TH 0xFF
1221 #define WLAN_RTS_TX_TIME_TH 0x08
1222 #define WLAN_MAX_AGG_PKT_LIMIT 0x3f
1223 #define WLAN_RTS_MAX_AGG_PKT_LIMIT 0x3f
1224 #define WLAN_PRE_TXCNT_TIME_TH 0x1E0
1225 #define FAST_EDCA_VO_TH 0x06
1226 #define FAST_EDCA_VI_TH 0x06
1227 #define FAST_EDCA_BE_TH 0x06
1228 #define FAST_EDCA_BK_TH 0x06
1229 #define WLAN_BAR_RETRY_LIMIT 0x01
1230 #define WLAN_BAR_ACK_TYPE 0x05
1231 #define WLAN_RA_TRY_RATE_AGG_LIMIT 0x08
1232 #define WLAN_RESP_TXRATE 0x84
1233 #define WLAN_ACK_TO 0x21
1234 #define WLAN_ACK_TO_CCK 0x6A
1235 #define WLAN_DATA_RATE_FB_CNT_1_4 0x01000000
1236 #define WLAN_DATA_RATE_FB_CNT_5_8 0x08070504
1237 #define WLAN_RTS_RATE_FB_CNT_5_8 0x08070504
1238 #define WLAN_DATA_RATE_FB_RATE0 0xFE01F010
1239 #define WLAN_DATA_RATE_FB_RATE0_H 0x40000000
1240 #define WLAN_RTS_RATE_FB_RATE1 0x003FF010
1241 #define WLAN_RTS_RATE_FB_RATE1_H 0x40000000
1242 #define WLAN_RTS_RATE_FB_RATE4 0x0600F010
1243 #define WLAN_RTS_RATE_FB_RATE4_H 0x400003E0
1244 #define WLAN_RTS_RATE_FB_RATE5 0x0600F015
1245 #define WLAN_RTS_RATE_FB_RATE5_H 0x000000E0
1246 #define WLAN_MULTI_ADDR 0xFFFFFFFF
1248 #define WLAN_TX_FUNC_CFG1 0x30
1249 #define WLAN_TX_FUNC_CFG2 0x30
1250 #define WLAN_MAC_OPT_NORM_FUNC1 0x98
1251 #define WLAN_MAC_OPT_LB_FUNC1 0x80
1252 #define WLAN_MAC_OPT_FUNC2 0x30810041
1253 #define WLAN_MAC_INT_MIG_CFG 0x33330000
1255 #define WLAN_SIFS_CFG (WLAN_SIFS_CCK_CONT_TX | \
1256 (WLAN_SIFS_OFDM_CONT_TX << BIT_SHIFT_SIFS_OFDM_CTX) | \
1257 (WLAN_SIFS_CCK_TRX << BIT_SHIFT_SIFS_CCK_TRX) | \
1258 (WLAN_SIFS_OFDM_TRX << BIT_SHIFT_SIFS_OFDM_TRX))
1260 #define WLAN_SIFS_DUR_TUNE (WLAN_SIFS_CCK_DUR_TUNE | \
1261 (WLAN_SIFS_OFDM_DUR_TUNE << 8))
1263 #define WLAN_TBTT_TIME (WLAN_TBTT_PROHIBIT |\
1264 (WLAN_TBTT_HOLD_TIME << BIT_SHIFT_TBTT_HOLD_TIME_AP))
1266 #define WLAN_NAV_CFG (WLAN_RDG_NAV | (WLAN_TXOP_NAV << 16))
1267 #define WLAN_RX_TSF_CFG (WLAN_CCK_RX_TSF | (WLAN_OFDM_RX_TSF) << 8)
1269 #define MAC_CLK_SPEED 80 /* 80M */
1270 #define EFUSE_PCB_INFO_OFFSET 0xCA
1272 static int rtw8822c_mac_init(struct rtw_dev
*rtwdev
)
1280 value8
= rtw_read8(rtwdev
, REG_FWHW_TXQ_CTRL
);
1281 value8
|= (BIT(7) & ~BIT(1) & ~BIT(2));
1282 rtw_write8(rtwdev
, REG_FWHW_TXQ_CTRL
, value8
);
1283 rtw_write8(rtwdev
, REG_FWHW_TXQ_CTRL
+ 1, WLAN_TXQ_RPT_EN
);
1285 rtw_write16(rtwdev
, REG_SPEC_SIFS
, WLAN_SIFS_DUR_TUNE
);
1286 rtw_write32(rtwdev
, REG_SIFS
, WLAN_SIFS_CFG
);
1287 rtw_write16(rtwdev
, REG_RESP_SIFS_CCK
,
1288 WLAN_SIFS_CCK_CTX
| WLAN_SIFS_CCK_IRX
<< 8);
1289 rtw_write16(rtwdev
, REG_RESP_SIFS_OFDM
,
1290 WLAN_SIFS_OFDM_CTX
| WLAN_SIFS_OFDM_IRX
<< 8);
1291 /* rate fallback control */
1292 rtw_write32(rtwdev
, REG_DARFRC
, WLAN_DATA_RATE_FB_CNT_1_4
);
1293 rtw_write32(rtwdev
, REG_DARFRCH
, WLAN_DATA_RATE_FB_CNT_5_8
);
1294 rtw_write32(rtwdev
, REG_RARFRCH
, WLAN_RTS_RATE_FB_CNT_5_8
);
1295 rtw_write32(rtwdev
, REG_ARFR0
, WLAN_DATA_RATE_FB_RATE0
);
1296 rtw_write32(rtwdev
, REG_ARFRH0
, WLAN_DATA_RATE_FB_RATE0_H
);
1297 rtw_write32(rtwdev
, REG_ARFR1_V1
, WLAN_RTS_RATE_FB_RATE1
);
1298 rtw_write32(rtwdev
, REG_ARFRH1_V1
, WLAN_RTS_RATE_FB_RATE1_H
);
1299 rtw_write32(rtwdev
, REG_ARFR4
, WLAN_RTS_RATE_FB_RATE4
);
1300 rtw_write32(rtwdev
, REG_ARFRH4
, WLAN_RTS_RATE_FB_RATE4_H
);
1301 rtw_write32(rtwdev
, REG_ARFR5
, WLAN_RTS_RATE_FB_RATE5
);
1302 rtw_write32(rtwdev
, REG_ARFRH5
, WLAN_RTS_RATE_FB_RATE5_H
);
1303 /* protocol configuration */
1304 rtw_write8(rtwdev
, REG_AMPDU_MAX_TIME_V1
, WLAN_AMPDU_MAX_TIME
);
1305 rtw_write8_set(rtwdev
, REG_TX_HANG_CTRL
, BIT_EN_EOF_V1
);
1306 pre_txcnt
= WLAN_PRE_TXCNT_TIME_TH
| BIT_EN_PRECNT
;
1307 rtw_write8(rtwdev
, REG_PRECNT_CTRL
, (u8
)(pre_txcnt
& 0xFF));
1308 rtw_write8(rtwdev
, REG_PRECNT_CTRL
+ 1, (u8
)(pre_txcnt
>> 8));
1309 value32
= WLAN_RTS_LEN_TH
| (WLAN_RTS_TX_TIME_TH
<< 8) |
1310 (WLAN_MAX_AGG_PKT_LIMIT
<< 16) |
1311 (WLAN_RTS_MAX_AGG_PKT_LIMIT
<< 24);
1312 rtw_write32(rtwdev
, REG_PROT_MODE_CTRL
, value32
);
1313 rtw_write16(rtwdev
, REG_BAR_MODE_CTRL
+ 2,
1314 WLAN_BAR_RETRY_LIMIT
| WLAN_RA_TRY_RATE_AGG_LIMIT
<< 8);
1315 rtw_write8(rtwdev
, REG_FAST_EDCA_VOVI_SETTING
, FAST_EDCA_VO_TH
);
1316 rtw_write8(rtwdev
, REG_FAST_EDCA_VOVI_SETTING
+ 2, FAST_EDCA_VI_TH
);
1317 rtw_write8(rtwdev
, REG_FAST_EDCA_BEBK_SETTING
, FAST_EDCA_BE_TH
);
1318 rtw_write8(rtwdev
, REG_FAST_EDCA_BEBK_SETTING
+ 2, FAST_EDCA_BK_TH
);
1319 /* close BA parser */
1320 rtw_write8_clr(rtwdev
, REG_LIFETIME_EN
, BIT_BA_PARSER_EN
);
1321 rtw_write32_clr(rtwdev
, REG_RRSR
, BITS_RRSR_RSC
);
1323 /* EDCA configuration */
1324 rtw_write32(rtwdev
, REG_EDCA_VO_PARAM
, WLAN_EDCA_VO_PARAM
);
1325 rtw_write32(rtwdev
, REG_EDCA_VI_PARAM
, WLAN_EDCA_VI_PARAM
);
1326 rtw_write32(rtwdev
, REG_EDCA_BE_PARAM
, WLAN_EDCA_BE_PARAM
);
1327 rtw_write32(rtwdev
, REG_EDCA_BK_PARAM
, WLAN_EDCA_BK_PARAM
);
1328 rtw_write8(rtwdev
, REG_PIFS
, WLAN_PIFS_TIME
);
1329 rtw_write8_clr(rtwdev
, REG_TX_PTCL_CTRL
+ 1, BIT_SIFS_BK_EN
>> 8);
1330 rtw_write8_set(rtwdev
, REG_RD_CTRL
+ 1,
1331 (BIT_DIS_TXOP_CFE
| BIT_DIS_LSIG_CFE
|
1332 BIT_DIS_STBC_CFE
) >> 8);
1334 /* MAC clock configuration */
1335 rtw_write32_clr(rtwdev
, REG_AFE_CTRL1
, BIT_MAC_CLK_SEL
);
1336 rtw_write8(rtwdev
, REG_USTIME_TSF
, MAC_CLK_SPEED
);
1337 rtw_write8(rtwdev
, REG_USTIME_EDCA
, MAC_CLK_SPEED
);
1339 rtw_write8_set(rtwdev
, REG_MISC_CTRL
,
1340 BIT_EN_FREE_CNT
| BIT_DIS_SECOND_CCA
);
1341 rtw_write8_clr(rtwdev
, REG_TIMER0_SRC_SEL
, BIT_TSFT_SEL_TIMER0
);
1342 rtw_write16(rtwdev
, REG_TXPAUSE
, 0x0000);
1343 rtw_write8(rtwdev
, REG_SLOT
, WLAN_SLOT_TIME
);
1344 rtw_write32(rtwdev
, REG_RD_NAV_NXT
, WLAN_NAV_CFG
);
1345 rtw_write16(rtwdev
, REG_RXTSF_OFFSET_CCK
, WLAN_RX_TSF_CFG
);
1346 /* Set beacon cotnrol - enable TSF and other related functions */
1347 rtw_write8_set(rtwdev
, REG_BCN_CTRL
, BIT_EN_BCN_FUNCTION
);
1348 /* Set send beacon related registers */
1349 rtw_write32(rtwdev
, REG_TBTT_PROHIBIT
, WLAN_TBTT_TIME
);
1350 rtw_write8(rtwdev
, REG_DRVERLYINT
, WLAN_DRV_EARLY_INT
);
1351 rtw_write8(rtwdev
, REG_BCN_CTRL_CLINT0
, WLAN_BCN_CTRL_CLT0
);
1352 rtw_write8(rtwdev
, REG_BCNDMATIM
, WLAN_BCN_DMA_TIME
);
1353 rtw_write8(rtwdev
, REG_BCN_MAX_ERR
, WLAN_BCN_MAX_ERR
);
1355 /* WMAC configuration */
1356 rtw_write32(rtwdev
, REG_MAR
, WLAN_MULTI_ADDR
);
1357 rtw_write32(rtwdev
, REG_MAR
+ 4, WLAN_MULTI_ADDR
);
1358 rtw_write8(rtwdev
, REG_BBPSF_CTRL
+ 2, WLAN_RESP_TXRATE
);
1359 rtw_write8(rtwdev
, REG_ACKTO
, WLAN_ACK_TO
);
1360 rtw_write8(rtwdev
, REG_ACKTO_CCK
, WLAN_ACK_TO_CCK
);
1361 rtw_write16(rtwdev
, REG_EIFS
, WLAN_EIFS_DUR_TUNE
);
1362 rtw_write8(rtwdev
, REG_NAV_CTRL
+ 2, WLAN_NAV_MAX
);
1363 rtw_write8(rtwdev
, REG_WMAC_TRXPTCL_CTL_H
+ 2, WLAN_BAR_ACK_TYPE
);
1364 rtw_write32(rtwdev
, REG_RXFLTMAP0
, WLAN_RX_FILTER0
);
1365 rtw_write16(rtwdev
, REG_RXFLTMAP2
, WLAN_RX_FILTER2
);
1366 rtw_write32(rtwdev
, REG_RCR
, WLAN_RCR_CFG
);
1367 rtw_write8(rtwdev
, REG_RX_PKT_LIMIT
, WLAN_RXPKT_MAX_SZ_512
);
1368 rtw_write8(rtwdev
, REG_TCR
+ 2, WLAN_TX_FUNC_CFG2
);
1369 rtw_write8(rtwdev
, REG_TCR
+ 1, WLAN_TX_FUNC_CFG1
);
1370 rtw_write32_set(rtwdev
, REG_GENERAL_OPTION
, BIT_DUMMY_FCS_READY_MASK_EN
);
1371 rtw_write32(rtwdev
, REG_WMAC_OPTION_FUNCTION
+ 8, WLAN_MAC_OPT_FUNC2
);
1372 rtw_write8(rtwdev
, REG_WMAC_OPTION_FUNCTION_1
, WLAN_MAC_OPT_NORM_FUNC1
);
1374 /* init low power */
1375 value16
= rtw_read16(rtwdev
, REG_RXPSF_CTRL
+ 2) & 0xF00F;
1376 value16
|= (BIT_RXGCK_VHT_FIFOTHR(1) | BIT_RXGCK_HT_FIFOTHR(1) |
1377 BIT_RXGCK_OFDM_FIFOTHR(1) | BIT_RXGCK_CCK_FIFOTHR(1)) >> 16;
1378 rtw_write16(rtwdev
, REG_RXPSF_CTRL
+ 2, value16
);
1380 value16
= BIT_SET_RXPSF_PKTLENTHR(value16
, 1);
1381 value16
|= BIT_RXPSF_CTRLEN
| BIT_RXPSF_VHTCHKEN
| BIT_RXPSF_HTCHKEN
1382 | BIT_RXPSF_OFDMCHKEN
| BIT_RXPSF_CCKCHKEN
1383 | BIT_RXPSF_OFDMRST
;
1384 rtw_write16(rtwdev
, REG_RXPSF_CTRL
, value16
);
1385 rtw_write32(rtwdev
, REG_RXPSF_TYPE_CTRL
, 0xFFFFFFFF);
1386 /* rx ignore configuration */
1387 value16
= rtw_read16(rtwdev
, REG_RXPSF_CTRL
);
1388 value16
&= ~(BIT_RXPSF_MHCHKEN
| BIT_RXPSF_CCKRST
|
1389 BIT_RXPSF_CONT_ERRCHKEN
);
1390 value16
= BIT_SET_RXPSF_ERRTHR(value16
, 0x07);
1391 rtw_write16(rtwdev
, REG_RXPSF_CTRL
, value16
);
1393 /* Interrupt migration configuration */
1394 rtw_write32(rtwdev
, REG_INT_MIG
, WLAN_MAC_INT_MIG_CFG
);
1399 static void rtw8822c_rstb_3wire(struct rtw_dev
*rtwdev
, bool enable
)
1402 rtw_write32_mask(rtwdev
, REG_RSTB
, BIT_RSTB_3WIRE
, 0x1);
1403 rtw_write32_mask(rtwdev
, REG_ANAPAR_A
, BIT_ANAPAR_UPDATE
, 0x1);
1404 rtw_write32_mask(rtwdev
, REG_ANAPAR_B
, BIT_ANAPAR_UPDATE
, 0x1);
1406 rtw_write32_mask(rtwdev
, REG_RSTB
, BIT_RSTB_3WIRE
, 0x0);
1410 static void rtw8822c_set_channel_rf(struct rtw_dev
*rtwdev
, u8 channel
, u8 bw
)
1412 #define RF18_BAND_MASK (BIT(16) | BIT(9) | BIT(8))
1413 #define RF18_BAND_2G (0)
1414 #define RF18_BAND_5G (BIT(16) | BIT(8))
1415 #define RF18_CHANNEL_MASK (MASKBYTE0)
1416 #define RF18_RFSI_MASK (BIT(18) | BIT(17))
1417 #define RF18_RFSI_GE_CH80 (BIT(17))
1418 #define RF18_RFSI_GT_CH140 (BIT(18))
1419 #define RF18_BW_MASK (BIT(13) | BIT(12))
1420 #define RF18_BW_20M (BIT(13) | BIT(12))
1421 #define RF18_BW_40M (BIT(13))
1422 #define RF18_BW_80M (BIT(12))
1427 rf_reg18
= rtw_read_rf(rtwdev
, RF_PATH_A
, 0x18, RFREG_MASK
);
1429 rf_reg18
&= ~(RF18_BAND_MASK
| RF18_CHANNEL_MASK
| RF18_RFSI_MASK
|
1432 rf_reg18
|= (IS_CH_2G_BAND(channel
) ? RF18_BAND_2G
: RF18_BAND_5G
);
1433 rf_reg18
|= (channel
& RF18_CHANNEL_MASK
);
1434 if (IS_CH_5G_BAND_4(channel
))
1435 rf_reg18
|= RF18_RFSI_GT_CH140
;
1436 else if (IS_CH_5G_BAND_3(channel
))
1437 rf_reg18
|= RF18_RFSI_GE_CH80
;
1440 case RTW_CHANNEL_WIDTH_5
:
1441 case RTW_CHANNEL_WIDTH_10
:
1442 case RTW_CHANNEL_WIDTH_20
:
1444 rf_reg18
|= RF18_BW_20M
;
1447 case RTW_CHANNEL_WIDTH_40
:
1449 rf_reg18
|= RF18_BW_40M
;
1452 case RTW_CHANNEL_WIDTH_80
:
1453 rf_reg18
|= RF18_BW_80M
;
1458 rtw8822c_rstb_3wire(rtwdev
, false);
1460 rtw_write_rf(rtwdev
, RF_PATH_A
, RF_LUTWE2
, 0x04, 0x01);
1461 rtw_write_rf(rtwdev
, RF_PATH_A
, RF_LUTWA
, 0x1f, 0x12);
1462 rtw_write_rf(rtwdev
, RF_PATH_A
, RF_LUTWD0
, 0xfffff, rf_rxbb
);
1463 rtw_write_rf(rtwdev
, RF_PATH_A
, RF_LUTWE2
, 0x04, 0x00);
1465 rtw_write_rf(rtwdev
, RF_PATH_B
, RF_LUTWE2
, 0x04, 0x01);
1466 rtw_write_rf(rtwdev
, RF_PATH_B
, RF_LUTWA
, 0x1f, 0x12);
1467 rtw_write_rf(rtwdev
, RF_PATH_B
, RF_LUTWD0
, 0xfffff, rf_rxbb
);
1468 rtw_write_rf(rtwdev
, RF_PATH_B
, RF_LUTWE2
, 0x04, 0x00);
1470 rtw_write_rf(rtwdev
, RF_PATH_A
, RF_CFGCH
, RFREG_MASK
, rf_reg18
);
1471 rtw_write_rf(rtwdev
, RF_PATH_B
, RF_CFGCH
, RFREG_MASK
, rf_reg18
);
1473 rtw8822c_rstb_3wire(rtwdev
, true);
1476 static void rtw8822c_toggle_igi(struct rtw_dev
*rtwdev
)
1480 igi
= rtw_read32_mask(rtwdev
, REG_RXIGI
, 0x7f);
1481 rtw_write32_mask(rtwdev
, REG_RXIGI
, 0x7f, igi
- 2);
1482 rtw_write32_mask(rtwdev
, REG_RXIGI
, 0x7f00, igi
- 2);
1483 rtw_write32_mask(rtwdev
, REG_RXIGI
, 0x7f, igi
);
1484 rtw_write32_mask(rtwdev
, REG_RXIGI
, 0x7f00, igi
);
1487 static void rtw8822c_set_channel_bb(struct rtw_dev
*rtwdev
, u8 channel
, u8 bw
,
1490 if (IS_CH_2G_BAND(channel
)) {
1491 rtw_write32_clr(rtwdev
, REG_BGCTRL
, BITS_RX_IQ_WEIGHT
);
1492 rtw_write32_set(rtwdev
, REG_TXF4
, BIT(20));
1493 rtw_write32_clr(rtwdev
, REG_CCK_CHECK
, BIT_CHECK_CCK_EN
);
1494 rtw_write32_clr(rtwdev
, REG_CCKTXONLY
, BIT_BB_CCK_CHECK_EN
);
1495 rtw_write32_mask(rtwdev
, REG_CCAMSK
, 0x3F000000, 0xF);
1498 case RTW_CHANNEL_WIDTH_20
:
1499 rtw_write32_mask(rtwdev
, REG_RXAGCCTL0
, BITS_RXAGC_CCK
,
1501 rtw_write32_mask(rtwdev
, REG_RXAGCCTL
, BITS_RXAGC_CCK
,
1503 rtw_write32_mask(rtwdev
, REG_RXAGCCTL0
, BITS_RXAGC_OFDM
,
1505 rtw_write32_mask(rtwdev
, REG_RXAGCCTL
, BITS_RXAGC_OFDM
,
1508 case RTW_CHANNEL_WIDTH_40
:
1509 rtw_write32_mask(rtwdev
, REG_RXAGCCTL0
, BITS_RXAGC_CCK
,
1511 rtw_write32_mask(rtwdev
, REG_RXAGCCTL
, BITS_RXAGC_CCK
,
1513 rtw_write32_mask(rtwdev
, REG_RXAGCCTL0
, BITS_RXAGC_OFDM
,
1515 rtw_write32_mask(rtwdev
, REG_RXAGCCTL
, BITS_RXAGC_OFDM
,
1519 if (channel
== 13 || channel
== 14)
1520 rtw_write32_mask(rtwdev
, REG_SCOTRK
, 0xfff, 0x969);
1521 else if (channel
== 11 || channel
== 12)
1522 rtw_write32_mask(rtwdev
, REG_SCOTRK
, 0xfff, 0x96a);
1524 rtw_write32_mask(rtwdev
, REG_SCOTRK
, 0xfff, 0x9aa);
1525 if (channel
== 14) {
1526 rtw_write32_mask(rtwdev
, REG_TXF0
, MASKHWORD
, 0x3da0);
1527 rtw_write32_mask(rtwdev
, REG_TXF1
, MASKDWORD
,
1529 rtw_write32_mask(rtwdev
, REG_TXF2
, MASKLWORD
, 0x6aa3);
1530 rtw_write32_mask(rtwdev
, REG_TXF3
, MASKHWORD
, 0xaa7b);
1531 rtw_write32_mask(rtwdev
, REG_TXF4
, MASKLWORD
, 0xf3d7);
1532 rtw_write32_mask(rtwdev
, REG_TXF5
, MASKDWORD
, 0x0);
1533 rtw_write32_mask(rtwdev
, REG_TXF6
, MASKDWORD
,
1535 rtw_write32_mask(rtwdev
, REG_TXF7
, MASKDWORD
, 0xffff);
1537 rtw_write32_mask(rtwdev
, REG_TXF0
, MASKHWORD
, 0x5284);
1538 rtw_write32_mask(rtwdev
, REG_TXF1
, MASKDWORD
,
1540 rtw_write32_mask(rtwdev
, REG_TXF2
, MASKLWORD
, 0x0a88);
1541 rtw_write32_mask(rtwdev
, REG_TXF3
, MASKHWORD
, 0xacc4);
1542 rtw_write32_mask(rtwdev
, REG_TXF4
, MASKLWORD
, 0xc8b2);
1543 rtw_write32_mask(rtwdev
, REG_TXF5
, MASKDWORD
,
1545 rtw_write32_mask(rtwdev
, REG_TXF6
, MASKDWORD
,
1547 rtw_write32_mask(rtwdev
, REG_TXF7
, MASKDWORD
,
1551 rtw_write32_mask(rtwdev
, REG_TXDFIR0
, 0x70, 0x3);
1553 rtw_write32_mask(rtwdev
, REG_TXDFIR0
, 0x70, 0x1);
1554 } else if (IS_CH_5G_BAND(channel
)) {
1555 rtw_write32_set(rtwdev
, REG_CCKTXONLY
, BIT_BB_CCK_CHECK_EN
);
1556 rtw_write32_set(rtwdev
, REG_CCK_CHECK
, BIT_CHECK_CCK_EN
);
1557 rtw_write32_set(rtwdev
, REG_BGCTRL
, BITS_RX_IQ_WEIGHT
);
1558 rtw_write32_clr(rtwdev
, REG_TXF4
, BIT(20));
1559 rtw_write32_mask(rtwdev
, REG_CCAMSK
, 0x3F000000, 0x22);
1560 rtw_write32_mask(rtwdev
, REG_TXDFIR0
, 0x70, 0x3);
1561 if (IS_CH_5G_BAND_1(channel
) || IS_CH_5G_BAND_2(channel
)) {
1562 rtw_write32_mask(rtwdev
, REG_RXAGCCTL0
, BITS_RXAGC_OFDM
,
1564 rtw_write32_mask(rtwdev
, REG_RXAGCCTL
, BITS_RXAGC_OFDM
,
1566 } else if (IS_CH_5G_BAND_3(channel
)) {
1567 rtw_write32_mask(rtwdev
, REG_RXAGCCTL0
, BITS_RXAGC_OFDM
,
1569 rtw_write32_mask(rtwdev
, REG_RXAGCCTL
, BITS_RXAGC_OFDM
,
1571 } else if (IS_CH_5G_BAND_4(channel
)) {
1572 rtw_write32_mask(rtwdev
, REG_RXAGCCTL0
, BITS_RXAGC_OFDM
,
1574 rtw_write32_mask(rtwdev
, REG_RXAGCCTL
, BITS_RXAGC_OFDM
,
1578 if (channel
>= 36 && channel
<= 51)
1579 rtw_write32_mask(rtwdev
, REG_SCOTRK
, 0xfff, 0x494);
1580 else if (channel
>= 52 && channel
<= 55)
1581 rtw_write32_mask(rtwdev
, REG_SCOTRK
, 0xfff, 0x493);
1582 else if (channel
>= 56 && channel
<= 111)
1583 rtw_write32_mask(rtwdev
, REG_SCOTRK
, 0xfff, 0x453);
1584 else if (channel
>= 112 && channel
<= 119)
1585 rtw_write32_mask(rtwdev
, REG_SCOTRK
, 0xfff, 0x452);
1586 else if (channel
>= 120 && channel
<= 172)
1587 rtw_write32_mask(rtwdev
, REG_SCOTRK
, 0xfff, 0x412);
1588 else if (channel
>= 173 && channel
<= 177)
1589 rtw_write32_mask(rtwdev
, REG_SCOTRK
, 0xfff, 0x411);
1593 case RTW_CHANNEL_WIDTH_20
:
1594 rtw_write32_mask(rtwdev
, REG_DFIRBW
, 0x3FF0, 0x19B);
1595 rtw_write32_mask(rtwdev
, REG_TXBWCTL
, 0xf, 0x0);
1596 rtw_write32_mask(rtwdev
, REG_TXBWCTL
, 0xffc0, 0x0);
1597 rtw_write32_mask(rtwdev
, REG_TXCLK
, 0x700, 0x7);
1598 rtw_write32_mask(rtwdev
, REG_TXCLK
, 0x700000, 0x6);
1599 rtw_write32_mask(rtwdev
, REG_CCK_SOURCE
, BIT_NBI_EN
, 0x0);
1600 rtw_write32_mask(rtwdev
, REG_SBD
, BITS_SUBTUNE
, 0x1);
1601 rtw_write32_mask(rtwdev
, REG_PT_CHSMO
, BIT_PT_OPT
, 0x0);
1603 case RTW_CHANNEL_WIDTH_40
:
1604 rtw_write32_mask(rtwdev
, REG_CCKSB
, BIT(4),
1605 (primary_ch_idx
== RTW_SC_20_UPPER
? 1 : 0));
1606 rtw_write32_mask(rtwdev
, REG_TXBWCTL
, 0xf, 0x5);
1607 rtw_write32_mask(rtwdev
, REG_TXBWCTL
, 0xc0, 0x0);
1608 rtw_write32_mask(rtwdev
, REG_TXBWCTL
, 0xff00,
1609 (primary_ch_idx
| (primary_ch_idx
<< 4)));
1610 rtw_write32_mask(rtwdev
, REG_CCK_SOURCE
, BIT_NBI_EN
, 0x1);
1611 rtw_write32_mask(rtwdev
, REG_SBD
, BITS_SUBTUNE
, 0x1);
1612 rtw_write32_mask(rtwdev
, REG_PT_CHSMO
, BIT_PT_OPT
, 0x1);
1614 case RTW_CHANNEL_WIDTH_80
:
1615 rtw_write32_mask(rtwdev
, REG_TXBWCTL
, 0xf, 0xa);
1616 rtw_write32_mask(rtwdev
, REG_TXBWCTL
, 0xc0, 0x0);
1617 rtw_write32_mask(rtwdev
, REG_TXBWCTL
, 0xff00,
1618 (primary_ch_idx
| (primary_ch_idx
<< 4)));
1619 rtw_write32_mask(rtwdev
, REG_SBD
, BITS_SUBTUNE
, 0x6);
1620 rtw_write32_mask(rtwdev
, REG_PT_CHSMO
, BIT_PT_OPT
, 0x1);
1622 case RTW_CHANNEL_WIDTH_5
:
1623 rtw_write32_mask(rtwdev
, REG_DFIRBW
, 0x3FF0, 0x2AB);
1624 rtw_write32_mask(rtwdev
, REG_TXBWCTL
, 0xf, 0x0);
1625 rtw_write32_mask(rtwdev
, REG_TXBWCTL
, 0xffc0, 0x1);
1626 rtw_write32_mask(rtwdev
, REG_TXCLK
, 0x700, 0x4);
1627 rtw_write32_mask(rtwdev
, REG_TXCLK
, 0x700000, 0x4);
1628 rtw_write32_mask(rtwdev
, REG_CCK_SOURCE
, BIT_NBI_EN
, 0x0);
1629 rtw_write32_mask(rtwdev
, REG_SBD
, BITS_SUBTUNE
, 0x1);
1630 rtw_write32_mask(rtwdev
, REG_PT_CHSMO
, BIT_PT_OPT
, 0x0);
1632 case RTW_CHANNEL_WIDTH_10
:
1633 rtw_write32_mask(rtwdev
, REG_DFIRBW
, 0x3FF0, 0x2AB);
1634 rtw_write32_mask(rtwdev
, REG_TXBWCTL
, 0xf, 0x0);
1635 rtw_write32_mask(rtwdev
, REG_TXBWCTL
, 0xffc0, 0x2);
1636 rtw_write32_mask(rtwdev
, REG_TXCLK
, 0x700, 0x6);
1637 rtw_write32_mask(rtwdev
, REG_TXCLK
, 0x700000, 0x5);
1638 rtw_write32_mask(rtwdev
, REG_CCK_SOURCE
, BIT_NBI_EN
, 0x0);
1639 rtw_write32_mask(rtwdev
, REG_SBD
, BITS_SUBTUNE
, 0x1);
1640 rtw_write32_mask(rtwdev
, REG_PT_CHSMO
, BIT_PT_OPT
, 0x0);
1645 static void rtw8822c_set_channel(struct rtw_dev
*rtwdev
, u8 channel
, u8 bw
,
1646 u8 primary_chan_idx
)
1648 rtw8822c_set_channel_bb(rtwdev
, channel
, bw
, primary_chan_idx
);
1649 rtw_set_channel_mac(rtwdev
, channel
, bw
, primary_chan_idx
);
1650 rtw8822c_set_channel_rf(rtwdev
, channel
, bw
);
1651 rtw8822c_toggle_igi(rtwdev
);
1654 static void rtw8822c_config_cck_rx_path(struct rtw_dev
*rtwdev
, u8 rx_path
)
1656 if (rx_path
== BB_PATH_A
|| rx_path
== BB_PATH_B
) {
1657 rtw_write32_mask(rtwdev
, REG_CCANRX
, 0x00060000, 0x0);
1658 rtw_write32_mask(rtwdev
, REG_CCANRX
, 0x00600000, 0x0);
1659 } else if (rx_path
== BB_PATH_AB
) {
1660 rtw_write32_mask(rtwdev
, REG_CCANRX
, 0x00600000, 0x1);
1661 rtw_write32_mask(rtwdev
, REG_CCANRX
, 0x00060000, 0x1);
1664 if (rx_path
== BB_PATH_A
)
1665 rtw_write32_mask(rtwdev
, REG_RXCCKSEL
, 0x0f000000, 0x0);
1666 else if (rx_path
== BB_PATH_B
)
1667 rtw_write32_mask(rtwdev
, REG_RXCCKSEL
, 0x0f000000, 0x5);
1668 else if (rx_path
== BB_PATH_AB
)
1669 rtw_write32_mask(rtwdev
, REG_RXCCKSEL
, 0x0f000000, 0x1);
1672 static void rtw8822c_config_ofdm_rx_path(struct rtw_dev
*rtwdev
, u8 rx_path
)
1674 if (rx_path
== BB_PATH_A
|| rx_path
== BB_PATH_B
) {
1675 rtw_write32_mask(rtwdev
, REG_RXFNCTL
, 0x300, 0x0);
1676 rtw_write32_mask(rtwdev
, REG_RXFNCTL
, 0x600000, 0x0);
1677 rtw_write32_mask(rtwdev
, REG_AGCSWSH
, BIT(17), 0x0);
1678 rtw_write32_mask(rtwdev
, REG_ANTWTPD
, BIT(20), 0x0);
1679 rtw_write32_mask(rtwdev
, REG_MRCM
, BIT(24), 0x0);
1680 } else if (rx_path
== BB_PATH_AB
) {
1681 rtw_write32_mask(rtwdev
, REG_RXFNCTL
, 0x300, 0x1);
1682 rtw_write32_mask(rtwdev
, REG_RXFNCTL
, 0x600000, 0x1);
1683 rtw_write32_mask(rtwdev
, REG_AGCSWSH
, BIT(17), 0x1);
1684 rtw_write32_mask(rtwdev
, REG_ANTWTPD
, BIT(20), 0x1);
1685 rtw_write32_mask(rtwdev
, REG_MRCM
, BIT(24), 0x1);
1688 rtw_write32_mask(rtwdev
, 0x824, 0x0f000000, rx_path
);
1689 rtw_write32_mask(rtwdev
, 0x824, 0x000f0000, rx_path
);
1692 static void rtw8822c_config_rx_path(struct rtw_dev
*rtwdev
, u8 rx_path
)
1694 rtw8822c_config_cck_rx_path(rtwdev
, rx_path
);
1695 rtw8822c_config_ofdm_rx_path(rtwdev
, rx_path
);
1698 static void rtw8822c_config_cck_tx_path(struct rtw_dev
*rtwdev
, u8 tx_path
,
1701 if (tx_path
== BB_PATH_A
) {
1702 rtw_write32_mask(rtwdev
, REG_RXCCKSEL
, 0xf0000000, 0x8);
1703 } else if (tx_path
== BB_PATH_B
) {
1704 rtw_write32_mask(rtwdev
, REG_RXCCKSEL
, 0xf0000000, 0x4);
1707 rtw_write32_mask(rtwdev
, REG_RXCCKSEL
, 0xf0000000, 0xc);
1709 rtw_write32_mask(rtwdev
, REG_RXCCKSEL
, 0xf0000000, 0x8);
1713 static void rtw8822c_config_ofdm_tx_path(struct rtw_dev
*rtwdev
, u8 tx_path
,
1716 if (tx_path
== BB_PATH_A
) {
1717 rtw_write32_mask(rtwdev
, REG_ANTMAP0
, 0xff, 0x11);
1718 rtw_write32_mask(rtwdev
, REG_TXLGMAP
, 0xff, 0x0);
1719 } else if (tx_path
== BB_PATH_B
) {
1720 rtw_write32_mask(rtwdev
, REG_ANTMAP0
, 0xff, 0x12);
1721 rtw_write32_mask(rtwdev
, REG_TXLGMAP
, 0xff, 0x0);
1724 rtw_write32_mask(rtwdev
, REG_ANTMAP0
, 0xff, 0x33);
1725 rtw_write32_mask(rtwdev
, REG_TXLGMAP
, 0xffff, 0x0404);
1727 rtw_write32_mask(rtwdev
, REG_ANTMAP0
, 0xff, 0x31);
1728 rtw_write32_mask(rtwdev
, REG_TXLGMAP
, 0xffff, 0x0400);
1733 static void rtw8822c_config_tx_path(struct rtw_dev
*rtwdev
, u8 tx_path
,
1736 rtw8822c_config_cck_tx_path(rtwdev
, tx_path
, is_tx2_path
);
1737 rtw8822c_config_ofdm_tx_path(rtwdev
, tx_path
, is_tx2_path
);
1740 static void rtw8822c_config_trx_mode(struct rtw_dev
*rtwdev
, u8 tx_path
,
1741 u8 rx_path
, bool is_tx2_path
)
1743 if ((tx_path
| rx_path
) & BB_PATH_A
)
1744 rtw_write32_mask(rtwdev
, REG_ORITXCODE
, MASK20BITS
, 0x33312);
1746 rtw_write32_mask(rtwdev
, REG_ORITXCODE
, MASK20BITS
, 0x11111);
1747 if ((tx_path
| rx_path
) & BB_PATH_B
)
1748 rtw_write32_mask(rtwdev
, REG_ORITXCODE2
, MASK20BITS
, 0x33312);
1750 rtw_write32_mask(rtwdev
, REG_ORITXCODE2
, MASK20BITS
, 0x11111);
1752 rtw8822c_config_rx_path(rtwdev
, rx_path
);
1753 rtw8822c_config_tx_path(rtwdev
, tx_path
, is_tx2_path
);
1755 rtw8822c_toggle_igi(rtwdev
);
1758 static void query_phy_status_page0(struct rtw_dev
*rtwdev
, u8
*phy_status
,
1759 struct rtw_rx_pkt_stat
*pkt_stat
)
1761 struct rtw_dm_info
*dm_info
= &rtwdev
->dm_info
;
1764 s8 rx_power
[RTW_RF_PATH_MAX
];
1765 s8 min_rx_power
= -120;
1769 rx_power
[RF_PATH_A
] = GET_PHY_STAT_P0_PWDB_A(phy_status
);
1770 rx_power
[RF_PATH_B
] = GET_PHY_STAT_P0_PWDB_B(phy_status
);
1771 l_bnd
= dm_info
->cck_gi_l_bnd
;
1772 u_bnd
= dm_info
->cck_gi_u_bnd
;
1773 gain_a
= GET_PHY_STAT_P0_GAIN_A(phy_status
);
1774 gain_b
= GET_PHY_STAT_P0_GAIN_B(phy_status
);
1776 rx_power
[RF_PATH_A
] += (l_bnd
- gain_a
) << 1;
1777 else if (gain_a
> u_bnd
)
1778 rx_power
[RF_PATH_A
] -= (gain_a
- u_bnd
) << 1;
1780 rx_power
[RF_PATH_B
] += (l_bnd
- gain_b
) << 1;
1781 else if (gain_b
> u_bnd
)
1782 rx_power
[RF_PATH_B
] -= (gain_b
- u_bnd
) << 1;
1784 rx_power
[RF_PATH_A
] -= 110;
1785 rx_power
[RF_PATH_B
] -= 110;
1787 pkt_stat
->rx_power
[RF_PATH_A
] = rx_power
[RF_PATH_A
];
1788 pkt_stat
->rx_power
[RF_PATH_B
] = rx_power
[RF_PATH_B
];
1790 for (path
= 0; path
<= rtwdev
->hal
.rf_path_num
; path
++) {
1791 rssi
= rtw_phy_rf_power_2_rssi(&pkt_stat
->rx_power
[path
], 1);
1792 dm_info
->rssi
[path
] = rssi
;
1795 pkt_stat
->rssi
= rtw_phy_rf_power_2_rssi(pkt_stat
->rx_power
, 1);
1796 pkt_stat
->bw
= RTW_CHANNEL_WIDTH_20
;
1797 pkt_stat
->signal_power
= max(pkt_stat
->rx_power
[RF_PATH_A
],
1801 static void query_phy_status_page1(struct rtw_dev
*rtwdev
, u8
*phy_status
,
1802 struct rtw_rx_pkt_stat
*pkt_stat
)
1804 struct rtw_dm_info
*dm_info
= &rtwdev
->dm_info
;
1806 s8 min_rx_power
= -120;
1812 if (pkt_stat
->rate
> DESC_RATE11M
&& pkt_stat
->rate
< DESC_RATEMCS0
)
1813 rxsc
= GET_PHY_STAT_P1_L_RXSC(phy_status
);
1815 rxsc
= GET_PHY_STAT_P1_HT_RXSC(phy_status
);
1817 if (rxsc
>= 9 && rxsc
<= 12)
1818 bw
= RTW_CHANNEL_WIDTH_40
;
1819 else if (rxsc
>= 13)
1820 bw
= RTW_CHANNEL_WIDTH_80
;
1822 bw
= RTW_CHANNEL_WIDTH_20
;
1824 pkt_stat
->rx_power
[RF_PATH_A
] = GET_PHY_STAT_P1_PWDB_A(phy_status
) - 110;
1825 pkt_stat
->rx_power
[RF_PATH_B
] = GET_PHY_STAT_P1_PWDB_B(phy_status
) - 110;
1826 pkt_stat
->rssi
= rtw_phy_rf_power_2_rssi(pkt_stat
->rx_power
, 2);
1828 pkt_stat
->signal_power
= max3(pkt_stat
->rx_power
[RF_PATH_A
],
1829 pkt_stat
->rx_power
[RF_PATH_B
],
1832 dm_info
->curr_rx_rate
= pkt_stat
->rate
;
1834 pkt_stat
->rx_evm
[RF_PATH_A
] = GET_PHY_STAT_P1_RXEVM_A(phy_status
);
1835 pkt_stat
->rx_evm
[RF_PATH_B
] = GET_PHY_STAT_P1_RXEVM_B(phy_status
);
1837 pkt_stat
->rx_snr
[RF_PATH_A
] = GET_PHY_STAT_P1_RXSNR_A(phy_status
);
1838 pkt_stat
->rx_snr
[RF_PATH_B
] = GET_PHY_STAT_P1_RXSNR_B(phy_status
);
1840 pkt_stat
->cfo_tail
[RF_PATH_A
] = GET_PHY_STAT_P1_CFO_TAIL_A(phy_status
);
1841 pkt_stat
->cfo_tail
[RF_PATH_B
] = GET_PHY_STAT_P1_CFO_TAIL_B(phy_status
);
1843 for (path
= 0; path
<= rtwdev
->hal
.rf_path_num
; path
++) {
1844 rssi
= rtw_phy_rf_power_2_rssi(&pkt_stat
->rx_power
[path
], 1);
1845 dm_info
->rssi
[path
] = rssi
;
1846 dm_info
->rx_snr
[path
] = pkt_stat
->rx_snr
[path
] >> 1;
1847 dm_info
->cfo_tail
[path
] = (pkt_stat
->cfo_tail
[path
] * 5) >> 1;
1849 rx_evm
= pkt_stat
->rx_evm
[path
];
1852 if (rx_evm
== S8_MIN
)
1855 evm_dbm
= ((u8
)-rx_evm
>> 1);
1857 dm_info
->rx_evm_dbm
[path
] = evm_dbm
;
1861 static void query_phy_status(struct rtw_dev
*rtwdev
, u8
*phy_status
,
1862 struct rtw_rx_pkt_stat
*pkt_stat
)
1866 page
= *phy_status
& 0xf;
1870 query_phy_status_page0(rtwdev
, phy_status
, pkt_stat
);
1873 query_phy_status_page1(rtwdev
, phy_status
, pkt_stat
);
1876 rtw_warn(rtwdev
, "unused phy status page (%d)\n", page
);
1881 static void rtw8822c_query_rx_desc(struct rtw_dev
*rtwdev
, u8
*rx_desc
,
1882 struct rtw_rx_pkt_stat
*pkt_stat
,
1883 struct ieee80211_rx_status
*rx_status
)
1885 struct ieee80211_hdr
*hdr
;
1886 u32 desc_sz
= rtwdev
->chip
->rx_pkt_desc_sz
;
1887 u8
*phy_status
= NULL
;
1889 memset(pkt_stat
, 0, sizeof(*pkt_stat
));
1891 pkt_stat
->phy_status
= GET_RX_DESC_PHYST(rx_desc
);
1892 pkt_stat
->icv_err
= GET_RX_DESC_ICV_ERR(rx_desc
);
1893 pkt_stat
->crc_err
= GET_RX_DESC_CRC32(rx_desc
);
1894 pkt_stat
->decrypted
= !GET_RX_DESC_SWDEC(rx_desc
) &&
1895 GET_RX_DESC_ENC_TYPE(rx_desc
) != RX_DESC_ENC_NONE
;
1896 pkt_stat
->is_c2h
= GET_RX_DESC_C2H(rx_desc
);
1897 pkt_stat
->pkt_len
= GET_RX_DESC_PKT_LEN(rx_desc
);
1898 pkt_stat
->drv_info_sz
= GET_RX_DESC_DRV_INFO_SIZE(rx_desc
);
1899 pkt_stat
->shift
= GET_RX_DESC_SHIFT(rx_desc
);
1900 pkt_stat
->rate
= GET_RX_DESC_RX_RATE(rx_desc
);
1901 pkt_stat
->cam_id
= GET_RX_DESC_MACID(rx_desc
);
1902 pkt_stat
->ppdu_cnt
= GET_RX_DESC_PPDU_CNT(rx_desc
);
1903 pkt_stat
->tsf_low
= GET_RX_DESC_TSFL(rx_desc
);
1905 /* drv_info_sz is in unit of 8-bytes */
1906 pkt_stat
->drv_info_sz
*= 8;
1908 /* c2h cmd pkt's rx/phy status is not interested */
1909 if (pkt_stat
->is_c2h
)
1912 hdr
= (struct ieee80211_hdr
*)(rx_desc
+ desc_sz
+ pkt_stat
->shift
+
1913 pkt_stat
->drv_info_sz
);
1914 if (pkt_stat
->phy_status
) {
1915 phy_status
= rx_desc
+ desc_sz
+ pkt_stat
->shift
;
1916 query_phy_status(rtwdev
, phy_status
, pkt_stat
);
1919 rtw_rx_fill_rx_status(rtwdev
, pkt_stat
, hdr
, rx_status
, phy_status
);
1923 rtw8822c_set_write_tx_power_ref(struct rtw_dev
*rtwdev
, u8
*tx_pwr_ref_cck
,
1924 u8
*tx_pwr_ref_ofdm
)
1926 struct rtw_hal
*hal
= &rtwdev
->hal
;
1927 u32 txref_cck
[2] = {0x18a0, 0x41a0};
1928 u32 txref_ofdm
[2] = {0x18e8, 0x41e8};
1931 for (path
= 0; path
< hal
->rf_path_num
; path
++) {
1932 rtw_write32_mask(rtwdev
, 0x1c90, BIT(15), 0);
1933 rtw_write32_mask(rtwdev
, txref_cck
[path
], 0x7f0000,
1934 tx_pwr_ref_cck
[path
]);
1936 for (path
= 0; path
< hal
->rf_path_num
; path
++) {
1937 rtw_write32_mask(rtwdev
, 0x1c90, BIT(15), 0);
1938 rtw_write32_mask(rtwdev
, txref_ofdm
[path
], 0x1fc00,
1939 tx_pwr_ref_ofdm
[path
]);
1943 static void rtw8822c_set_tx_power_diff(struct rtw_dev
*rtwdev
, u8 rate
,
1946 u32 offset_txagc
= 0x3a00;
1947 u8 rate_idx
= rate
& 0xfc;
1952 for (i
= 0; i
< 4; i
++)
1953 pwr_idx
[i
] = diff_idx
[i
] & 0x7f;
1955 phy_pwr_idx
= pwr_idx
[0] |
1957 (pwr_idx
[2] << 16) |
1960 rtw_write32_mask(rtwdev
, 0x1c90, BIT(15), 0x0);
1961 rtw_write32_mask(rtwdev
, offset_txagc
+ rate_idx
, MASKDWORD
,
1965 static void rtw8822c_set_tx_power_index(struct rtw_dev
*rtwdev
)
1967 struct rtw_hal
*hal
= &rtwdev
->hal
;
1969 u8 pwr_ref_cck
[2] = {hal
->tx_pwr_tbl
[RF_PATH_A
][DESC_RATE11M
],
1970 hal
->tx_pwr_tbl
[RF_PATH_B
][DESC_RATE11M
]};
1971 u8 pwr_ref_ofdm
[2] = {hal
->tx_pwr_tbl
[RF_PATH_A
][DESC_RATEMCS7
],
1972 hal
->tx_pwr_tbl
[RF_PATH_B
][DESC_RATEMCS7
]};
1977 rtw8822c_set_write_tx_power_ref(rtwdev
, pwr_ref_cck
, pwr_ref_ofdm
);
1978 for (rs
= 0; rs
< RTW_RATE_SECTION_MAX
; rs
++) {
1979 for (j
= 0; j
< rtw_rate_size
[rs
]; j
++) {
1980 rate
= rtw_rate_section
[rs
][j
];
1981 pwr_a
= hal
->tx_pwr_tbl
[RF_PATH_A
][rate
];
1982 pwr_b
= hal
->tx_pwr_tbl
[RF_PATH_B
][rate
];
1984 diff_a
= (s8
)pwr_a
- (s8
)pwr_ref_cck
[0];
1985 diff_b
= (s8
)pwr_b
- (s8
)pwr_ref_cck
[1];
1987 diff_a
= (s8
)pwr_a
- (s8
)pwr_ref_ofdm
[0];
1988 diff_b
= (s8
)pwr_b
- (s8
)pwr_ref_ofdm
[1];
1990 diff_idx
[rate
% 4] = min(diff_a
, diff_b
);
1992 rtw8822c_set_tx_power_diff(rtwdev
, rate
- 3,
1998 static int rtw8822c_set_antenna(struct rtw_dev
*rtwdev
,
2002 struct rtw_hal
*hal
= &rtwdev
->hal
;
2004 switch (antenna_tx
) {
2010 rtw_info(rtwdev
, "unsupported tx path 0x%x\n", antenna_tx
);
2014 /* path B only is not available for RX */
2015 switch (antenna_rx
) {
2020 rtw_info(rtwdev
, "unsupported rx path 0x%x\n", antenna_rx
);
2024 hal
->antenna_tx
= antenna_tx
;
2025 hal
->antenna_rx
= antenna_rx
;
2027 rtw8822c_config_trx_mode(rtwdev
, antenna_tx
, antenna_rx
, false);
2032 static void rtw8822c_cfg_ldo25(struct rtw_dev
*rtwdev
, bool enable
)
2036 ldo_pwr
= rtw_read8(rtwdev
, REG_ANAPARLDO_POW_MAC
);
2037 ldo_pwr
= enable
? ldo_pwr
| BIT_LDOE25_PON
: ldo_pwr
& ~BIT_LDOE25_PON
;
2038 rtw_write8(rtwdev
, REG_ANAPARLDO_POW_MAC
, ldo_pwr
);
2041 static void rtw8822c_false_alarm_statistics(struct rtw_dev
*rtwdev
)
2043 struct rtw_dm_info
*dm_info
= &rtwdev
->dm_info
;
2049 u32 ofdm_fa_cnt1
, ofdm_fa_cnt2
, ofdm_fa_cnt3
, ofdm_fa_cnt4
, ofdm_fa_cnt5
;
2050 u16 parity_fail
, rate_illegal
, crc8_fail
, mcs_fail
, sb_search_fail
,
2051 fast_fsync
, crc8_fail_vhta
, mcs_fail_vht
;
2053 cck_enable
= rtw_read32(rtwdev
, REG_ENCCK
) & BIT_CCK_BLK_EN
;
2054 cck_fa_cnt
= rtw_read16(rtwdev
, REG_CCK_FACNT
);
2056 ofdm_fa_cnt1
= rtw_read32(rtwdev
, REG_OFDM_FACNT1
);
2057 ofdm_fa_cnt2
= rtw_read32(rtwdev
, REG_OFDM_FACNT2
);
2058 ofdm_fa_cnt3
= rtw_read32(rtwdev
, REG_OFDM_FACNT3
);
2059 ofdm_fa_cnt4
= rtw_read32(rtwdev
, REG_OFDM_FACNT4
);
2060 ofdm_fa_cnt5
= rtw_read32(rtwdev
, REG_OFDM_FACNT5
);
2062 parity_fail
= FIELD_GET(GENMASK(31, 16), ofdm_fa_cnt1
);
2063 rate_illegal
= FIELD_GET(GENMASK(15, 0), ofdm_fa_cnt2
);
2064 crc8_fail
= FIELD_GET(GENMASK(31, 16), ofdm_fa_cnt2
);
2065 crc8_fail_vhta
= FIELD_GET(GENMASK(15, 0), ofdm_fa_cnt3
);
2066 mcs_fail
= FIELD_GET(GENMASK(15, 0), ofdm_fa_cnt4
);
2067 mcs_fail_vht
= FIELD_GET(GENMASK(31, 16), ofdm_fa_cnt4
);
2068 fast_fsync
= FIELD_GET(GENMASK(15, 0), ofdm_fa_cnt5
);
2069 sb_search_fail
= FIELD_GET(GENMASK(31, 16), ofdm_fa_cnt5
);
2071 ofdm_fa_cnt
= parity_fail
+ rate_illegal
+ crc8_fail
+ crc8_fail_vhta
+
2072 mcs_fail
+ mcs_fail_vht
+ fast_fsync
+ sb_search_fail
;
2074 dm_info
->cck_fa_cnt
= cck_fa_cnt
;
2075 dm_info
->ofdm_fa_cnt
= ofdm_fa_cnt
;
2076 dm_info
->total_fa_cnt
= ofdm_fa_cnt
;
2077 dm_info
->total_fa_cnt
+= cck_enable
? cck_fa_cnt
: 0;
2079 crc32_cnt
= rtw_read32(rtwdev
, 0x2c04);
2080 dm_info
->cck_ok_cnt
= crc32_cnt
& 0xffff;
2081 dm_info
->cck_err_cnt
= (crc32_cnt
& 0xffff0000) >> 16;
2082 crc32_cnt
= rtw_read32(rtwdev
, 0x2c14);
2083 dm_info
->ofdm_ok_cnt
= crc32_cnt
& 0xffff;
2084 dm_info
->ofdm_err_cnt
= (crc32_cnt
& 0xffff0000) >> 16;
2085 crc32_cnt
= rtw_read32(rtwdev
, 0x2c10);
2086 dm_info
->ht_ok_cnt
= crc32_cnt
& 0xffff;
2087 dm_info
->ht_err_cnt
= (crc32_cnt
& 0xffff0000) >> 16;
2088 crc32_cnt
= rtw_read32(rtwdev
, 0x2c0c);
2089 dm_info
->vht_ok_cnt
= crc32_cnt
& 0xffff;
2090 dm_info
->vht_err_cnt
= (crc32_cnt
& 0xffff0000) >> 16;
2092 cca32_cnt
= rtw_read32(rtwdev
, 0x2c08);
2093 dm_info
->ofdm_cca_cnt
= ((cca32_cnt
& 0xffff0000) >> 16);
2094 dm_info
->cck_cca_cnt
= cca32_cnt
& 0xffff;
2095 dm_info
->total_cca_cnt
= dm_info
->ofdm_cca_cnt
;
2097 dm_info
->total_cca_cnt
+= dm_info
->cck_cca_cnt
;
2099 rtw_write32_mask(rtwdev
, REG_CCANRX
, BIT_CCK_FA_RST
, 0);
2100 rtw_write32_mask(rtwdev
, REG_CCANRX
, BIT_CCK_FA_RST
, 2);
2101 rtw_write32_mask(rtwdev
, REG_CCANRX
, BIT_OFDM_FA_RST
, 0);
2102 rtw_write32_mask(rtwdev
, REG_CCANRX
, BIT_OFDM_FA_RST
, 2);
2104 /* disable rx clk gating to reset counters */
2105 rtw_write32_clr(rtwdev
, REG_RX_BREAK
, BIT_COM_RX_GCK_EN
);
2106 rtw_write32_set(rtwdev
, REG_CNT_CTRL
, BIT_ALL_CNT_RST
);
2107 rtw_write32_clr(rtwdev
, REG_CNT_CTRL
, BIT_ALL_CNT_RST
);
2108 rtw_write32_set(rtwdev
, REG_RX_BREAK
, BIT_COM_RX_GCK_EN
);
2111 static void rtw8822c_do_iqk(struct rtw_dev
*rtwdev
)
2113 struct rtw_iqk_para para
= {0};
2118 rtw_fw_do_iqk(rtwdev
, ¶
);
2120 ret
= read_poll_timeout(rtw_read8
, iqk_chk
, iqk_chk
== IQK_DONE_8822C
,
2121 20000, 300000, false, rtwdev
, REG_RPT_CIP
);
2123 rtw_warn(rtwdev
, "failed to poll iqk status bit\n");
2125 rtw_write8(rtwdev
, REG_IQKSTAT
, 0x0);
2129 static void rtw8822c_coex_cfg_init(struct rtw_dev
*rtwdev
)
2131 /* enable TBTT nterrupt */
2132 rtw_write8_set(rtwdev
, REG_BCN_CTRL
, BIT_EN_BCN_FUNCTION
);
2134 /* BT report packet sample rate */
2135 /* 0x790[5:0]=0x5 */
2136 rtw_write8_mask(rtwdev
, REG_BT_TDMA_TIME
, BIT_MASK_SAMPLE_RATE
, 0x5);
2138 /* enable BT counter statistics */
2139 rtw_write8(rtwdev
, REG_BT_STAT_CTRL
, 0x1);
2141 /* enable PTA (3-wire function form BT side) */
2142 rtw_write32_set(rtwdev
, REG_GPIO_MUXCFG
, BIT_BT_PTA_EN
);
2143 rtw_write32_set(rtwdev
, REG_GPIO_MUXCFG
, BIT_PO_BT_PTA_PINS
);
2145 /* enable PTA (tx/rx signal form WiFi side) */
2146 rtw_write8_set(rtwdev
, REG_QUEUE_CTRL
, BIT_PTA_WL_TX_EN
);
2147 /* wl tx signal to PTA not case EDCCA */
2148 rtw_write8_clr(rtwdev
, REG_QUEUE_CTRL
, BIT_PTA_EDCCA_EN
);
2149 /* GNT_BT=1 while select both */
2150 rtw_write16_set(rtwdev
, REG_BT_COEX_V2
, BIT_GNT_BT_POLARITY
);
2151 /* BT_CCA = ~GNT_WL_BB, not or GNT_BT_BB, LTE_Rx */
2152 rtw_write8_clr(rtwdev
, REG_DUMMY_PAGE4_V1
, BIT_BTCCA_CTRL
);
2154 /* to avoid RF parameter error */
2155 rtw_write_rf(rtwdev
, RF_PATH_B
, RF_MODOPT
, 0xfffff, 0x40000);
2158 static void rtw8822c_coex_cfg_gnt_fix(struct rtw_dev
*rtwdev
)
2160 struct rtw_coex
*coex
= &rtwdev
->coex
;
2161 struct rtw_coex_stat
*coex_stat
= &coex
->stat
;
2162 struct rtw_efuse
*efuse
= &rtwdev
->efuse
;
2165 if (coex_stat
->gnt_workaround_state
== coex_stat
->wl_coex_mode
)
2168 coex_stat
->gnt_workaround_state
= coex_stat
->wl_coex_mode
;
2170 if ((coex_stat
->kt_ver
== 0 && coex
->under_5g
) || coex
->freerun
)
2175 /* BT at S1 for Shared-Ant */
2176 if (efuse
->share_ant
)
2179 rtw_write_rf(rtwdev
, RF_PATH_B
, 0x1, 0xfffff, rf_0x1
);
2181 /* WL-S0 2G RF TRX cannot be masked by GNT_BT
2182 * enable "WLS0 BB chage RF mode if GNT_BT = 1" for shared-antenna type
2183 * disable:0x1860[3] = 1, enable:0x1860[3] = 0
2185 * enable "DAC off if GNT_WL = 0" for non-shared-antenna
2186 * disable 0x1c30[22] = 0,
2187 * enable: 0x1c30[22] = 1, 0x1c38[12] = 0, 0x1c38[28] = 1
2189 * disable WL-S1 BB chage RF mode if GNT_BT
2190 * since RF TRx mask can do it
2192 rtw_write8_mask(rtwdev
, REG_ANAPAR
+ 2, BIT_ANAPAR_BTPS
>> 16, 1);
2193 rtw_write8_mask(rtwdev
, REG_RSTB_SEL
+ 1, BIT_DAC_OFF_ENABLE
, 0);
2194 rtw_write8_mask(rtwdev
, REG_RSTB_SEL
+ 3, BIT_DAC_OFF_ENABLE
, 1);
2195 rtw_write8_mask(rtwdev
, REG_IGN_GNTBT4
, BIT_PI_IGNORE_GNT_BT
, 1);
2197 /* disable WL-S0 BB chage RF mode if wifi is at 5G,
2198 * or antenna path is separated
2200 if (coex_stat
->wl_coex_mode
== COEX_WLINK_5G
||
2201 coex
->under_5g
|| !efuse
->share_ant
) {
2202 if (coex_stat
->kt_ver
>= 3) {
2203 rtw_write8_mask(rtwdev
, REG_IGN_GNT_BT1
,
2204 BIT_PI_IGNORE_GNT_BT
, 0);
2205 rtw_write8_mask(rtwdev
, REG_NOMASK_TXBT
,
2206 BIT_NOMASK_TXBT_ENABLE
, 1);
2208 rtw_write8_mask(rtwdev
, REG_IGN_GNT_BT1
,
2209 BIT_PI_IGNORE_GNT_BT
, 1);
2212 /* shared-antenna */
2213 rtw_write8_mask(rtwdev
, REG_IGN_GNT_BT1
,
2214 BIT_PI_IGNORE_GNT_BT
, 0);
2215 if (coex_stat
->kt_ver
>= 3) {
2216 rtw_write8_mask(rtwdev
, REG_NOMASK_TXBT
,
2217 BIT_NOMASK_TXBT_ENABLE
, 0);
2222 static void rtw8822c_coex_cfg_gnt_debug(struct rtw_dev
*rtwdev
)
2224 rtw_write8_mask(rtwdev
, REG_PAD_CTRL1
+ 2, BIT_BTGP_SPI_EN
>> 16, 0);
2225 rtw_write8_mask(rtwdev
, REG_PAD_CTRL1
+ 3, BIT_BTGP_JTAG_EN
>> 24, 0);
2226 rtw_write8_mask(rtwdev
, REG_GPIO_MUXCFG
+ 2, BIT_FSPI_EN
>> 16, 0);
2227 rtw_write8_mask(rtwdev
, REG_PAD_CTRL1
+ 1, BIT_LED1DIS
>> 8, 0);
2228 rtw_write8_mask(rtwdev
, REG_SYS_SDIO_CTRL
+ 3, BIT_DBG_GNT_WL_BT
>> 24, 0);
2231 static void rtw8822c_coex_cfg_rfe_type(struct rtw_dev
*rtwdev
)
2233 struct rtw_coex
*coex
= &rtwdev
->coex
;
2234 struct rtw_coex_rfe
*coex_rfe
= &coex
->rfe
;
2235 struct rtw_efuse
*efuse
= &rtwdev
->efuse
;
2237 coex_rfe
->rfe_module_type
= rtwdev
->efuse
.rfe_option
;
2238 coex_rfe
->ant_switch_polarity
= 0;
2239 coex_rfe
->ant_switch_exist
= false;
2240 coex_rfe
->ant_switch_with_bt
= false;
2241 coex_rfe
->ant_switch_diversity
= false;
2243 if (efuse
->share_ant
)
2244 coex_rfe
->wlg_at_btg
= true;
2246 coex_rfe
->wlg_at_btg
= false;
2248 /* disable LTE coex in wifi side */
2249 rtw_coex_write_indirect_reg(rtwdev
, LTE_COEX_CTRL
, BIT_LTE_COEX_EN
, 0x0);
2250 rtw_coex_write_indirect_reg(rtwdev
, LTE_WL_TRX_CTRL
, MASKLWORD
, 0xffff);
2251 rtw_coex_write_indirect_reg(rtwdev
, LTE_BT_TRX_CTRL
, MASKLWORD
, 0xffff);
2254 static void rtw8822c_coex_cfg_wl_tx_power(struct rtw_dev
*rtwdev
, u8 wl_pwr
)
2256 struct rtw_coex
*coex
= &rtwdev
->coex
;
2257 struct rtw_coex_dm
*coex_dm
= &coex
->dm
;
2259 if (wl_pwr
== coex_dm
->cur_wl_pwr_lvl
)
2262 coex_dm
->cur_wl_pwr_lvl
= wl_pwr
;
2265 static void rtw8822c_coex_cfg_wl_rx_gain(struct rtw_dev
*rtwdev
, bool low_gain
)
2267 struct rtw_coex
*coex
= &rtwdev
->coex
;
2268 struct rtw_coex_dm
*coex_dm
= &coex
->dm
;
2270 if (low_gain
== coex_dm
->cur_wl_rx_low_gain_en
)
2273 coex_dm
->cur_wl_rx_low_gain_en
= low_gain
;
2275 if (coex_dm
->cur_wl_rx_low_gain_en
) {
2276 rtw_dbg(rtwdev
, RTW_DBG_COEX
, "[BTCoex], Hi-Li Table On!\n");
2278 /* set Rx filter corner RCK offset */
2279 rtw_write_rf(rtwdev
, RF_PATH_A
, RF_RCKD
, RFREG_MASK
, 0x22);
2280 rtw_write_rf(rtwdev
, RF_PATH_A
, RF_RCK
, RFREG_MASK
, 0x36);
2281 rtw_write_rf(rtwdev
, RF_PATH_B
, RF_RCKD
, RFREG_MASK
, 0x22);
2282 rtw_write_rf(rtwdev
, RF_PATH_B
, RF_RCK
, RFREG_MASK
, 0x36);
2285 rtw_dbg(rtwdev
, RTW_DBG_COEX
, "[BTCoex], Hi-Li Table Off!\n");
2287 /* set Rx filter corner RCK offset */
2288 rtw_write_rf(rtwdev
, RF_PATH_A
, RF_RCKD
, RFREG_MASK
, 0x20);
2289 rtw_write_rf(rtwdev
, RF_PATH_A
, RF_RCK
, RFREG_MASK
, 0x0);
2290 rtw_write_rf(rtwdev
, RF_PATH_B
, RF_RCKD
, RFREG_MASK
, 0x20);
2291 rtw_write_rf(rtwdev
, RF_PATH_B
, RF_RCK
, RFREG_MASK
, 0x0);
2295 static void rtw8822c_bf_enable_bfee_su(struct rtw_dev
*rtwdev
,
2296 struct rtw_vif
*vif
,
2297 struct rtw_bfee
*bfee
)
2302 rtw_bf_enable_bfee_su(rtwdev
, vif
, bfee
);
2304 tmp6dc
= rtw_read32(rtwdev
, REG_BBPSF_CTRL
) |
2305 BIT_WMAC_USE_NDPARATE
|
2307 if (vif
->net_type
== RTW_NET_AP_MODE
)
2308 rtw_write32(rtwdev
, REG_BBPSF_CTRL
, tmp6dc
| BIT(12));
2310 rtw_write32(rtwdev
, REG_BBPSF_CTRL
, tmp6dc
& ~BIT(12));
2312 rtw_write32(rtwdev
, REG_CSI_RRSR
, 0x550);
2315 static void rtw8822c_bf_config_bfee_su(struct rtw_dev
*rtwdev
,
2316 struct rtw_vif
*vif
,
2317 struct rtw_bfee
*bfee
, bool enable
)
2320 rtw8822c_bf_enable_bfee_su(rtwdev
, vif
, bfee
);
2322 rtw_bf_remove_bfee_su(rtwdev
, bfee
);
2325 static void rtw8822c_bf_config_bfee_mu(struct rtw_dev
*rtwdev
,
2326 struct rtw_vif
*vif
,
2327 struct rtw_bfee
*bfee
, bool enable
)
2330 rtw_bf_enable_bfee_mu(rtwdev
, vif
, bfee
);
2332 rtw_bf_remove_bfee_mu(rtwdev
, bfee
);
2335 static void rtw8822c_bf_config_bfee(struct rtw_dev
*rtwdev
, struct rtw_vif
*vif
,
2336 struct rtw_bfee
*bfee
, bool enable
)
2338 if (bfee
->role
== RTW_BFEE_SU
)
2339 rtw8822c_bf_config_bfee_su(rtwdev
, vif
, bfee
, enable
);
2340 else if (bfee
->role
== RTW_BFEE_MU
)
2341 rtw8822c_bf_config_bfee_mu(rtwdev
, vif
, bfee
, enable
);
2343 rtw_warn(rtwdev
, "wrong bfee role\n");
2346 struct dpk_cfg_pair
{
2352 void rtw8822c_parse_tbl_dpk(struct rtw_dev
*rtwdev
,
2353 const struct rtw_table
*tbl
)
2355 const struct dpk_cfg_pair
*p
= tbl
->data
;
2356 const struct dpk_cfg_pair
*end
= p
+ tbl
->size
/ 3;
2358 BUILD_BUG_ON(sizeof(struct dpk_cfg_pair
) != sizeof(u32
) * 3);
2360 for (; p
< end
; p
++)
2361 rtw_write32_mask(rtwdev
, p
->addr
, p
->bitmask
, p
->data
);
2364 static void rtw8822c_dpk_set_gnt_wl(struct rtw_dev
*rtwdev
, bool is_before_k
)
2366 struct rtw_dpk_info
*dpk_info
= &rtwdev
->dm_info
.dpk_info
;
2369 dpk_info
->gnt_control
= rtw_read32(rtwdev
, 0x70);
2370 dpk_info
->gnt_value
= rtw_coex_read_indirect_reg(rtwdev
, 0x38);
2371 rtw_write32_mask(rtwdev
, 0x70, BIT(26), 0x1);
2372 rtw_coex_write_indirect_reg(rtwdev
, 0x38, MASKBYTE1
, 0x77);
2374 rtw_coex_write_indirect_reg(rtwdev
, 0x38, MASKDWORD
,
2375 dpk_info
->gnt_value
);
2376 rtw_write32(rtwdev
, 0x70, dpk_info
->gnt_control
);
2381 rtw8822c_dpk_restore_registers(struct rtw_dev
*rtwdev
, u32 reg_num
,
2382 struct rtw_backup_info
*bckp
)
2384 rtw_restore_reg(rtwdev
, bckp
, reg_num
);
2385 rtw_write32_mask(rtwdev
, REG_NCTL0
, BIT_SUBPAGE
, 0xc);
2386 rtw_write32_mask(rtwdev
, REG_RXSRAM_CTL
, BIT_DPD_CLK
, 0x4);
2390 rtw8822c_dpk_backup_registers(struct rtw_dev
*rtwdev
, u32
*reg
,
2391 u32 reg_num
, struct rtw_backup_info
*bckp
)
2395 for (i
= 0; i
< reg_num
; i
++) {
2397 bckp
[i
].reg
= reg
[i
];
2398 bckp
[i
].val
= rtw_read32(rtwdev
, reg
[i
]);
2402 static void rtw8822c_dpk_backup_rf_registers(struct rtw_dev
*rtwdev
,
2404 u32 rf_reg_bak
[][2])
2408 for (i
= 0; i
< DPK_RF_REG_NUM
; i
++) {
2409 rf_reg_bak
[i
][RF_PATH_A
] = rtw_read_rf(rtwdev
, RF_PATH_A
,
2410 rf_reg
[i
], RFREG_MASK
);
2411 rf_reg_bak
[i
][RF_PATH_B
] = rtw_read_rf(rtwdev
, RF_PATH_B
,
2412 rf_reg
[i
], RFREG_MASK
);
2416 static void rtw8822c_dpk_reload_rf_registers(struct rtw_dev
*rtwdev
,
2418 u32 rf_reg_bak
[][2])
2422 for (i
= 0; i
< DPK_RF_REG_NUM
; i
++) {
2423 rtw_write_rf(rtwdev
, RF_PATH_A
, rf_reg
[i
], RFREG_MASK
,
2424 rf_reg_bak
[i
][RF_PATH_A
]);
2425 rtw_write_rf(rtwdev
, RF_PATH_B
, rf_reg
[i
], RFREG_MASK
,
2426 rf_reg_bak
[i
][RF_PATH_B
]);
2430 static void rtw8822c_dpk_information(struct rtw_dev
*rtwdev
)
2432 struct rtw_dpk_info
*dpk_info
= &rtwdev
->dm_info
.dpk_info
;
2436 reg
= rtw_read_rf(rtwdev
, RF_PATH_A
, 0x18, RFREG_MASK
);
2438 band_shift
= FIELD_GET(BIT(16), reg
);
2439 dpk_info
->dpk_band
= 1 << band_shift
;
2440 dpk_info
->dpk_ch
= FIELD_GET(0xff, reg
);
2441 dpk_info
->dpk_bw
= FIELD_GET(0x3000, reg
);
2444 static void rtw8822c_dpk_rxbb_dc_cal(struct rtw_dev
*rtwdev
, u8 path
)
2446 rtw_write_rf(rtwdev
, path
, 0x92, RFREG_MASK
, 0x84800);
2448 rtw_write_rf(rtwdev
, path
, 0x92, RFREG_MASK
, 0x84801);
2449 usleep_range(600, 610);
2450 rtw_write_rf(rtwdev
, path
, 0x92, RFREG_MASK
, 0x84800);
2453 static u8
rtw8822c_dpk_dc_corr_check(struct rtw_dev
*rtwdev
, u8 path
)
2458 rtw_write32(rtwdev
, REG_RXSRAM_CTL
, 0x000900f0);
2459 dc_i
= (u16
)rtw_read32_mask(rtwdev
, REG_STAT_RPT
, GENMASK(27, 16));
2460 dc_q
= (u16
)rtw_read32_mask(rtwdev
, REG_STAT_RPT
, GENMASK(11, 0));
2463 dc_i
= 0x1000 - dc_i
;
2465 dc_q
= 0x1000 - dc_q
;
2467 rtw_write32(rtwdev
, REG_RXSRAM_CTL
, 0x000000f0);
2468 corr_idx
= (u8
)rtw_read32_mask(rtwdev
, REG_STAT_RPT
, GENMASK(7, 0));
2469 rtw_read32_mask(rtwdev
, REG_STAT_RPT
, GENMASK(15, 8));
2471 if (dc_i
> 200 || dc_q
> 200 || corr_idx
< 40 || corr_idx
> 65)
2478 static void rtw8822c_dpk_tx_pause(struct rtw_dev
*rtwdev
)
2483 rtw_write8(rtwdev
, 0x522, 0xff);
2484 rtw_write32_mask(rtwdev
, 0x1e70, 0xf, 0x2);
2487 reg_a
= (u8
)rtw_read_rf(rtwdev
, RF_PATH_A
, 0x00, 0xf0000);
2488 reg_b
= (u8
)rtw_read_rf(rtwdev
, RF_PATH_B
, 0x00, 0xf0000);
2491 } while ((reg_a
== 2 || reg_b
== 2) && count
< 2500);
2494 static void rtw8822c_dpk_mac_bb_setting(struct rtw_dev
*rtwdev
)
2496 rtw8822c_dpk_tx_pause(rtwdev
);
2497 rtw_load_table(rtwdev
, &rtw8822c_dpk_mac_bb_tbl
);
2500 static void rtw8822c_dpk_afe_setting(struct rtw_dev
*rtwdev
, bool is_do_dpk
)
2503 rtw_load_table(rtwdev
, &rtw8822c_dpk_afe_is_dpk_tbl
);
2505 rtw_load_table(rtwdev
, &rtw8822c_dpk_afe_no_dpk_tbl
);
2508 static void rtw8822c_dpk_pre_setting(struct rtw_dev
*rtwdev
)
2512 for (path
= 0; path
< rtwdev
->hal
.rf_path_num
; path
++) {
2513 rtw_write_rf(rtwdev
, path
, RF_RXAGC_OFFSET
, RFREG_MASK
, 0x0);
2514 rtw_write32(rtwdev
, REG_NCTL0
, 0x8 | (path
<< 1));
2515 if (rtwdev
->dm_info
.dpk_info
.dpk_band
== RTW_BAND_2G
)
2516 rtw_write32(rtwdev
, REG_DPD_LUT3
, 0x1f100000);
2518 rtw_write32(rtwdev
, REG_DPD_LUT3
, 0x1f0d0000);
2519 rtw_write32_mask(rtwdev
, REG_DPD_LUT0
, BIT_GLOSS_DB
, 0x4);
2520 rtw_write32_mask(rtwdev
, REG_IQK_CTL1
, BIT_TX_CFIR
, 0x3);
2522 rtw_write32_mask(rtwdev
, REG_NCTL0
, BIT_SUBPAGE
, 0xc);
2523 rtw_write32(rtwdev
, REG_DPD_CTL11
, 0x3b23170b);
2524 rtw_write32(rtwdev
, REG_DPD_CTL12
, 0x775f5347);
2527 static u32
rtw8822c_dpk_rf_setting(struct rtw_dev
*rtwdev
, u8 path
)
2531 rtw_write_rf(rtwdev
, path
, RF_MODE_TRXAGC
, RFREG_MASK
, 0x50017);
2532 ori_txbb
= rtw_read_rf(rtwdev
, path
, RF_TX_GAIN
, RFREG_MASK
);
2534 rtw_write_rf(rtwdev
, path
, RF_DEBUG
, BIT_DE_TX_GAIN
, 0x1);
2535 rtw_write_rf(rtwdev
, path
, RF_DEBUG
, BIT_DE_PWR_TRIM
, 0x1);
2536 rtw_write_rf(rtwdev
, path
, RF_TX_GAIN_OFFSET
, BIT_TX_OFFSET_VAL
, 0x0);
2537 rtw_write_rf(rtwdev
, path
, RF_TX_GAIN
, RFREG_MASK
, ori_txbb
);
2539 if (rtwdev
->dm_info
.dpk_info
.dpk_band
== RTW_BAND_2G
) {
2540 rtw_write_rf(rtwdev
, path
, RF_TX_GAIN_OFFSET
, BIT_LB_ATT
, 0x1);
2541 rtw_write_rf(rtwdev
, path
, RF_RXG_GAIN
, BIT_RXG_GAIN
, 0x0);
2543 rtw_write_rf(rtwdev
, path
, RF_TXA_LB_SW
, BIT_TXA_LB_ATT
, 0x0);
2544 rtw_write_rf(rtwdev
, path
, RF_TXA_LB_SW
, BIT_LB_ATT
, 0x6);
2545 rtw_write_rf(rtwdev
, path
, RF_TXA_LB_SW
, BIT_LB_SW
, 0x1);
2546 rtw_write_rf(rtwdev
, path
, RF_RXA_MIX_GAIN
, BIT_RXA_MIX_GAIN
, 0);
2549 rtw_write_rf(rtwdev
, path
, RF_MODE_TRXAGC
, BIT_RXAGC
, 0xf);
2550 rtw_write_rf(rtwdev
, path
, RF_DEBUG
, BIT_DE_TRXBW
, 0x1);
2551 rtw_write_rf(rtwdev
, path
, RF_BW_TRXBB
, BIT_BW_RXBB
, 0x0);
2553 if (rtwdev
->dm_info
.dpk_info
.dpk_bw
== DPK_CHANNEL_WIDTH_80
)
2554 rtw_write_rf(rtwdev
, path
, RF_BW_TRXBB
, BIT_BW_TXBB
, 0x2);
2556 rtw_write_rf(rtwdev
, path
, RF_BW_TRXBB
, BIT_BW_TXBB
, 0x1);
2558 rtw_write_rf(rtwdev
, path
, RF_EXT_TIA_BW
, BIT(1), 0x1);
2560 usleep_range(100, 110);
2562 return ori_txbb
& 0x1f;
2565 static u16
rtw8822c_dpk_get_cmd(struct rtw_dev
*rtwdev
, u8 action
, u8 path
)
2568 u8 bw
= rtwdev
->dm_info
.dpk_info
.dpk_bw
== DPK_CHANNEL_WIDTH_80
? 2 : 0;
2571 case RTW_DPK_GAIN_LOSS
:
2574 case RTW_DPK_DO_DPK
:
2575 cmd
= 0x16 + path
+ bw
;
2577 case RTW_DPK_DPK_ON
:
2581 cmd
= 0x1c + path
+ bw
;
2587 return (cmd
<< 8) | 0x48;
2590 static u8
rtw8822c_dpk_one_shot(struct rtw_dev
*rtwdev
, u8 path
, u8 action
)
2595 rtw8822c_dpk_set_gnt_wl(rtwdev
, true);
2597 if (action
== RTW_DPK_CAL_PWR
) {
2598 rtw_write32_mask(rtwdev
, REG_DPD_CTL0
, BIT(12), 0x1);
2599 rtw_write32_mask(rtwdev
, REG_DPD_CTL0
, BIT(12), 0x0);
2600 rtw_write32_mask(rtwdev
, REG_RXSRAM_CTL
, BIT_RPT_SEL
, 0x0);
2602 if (!check_hw_ready(rtwdev
, REG_STAT_RPT
, BIT(31), 0x1)) {
2604 rtw_dbg(rtwdev
, RTW_DBG_RFK
, "[DPK] one-shot over 20ms\n");
2607 rtw_write32_mask(rtwdev
, REG_NCTL0
, BIT_SUBPAGE
,
2609 rtw_write32_mask(rtwdev
, REG_R_CONFIG
, BIT_IQ_SWITCH
, 0x9);
2611 dpk_cmd
= rtw8822c_dpk_get_cmd(rtwdev
, action
, path
);
2612 rtw_write32(rtwdev
, REG_NCTL0
, dpk_cmd
);
2613 rtw_write32(rtwdev
, REG_NCTL0
, dpk_cmd
+ 1);
2615 if (!check_hw_ready(rtwdev
, 0x2d9c, 0xff, 0x55)) {
2617 rtw_dbg(rtwdev
, RTW_DBG_RFK
, "[DPK] one-shot over 20ms\n");
2619 rtw_write32_mask(rtwdev
, REG_NCTL0
, BIT_SUBPAGE
,
2621 rtw_write32_mask(rtwdev
, REG_R_CONFIG
, BIT_IQ_SWITCH
, 0x0);
2624 rtw8822c_dpk_set_gnt_wl(rtwdev
, false);
2626 rtw_write8(rtwdev
, 0x1b10, 0x0);
2631 static u16
rtw8822c_dpk_dgain_read(struct rtw_dev
*rtwdev
, u8 path
)
2635 rtw_write32_mask(rtwdev
, REG_NCTL0
, BIT_SUBPAGE
, 0xc);
2636 rtw_write32_mask(rtwdev
, REG_RXSRAM_CTL
, 0x00ff0000, 0x0);
2638 dgain
= (u16
)rtw_read32_mask(rtwdev
, REG_STAT_RPT
, GENMASK(27, 16));
2643 static u8
rtw8822c_dpk_thermal_read(struct rtw_dev
*rtwdev
, u8 path
)
2645 rtw_write_rf(rtwdev
, path
, RF_T_METER
, BIT(19), 0x1);
2646 rtw_write_rf(rtwdev
, path
, RF_T_METER
, BIT(19), 0x0);
2647 rtw_write_rf(rtwdev
, path
, RF_T_METER
, BIT(19), 0x1);
2650 return (u8
)rtw_read_rf(rtwdev
, path
, RF_T_METER
, 0x0007e);
2653 static u32
rtw8822c_dpk_pas_read(struct rtw_dev
*rtwdev
, u8 path
)
2657 rtw_write32(rtwdev
, REG_NCTL0
, 0x8 | (path
<< 1));
2658 rtw_write32_mask(rtwdev
, 0x1b48, BIT(14), 0x0);
2659 rtw_write32(rtwdev
, REG_RXSRAM_CTL
, 0x00060001);
2660 rtw_write32(rtwdev
, 0x1b4c, 0x00000000);
2661 rtw_write32(rtwdev
, 0x1b4c, 0x00080000);
2663 q_val
= rtw_read32_mask(rtwdev
, REG_STAT_RPT
, MASKHWORD
);
2664 i_val
= rtw_read32_mask(rtwdev
, REG_STAT_RPT
, MASKLWORD
);
2666 if (i_val
& BIT(15))
2667 i_val
= 0x10000 - i_val
;
2668 if (q_val
& BIT(15))
2669 q_val
= 0x10000 - q_val
;
2671 rtw_write32(rtwdev
, 0x1b4c, 0x00000000);
2673 return i_val
* i_val
+ q_val
* q_val
;
2676 static u32
rtw8822c_psd_log2base(u32 val
)
2678 u32 tmp
, val_integerd_b
, tindex
;
2679 u32 result
, val_fractiond_b
;
2680 u32 table_fraction
[21] = {0, 432, 332, 274, 232, 200, 174,
2681 151, 132, 115, 100, 86, 74, 62, 51,
2682 42, 32, 23, 15, 7, 0};
2687 val_integerd_b
= __fls(val
) + 1;
2689 tmp
= (val
* 100) / (1 << val_integerd_b
);
2692 if (tindex
>= ARRAY_SIZE(table_fraction
))
2693 tindex
= ARRAY_SIZE(table_fraction
) - 1;
2695 val_fractiond_b
= table_fraction
[tindex
];
2697 result
= val_integerd_b
* 100 - val_fractiond_b
;
2702 static u8
rtw8822c_dpk_gainloss_result(struct rtw_dev
*rtwdev
, u8 path
)
2706 rtw_write32_mask(rtwdev
, REG_NCTL0
, BIT_SUBPAGE
, 0x8 | (path
<< 1));
2707 rtw_write32_mask(rtwdev
, 0x1b48, BIT(14), 0x1);
2708 rtw_write32(rtwdev
, REG_RXSRAM_CTL
, 0x00060000);
2710 result
= (u8
)rtw_read32_mask(rtwdev
, REG_STAT_RPT
, 0x000000f0);
2712 rtw_write32_mask(rtwdev
, 0x1b48, BIT(14), 0x0);
2717 static u8
rtw8822c_dpk_agc_gain_chk(struct rtw_dev
*rtwdev
, u8 path
,
2723 rtw8822c_dpk_one_shot(rtwdev
, path
, RTW_DPK_DAGC
);
2724 dgain
= rtw8822c_dpk_dgain_read(rtwdev
, path
);
2726 if (dgain
> 1535 && !limited_pga
)
2727 return RTW_DPK_GAIN_LESS
;
2728 else if (dgain
< 768 && !limited_pga
)
2729 return RTW_DPK_GAIN_LARGE
;
2734 static u8
rtw8822c_dpk_agc_loss_chk(struct rtw_dev
*rtwdev
, u8 path
)
2738 loss
= rtw8822c_dpk_pas_read(rtwdev
, path
);
2739 if (loss
< 0x4000000)
2740 return RTW_DPK_GL_LESS
;
2741 loss_db
= 3 * rtw8822c_psd_log2base(loss
>> 13) - 3870;
2744 return RTW_DPK_GL_LARGE
;
2745 else if (loss_db
< 250)
2746 return RTW_DPK_GL_LESS
;
2748 return RTW_DPK_AGC_OUT
;
2751 struct rtw8822c_dpk_data
{
2761 static u8
rtw8822c_gain_check_state(struct rtw_dev
*rtwdev
,
2762 struct rtw8822c_dpk_data
*data
)
2766 data
->txbb
= (u8
)rtw_read_rf(rtwdev
, data
->path
, RF_TX_GAIN
,
2768 data
->pga
= (u8
)rtw_read_rf(rtwdev
, data
->path
, RF_MODE_TRXAGC
,
2771 if (data
->loss_only
) {
2772 state
= RTW_DPK_LOSS_CHECK
;
2776 state
= rtw8822c_dpk_agc_gain_chk(rtwdev
, data
->path
,
2778 if (state
== RTW_DPK_GAIN_CHECK
&& data
->gain_only
)
2779 state
= RTW_DPK_AGC_OUT
;
2780 else if (state
== RTW_DPK_GAIN_CHECK
)
2781 state
= RTW_DPK_LOSS_CHECK
;
2785 if (data
->agc_cnt
>= 6)
2786 state
= RTW_DPK_AGC_OUT
;
2791 static u8
rtw8822c_gain_large_state(struct rtw_dev
*rtwdev
,
2792 struct rtw8822c_dpk_data
*data
)
2797 rtw_write_rf(rtwdev
, data
->path
, RF_MODE_TRXAGC
, BIT_RXAGC
, 0xc);
2798 else if (pga
> 0xb && pga
< 0xf)
2799 rtw_write_rf(rtwdev
, data
->path
, RF_MODE_TRXAGC
, BIT_RXAGC
, 0x0);
2801 data
->limited_pga
= 1;
2803 return RTW_DPK_GAIN_CHECK
;
2806 static u8
rtw8822c_gain_less_state(struct rtw_dev
*rtwdev
,
2807 struct rtw8822c_dpk_data
*data
)
2812 rtw_write_rf(rtwdev
, data
->path
, RF_MODE_TRXAGC
, BIT_RXAGC
, 0xc);
2813 else if (pga
> 0xb && pga
< 0xf)
2814 rtw_write_rf(rtwdev
, data
->path
, RF_MODE_TRXAGC
, BIT_RXAGC
, 0xf);
2816 data
->limited_pga
= 1;
2818 return RTW_DPK_GAIN_CHECK
;
2821 static u8
rtw8822c_gl_state(struct rtw_dev
*rtwdev
,
2822 struct rtw8822c_dpk_data
*data
, u8 is_large
)
2824 u8 txbb_bound
[] = {0x1f, 0};
2826 if (data
->txbb
== txbb_bound
[is_large
])
2827 return RTW_DPK_AGC_OUT
;
2834 rtw_write_rf(rtwdev
, data
->path
, RF_TX_GAIN
, BIT_GAIN_TXBB
, data
->txbb
);
2835 data
->limited_pga
= 0;
2837 return RTW_DPK_GAIN_CHECK
;
2840 static u8
rtw8822c_gl_large_state(struct rtw_dev
*rtwdev
,
2841 struct rtw8822c_dpk_data
*data
)
2843 return rtw8822c_gl_state(rtwdev
, data
, 1);
2846 static u8
rtw8822c_gl_less_state(struct rtw_dev
*rtwdev
,
2847 struct rtw8822c_dpk_data
*data
)
2849 return rtw8822c_gl_state(rtwdev
, data
, 0);
2852 static u8
rtw8822c_loss_check_state(struct rtw_dev
*rtwdev
,
2853 struct rtw8822c_dpk_data
*data
)
2855 u8 path
= data
->path
;
2858 rtw8822c_dpk_one_shot(rtwdev
, path
, RTW_DPK_GAIN_LOSS
);
2859 state
= rtw8822c_dpk_agc_loss_chk(rtwdev
, path
);
2864 static u8 (*dpk_state
[])(struct rtw_dev
*rtwdev
,
2865 struct rtw8822c_dpk_data
*data
) = {
2866 rtw8822c_gain_check_state
, rtw8822c_gain_large_state
,
2867 rtw8822c_gain_less_state
, rtw8822c_gl_large_state
,
2868 rtw8822c_gl_less_state
, rtw8822c_loss_check_state
};
2870 static u8
rtw8822c_dpk_pas_agc(struct rtw_dev
*rtwdev
, u8 path
,
2871 bool gain_only
, bool loss_only
)
2873 struct rtw8822c_dpk_data data
= {0};
2874 u8 (*func
)(struct rtw_dev
*rtwdev
, struct rtw8822c_dpk_data
*data
);
2875 u8 state
= RTW_DPK_GAIN_CHECK
;
2877 data
.loss_only
= loss_only
;
2878 data
.gain_only
= gain_only
;
2882 func
= dpk_state
[state
];
2883 state
= func(rtwdev
, &data
);
2884 if (state
== RTW_DPK_AGC_OUT
)
2891 static bool rtw8822c_dpk_coef_iq_check(struct rtw_dev
*rtwdev
,
2892 u16 coef_i
, u16 coef_q
)
2894 if (coef_i
== 0x1000 || coef_i
== 0x0fff ||
2895 coef_q
== 0x1000 || coef_q
== 0x0fff)
2901 static u32
rtw8822c_dpk_coef_transfer(struct rtw_dev
*rtwdev
)
2904 u16 coef_i
= 0, coef_q
= 0;
2906 reg
= rtw_read32(rtwdev
, REG_STAT_RPT
);
2908 coef_i
= (u16
)rtw_read32_mask(rtwdev
, REG_STAT_RPT
, MASKHWORD
) & 0x1fff;
2909 coef_q
= (u16
)rtw_read32_mask(rtwdev
, REG_STAT_RPT
, MASKLWORD
) & 0x1fff;
2911 coef_q
= ((0x2000 - coef_q
) & 0x1fff) - 1;
2913 reg
= (coef_i
<< 16) | coef_q
;
2918 static const u32 rtw8822c_dpk_get_coef_tbl
[] = {
2919 0x000400f0, 0x040400f0, 0x080400f0, 0x010400f0, 0x050400f0,
2920 0x090400f0, 0x020400f0, 0x060400f0, 0x0a0400f0, 0x030400f0,
2921 0x070400f0, 0x0b0400f0, 0x0c0400f0, 0x100400f0, 0x0d0400f0,
2922 0x110400f0, 0x0e0400f0, 0x120400f0, 0x0f0400f0, 0x130400f0,
2925 static void rtw8822c_dpk_coef_tbl_apply(struct rtw_dev
*rtwdev
, u8 path
)
2927 struct rtw_dpk_info
*dpk_info
= &rtwdev
->dm_info
.dpk_info
;
2930 for (i
= 0; i
< 20; i
++) {
2931 rtw_write32(rtwdev
, REG_RXSRAM_CTL
,
2932 rtw8822c_dpk_get_coef_tbl
[i
]);
2933 dpk_info
->coef
[path
][i
] = rtw8822c_dpk_coef_transfer(rtwdev
);
2937 static void rtw8822c_dpk_get_coef(struct rtw_dev
*rtwdev
, u8 path
)
2939 rtw_write32(rtwdev
, REG_NCTL0
, 0x0000000c);
2941 if (path
== RF_PATH_A
) {
2942 rtw_write32_mask(rtwdev
, REG_DPD_CTL0
, BIT(24), 0x0);
2943 rtw_write32(rtwdev
, REG_DPD_CTL0_S0
, 0x30000080);
2944 } else if (path
== RF_PATH_B
) {
2945 rtw_write32_mask(rtwdev
, REG_DPD_CTL0
, BIT(24), 0x1);
2946 rtw_write32(rtwdev
, REG_DPD_CTL0_S1
, 0x30000080);
2949 rtw8822c_dpk_coef_tbl_apply(rtwdev
, path
);
2952 static u8
rtw8822c_dpk_coef_read(struct rtw_dev
*rtwdev
, u8 path
)
2954 struct rtw_dpk_info
*dpk_info
= &rtwdev
->dm_info
.dpk_info
;
2955 u8 addr
, result
= 1;
2958 for (addr
= 0; addr
< 20; addr
++) {
2959 coef_i
= FIELD_GET(0x1fff0000, dpk_info
->coef
[path
][addr
]);
2960 coef_q
= FIELD_GET(0x1fff, dpk_info
->coef
[path
][addr
]);
2962 if (rtw8822c_dpk_coef_iq_check(rtwdev
, coef_i
, coef_q
)) {
2970 static void rtw8822c_dpk_coef_write(struct rtw_dev
*rtwdev
, u8 path
, u8 result
)
2972 struct rtw_dpk_info
*dpk_info
= &rtwdev
->dm_info
.dpk_info
;
2973 u16 reg
[DPK_RF_PATH_NUM
] = {0x1b0c, 0x1b64};
2977 rtw_write32(rtwdev
, REG_NCTL0
, 0x0000000c);
2978 rtw_write32(rtwdev
, REG_RXSRAM_CTL
, 0x000000f0);
2980 for (addr
= 0; addr
< 20; addr
++) {
2987 coef
= dpk_info
->coef
[path
][addr
];
2989 rtw_write32(rtwdev
, reg
[path
] + addr
* 4, coef
);
2993 static void rtw8822c_dpk_fill_result(struct rtw_dev
*rtwdev
, u32 dpk_txagc
,
2996 struct rtw_dpk_info
*dpk_info
= &rtwdev
->dm_info
.dpk_info
;
2998 rtw_write32_mask(rtwdev
, REG_NCTL0
, BIT_SUBPAGE
, 0x8 | (path
<< 1));
3001 rtw_write8(rtwdev
, REG_DPD_AGC
, (u8
)(dpk_txagc
- 6));
3003 rtw_write8(rtwdev
, REG_DPD_AGC
, 0x00);
3005 dpk_info
->result
[path
] = result
;
3006 dpk_info
->dpk_txagc
[path
] = rtw_read8(rtwdev
, REG_DPD_AGC
);
3008 rtw8822c_dpk_coef_write(rtwdev
, path
, result
);
3011 static u32
rtw8822c_dpk_gainloss(struct rtw_dev
*rtwdev
, u8 path
)
3013 struct rtw_dpk_info
*dpk_info
= &rtwdev
->dm_info
.dpk_info
;
3014 u8 tx_agc
, tx_bb
, ori_txbb
, ori_txagc
, tx_agc_search
, t1
, t2
;
3016 ori_txbb
= rtw8822c_dpk_rf_setting(rtwdev
, path
);
3017 ori_txagc
= (u8
)rtw_read_rf(rtwdev
, path
, RF_MODE_TRXAGC
, BIT_TXAGC
);
3019 rtw8822c_dpk_rxbb_dc_cal(rtwdev
, path
);
3020 rtw8822c_dpk_one_shot(rtwdev
, path
, RTW_DPK_DAGC
);
3021 rtw8822c_dpk_dgain_read(rtwdev
, path
);
3023 if (rtw8822c_dpk_dc_corr_check(rtwdev
, path
)) {
3024 rtw8822c_dpk_rxbb_dc_cal(rtwdev
, path
);
3025 rtw8822c_dpk_one_shot(rtwdev
, path
, RTW_DPK_DAGC
);
3026 rtw8822c_dpk_dc_corr_check(rtwdev
, path
);
3029 t1
= rtw8822c_dpk_thermal_read(rtwdev
, path
);
3030 tx_bb
= rtw8822c_dpk_pas_agc(rtwdev
, path
, false, true);
3031 tx_agc_search
= rtw8822c_dpk_gainloss_result(rtwdev
, path
);
3033 if (tx_bb
< tx_agc_search
)
3036 tx_bb
= tx_bb
- tx_agc_search
;
3038 rtw_write_rf(rtwdev
, path
, RF_TX_GAIN
, BIT_GAIN_TXBB
, tx_bb
);
3040 tx_agc
= ori_txagc
- (ori_txbb
- tx_bb
);
3042 t2
= rtw8822c_dpk_thermal_read(rtwdev
, path
);
3044 dpk_info
->thermal_dpk_delta
[path
] = abs(t2
- t1
);
3049 static u8
rtw8822c_dpk_by_path(struct rtw_dev
*rtwdev
, u32 tx_agc
, u8 path
)
3053 result
= rtw8822c_dpk_one_shot(rtwdev
, path
, RTW_DPK_DO_DPK
);
3055 rtw_write32_mask(rtwdev
, REG_NCTL0
, BIT_SUBPAGE
, 0x8 | (path
<< 1));
3057 result
= result
| (u8
)rtw_read32_mask(rtwdev
, REG_DPD_CTL1_S0
, BIT(26));
3059 rtw_write_rf(rtwdev
, path
, RF_MODE_TRXAGC
, RFREG_MASK
, 0x33e14);
3061 rtw8822c_dpk_get_coef(rtwdev
, path
);
3066 static void rtw8822c_dpk_cal_gs(struct rtw_dev
*rtwdev
, u8 path
)
3068 struct rtw_dpk_info
*dpk_info
= &rtwdev
->dm_info
.dpk_info
;
3071 rtw_write32_mask(rtwdev
, REG_NCTL0
, BIT_SUBPAGE
, 0x8 | (path
<< 1));
3072 rtw_write32_mask(rtwdev
, REG_IQK_CTL1
, BIT_BYPASS_DPD
, 0x0);
3073 rtw_write32_mask(rtwdev
, REG_IQK_CTL1
, BIT_TX_CFIR
, 0x0);
3074 rtw_write32_mask(rtwdev
, REG_R_CONFIG
, BIT_IQ_SWITCH
, 0x9);
3075 rtw_write32_mask(rtwdev
, REG_R_CONFIG
, BIT_INNER_LB
, 0x1);
3076 rtw_write32_mask(rtwdev
, REG_NCTL0
, BIT_SUBPAGE
, 0xc);
3077 rtw_write32_mask(rtwdev
, REG_RXSRAM_CTL
, BIT_DPD_CLK
, 0xf);
3079 if (path
== RF_PATH_A
) {
3080 rtw_write32_mask(rtwdev
, REG_DPD_CTL0_S0
, BIT_GS_PWSF
,
3082 rtw_write32_mask(rtwdev
, REG_DPD_CTL1_S0
, BIT_DPD_EN
, 0x1);
3084 rtw_write32_mask(rtwdev
, REG_DPD_CTL0_S1
, BIT_GS_PWSF
,
3086 rtw_write32_mask(rtwdev
, REG_DPD_CTL1_S1
, BIT_DPD_EN
, 0x1);
3089 if (dpk_info
->dpk_bw
== DPK_CHANNEL_WIDTH_80
) {
3090 rtw_write32(rtwdev
, REG_DPD_CTL16
, 0x80001310);
3091 rtw_write32(rtwdev
, REG_DPD_CTL16
, 0x00001310);
3092 rtw_write32(rtwdev
, REG_DPD_CTL16
, 0x810000db);
3093 rtw_write32(rtwdev
, REG_DPD_CTL16
, 0x010000db);
3094 rtw_write32(rtwdev
, REG_DPD_CTL16
, 0x0000b428);
3095 rtw_write32(rtwdev
, REG_DPD_CTL15
,
3096 0x05020000 | (BIT(path
) << 28));
3098 rtw_write32(rtwdev
, REG_DPD_CTL16
, 0x8200190c);
3099 rtw_write32(rtwdev
, REG_DPD_CTL16
, 0x0200190c);
3100 rtw_write32(rtwdev
, REG_DPD_CTL16
, 0x8301ee14);
3101 rtw_write32(rtwdev
, REG_DPD_CTL16
, 0x0301ee14);
3102 rtw_write32(rtwdev
, REG_DPD_CTL16
, 0x0000b428);
3103 rtw_write32(rtwdev
, REG_DPD_CTL15
,
3104 0x05020008 | (BIT(path
) << 28));
3107 rtw_write32_mask(rtwdev
, REG_DPD_CTL0
, MASKBYTE3
, 0x8 | path
);
3109 rtw8822c_dpk_one_shot(rtwdev
, path
, RTW_DPK_CAL_PWR
);
3111 rtw_write32_mask(rtwdev
, REG_DPD_CTL15
, MASKBYTE3
, 0x0);
3112 rtw_write32_mask(rtwdev
, REG_NCTL0
, BIT_SUBPAGE
, 0x8 | (path
<< 1));
3113 rtw_write32_mask(rtwdev
, REG_R_CONFIG
, BIT_IQ_SWITCH
, 0x0);
3114 rtw_write32_mask(rtwdev
, REG_R_CONFIG
, BIT_INNER_LB
, 0x0);
3115 rtw_write32_mask(rtwdev
, REG_NCTL0
, BIT_SUBPAGE
, 0xc);
3117 if (path
== RF_PATH_A
)
3118 rtw_write32_mask(rtwdev
, REG_DPD_CTL0_S0
, BIT_GS_PWSF
, 0x5b);
3120 rtw_write32_mask(rtwdev
, REG_DPD_CTL0_S1
, BIT_GS_PWSF
, 0x5b);
3122 rtw_write32_mask(rtwdev
, REG_RXSRAM_CTL
, BIT_RPT_SEL
, 0x0);
3124 tmp_gs
= (u16
)rtw_read32_mask(rtwdev
, REG_STAT_RPT
, BIT_RPT_DGAIN
);
3125 tmp_gs
= (tmp_gs
* 910) >> 10;
3126 tmp_gs
= DIV_ROUND_CLOSEST(tmp_gs
, 10);
3128 if (path
== RF_PATH_A
)
3129 rtw_write32_mask(rtwdev
, REG_DPD_CTL0_S0
, BIT_GS_PWSF
, tmp_gs
);
3131 rtw_write32_mask(rtwdev
, REG_DPD_CTL0_S1
, BIT_GS_PWSF
, tmp_gs
);
3133 dpk_info
->dpk_gs
[path
] = tmp_gs
;
3136 static void rtw8822c_dpk_cal_coef1(struct rtw_dev
*rtwdev
)
3138 struct rtw_dpk_info
*dpk_info
= &rtwdev
->dm_info
.dpk_info
;
3139 u32 offset
[DPK_RF_PATH_NUM
] = {0, 0x58};
3143 rtw_write32_mask(rtwdev
, REG_NCTL0
, BIT_SUBPAGE
, 0x0000000c);
3144 rtw_write32(rtwdev
, REG_RXSRAM_CTL
, 0x000000f0);
3145 rtw_write32(rtwdev
, REG_NCTL0
, 0x00001148);
3146 rtw_write32(rtwdev
, REG_NCTL0
, 0x00001149);
3148 check_hw_ready(rtwdev
, 0x2d9c, MASKBYTE0
, 0x55);
3150 rtw_write8(rtwdev
, 0x1b10, 0x0);
3151 rtw_write32_mask(rtwdev
, REG_NCTL0
, BIT_SUBPAGE
, 0x0000000c);
3153 for (path
= 0; path
< rtwdev
->hal
.rf_path_num
; path
++) {
3154 i_scaling
= 0x16c00 / dpk_info
->dpk_gs
[path
];
3156 rtw_write32_mask(rtwdev
, 0x1b18 + offset
[path
], MASKHWORD
,
3158 rtw_write32_mask(rtwdev
, REG_DPD_CTL0_S0
+ offset
[path
],
3159 GENMASK(31, 28), 0x9);
3160 rtw_write32_mask(rtwdev
, REG_DPD_CTL0_S0
+ offset
[path
],
3161 GENMASK(31, 28), 0x1);
3162 rtw_write32_mask(rtwdev
, REG_DPD_CTL0_S0
+ offset
[path
],
3163 GENMASK(31, 28), 0x0);
3164 rtw_write32_mask(rtwdev
, REG_DPD_CTL1_S0
+ offset
[path
],
3169 static void rtw8822c_dpk_on(struct rtw_dev
*rtwdev
, u8 path
)
3171 struct rtw_dpk_info
*dpk_info
= &rtwdev
->dm_info
.dpk_info
;
3173 rtw8822c_dpk_one_shot(rtwdev
, path
, RTW_DPK_DPK_ON
);
3175 rtw_write32_mask(rtwdev
, REG_NCTL0
, BIT_SUBPAGE
, 0x8 | (path
<< 1));
3176 rtw_write32_mask(rtwdev
, REG_IQK_CTL1
, BIT_TX_CFIR
, 0x0);
3178 if (test_bit(path
, dpk_info
->dpk_path_ok
))
3179 rtw8822c_dpk_cal_gs(rtwdev
, path
);
3182 static bool rtw8822c_dpk_check_pass(struct rtw_dev
*rtwdev
, bool is_fail
,
3183 u32 dpk_txagc
, u8 path
)
3188 if (rtw8822c_dpk_coef_read(rtwdev
, path
))
3196 rtw8822c_dpk_fill_result(rtwdev
, dpk_txagc
, path
, result
);
3201 static void rtw8822c_dpk_result_reset(struct rtw_dev
*rtwdev
)
3203 struct rtw_dpk_info
*dpk_info
= &rtwdev
->dm_info
.dpk_info
;
3206 for (path
= 0; path
< rtwdev
->hal
.rf_path_num
; path
++) {
3207 clear_bit(path
, dpk_info
->dpk_path_ok
);
3208 rtw_write32_mask(rtwdev
, REG_NCTL0
, BIT_SUBPAGE
,
3210 rtw_write32_mask(rtwdev
, 0x1b58, 0x0000007f, 0x0);
3212 dpk_info
->dpk_txagc
[path
] = 0;
3213 dpk_info
->result
[path
] = 0;
3214 dpk_info
->dpk_gs
[path
] = 0x5b;
3215 dpk_info
->pre_pwsf
[path
] = 0;
3216 dpk_info
->thermal_dpk
[path
] = rtw8822c_dpk_thermal_read(rtwdev
,
3221 static void rtw8822c_dpk_calibrate(struct rtw_dev
*rtwdev
, u8 path
)
3223 struct rtw_dpk_info
*dpk_info
= &rtwdev
->dm_info
.dpk_info
;
3227 rtw_dbg(rtwdev
, RTW_DBG_RFK
, "[DPK] s%d dpk start\n", path
);
3229 dpk_txagc
= rtw8822c_dpk_gainloss(rtwdev
, path
);
3231 dpk_fail
= rtw8822c_dpk_by_path(rtwdev
, dpk_txagc
, path
);
3233 if (!rtw8822c_dpk_check_pass(rtwdev
, dpk_fail
, dpk_txagc
, path
))
3234 rtw_err(rtwdev
, "failed to do dpk calibration\n");
3236 rtw_dbg(rtwdev
, RTW_DBG_RFK
, "[DPK] s%d dpk finish\n", path
);
3238 if (dpk_info
->result
[path
])
3239 set_bit(path
, dpk_info
->dpk_path_ok
);
3242 static void rtw8822c_dpk_path_select(struct rtw_dev
*rtwdev
)
3244 rtw8822c_dpk_calibrate(rtwdev
, RF_PATH_A
);
3245 rtw8822c_dpk_calibrate(rtwdev
, RF_PATH_B
);
3246 rtw8822c_dpk_on(rtwdev
, RF_PATH_A
);
3247 rtw8822c_dpk_on(rtwdev
, RF_PATH_B
);
3248 rtw8822c_dpk_cal_coef1(rtwdev
);
3251 static void rtw8822c_dpk_enable_disable(struct rtw_dev
*rtwdev
)
3253 struct rtw_dpk_info
*dpk_info
= &rtwdev
->dm_info
.dpk_info
;
3254 u32 mask
= BIT(15) | BIT(14);
3256 rtw_write32_mask(rtwdev
, REG_NCTL0
, BIT_SUBPAGE
, 0xc);
3258 rtw_write32_mask(rtwdev
, REG_DPD_CTL1_S0
, BIT_DPD_EN
,
3259 dpk_info
->is_dpk_pwr_on
);
3260 rtw_write32_mask(rtwdev
, REG_DPD_CTL1_S1
, BIT_DPD_EN
,
3261 dpk_info
->is_dpk_pwr_on
);
3263 if (test_bit(RF_PATH_A
, dpk_info
->dpk_path_ok
)) {
3264 rtw_write32_mask(rtwdev
, REG_DPD_CTL1_S0
, mask
, 0x0);
3265 rtw_write8(rtwdev
, REG_DPD_CTL0_S0
, dpk_info
->dpk_gs
[RF_PATH_A
]);
3267 if (test_bit(RF_PATH_B
, dpk_info
->dpk_path_ok
)) {
3268 rtw_write32_mask(rtwdev
, REG_DPD_CTL1_S1
, mask
, 0x0);
3269 rtw_write8(rtwdev
, REG_DPD_CTL0_S1
, dpk_info
->dpk_gs
[RF_PATH_B
]);
3273 static void rtw8822c_dpk_reload_data(struct rtw_dev
*rtwdev
)
3275 struct rtw_dpk_info
*dpk_info
= &rtwdev
->dm_info
.dpk_info
;
3278 if (!test_bit(RF_PATH_A
, dpk_info
->dpk_path_ok
) &&
3279 !test_bit(RF_PATH_B
, dpk_info
->dpk_path_ok
) &&
3280 dpk_info
->dpk_ch
== 0)
3283 for (path
= 0; path
< rtwdev
->hal
.rf_path_num
; path
++) {
3284 rtw_write32_mask(rtwdev
, REG_NCTL0
, BIT_SUBPAGE
,
3286 if (dpk_info
->dpk_band
== RTW_BAND_2G
)
3287 rtw_write32(rtwdev
, REG_DPD_LUT3
, 0x1f100000);
3289 rtw_write32(rtwdev
, REG_DPD_LUT3
, 0x1f0d0000);
3291 rtw_write8(rtwdev
, REG_DPD_AGC
, dpk_info
->dpk_txagc
[path
]);
3293 rtw8822c_dpk_coef_write(rtwdev
, path
,
3294 test_bit(path
, dpk_info
->dpk_path_ok
));
3296 rtw8822c_dpk_one_shot(rtwdev
, path
, RTW_DPK_DPK_ON
);
3298 rtw_write32_mask(rtwdev
, REG_NCTL0
, BIT_SUBPAGE
, 0xc);
3300 if (path
== RF_PATH_A
)
3301 rtw_write32_mask(rtwdev
, REG_DPD_CTL0_S0
, BIT_GS_PWSF
,
3302 dpk_info
->dpk_gs
[path
]);
3304 rtw_write32_mask(rtwdev
, REG_DPD_CTL0_S1
, BIT_GS_PWSF
,
3305 dpk_info
->dpk_gs
[path
]);
3307 rtw8822c_dpk_cal_coef1(rtwdev
);
3310 static bool rtw8822c_dpk_reload(struct rtw_dev
*rtwdev
)
3312 struct rtw_dpk_info
*dpk_info
= &rtwdev
->dm_info
.dpk_info
;
3315 dpk_info
->is_reload
= false;
3317 channel
= (u8
)(rtw_read_rf(rtwdev
, RF_PATH_A
, 0x18, RFREG_MASK
) & 0xff);
3319 if (channel
== dpk_info
->dpk_ch
) {
3320 rtw_dbg(rtwdev
, RTW_DBG_RFK
,
3321 "[DPK] DPK reload for CH%d!!\n", dpk_info
->dpk_ch
);
3322 rtw8822c_dpk_reload_data(rtwdev
);
3323 dpk_info
->is_reload
= true;
3326 return dpk_info
->is_reload
;
3329 static void rtw8822c_do_dpk(struct rtw_dev
*rtwdev
)
3331 struct rtw_dpk_info
*dpk_info
= &rtwdev
->dm_info
.dpk_info
;
3332 struct rtw_backup_info bckp
[DPK_BB_REG_NUM
];
3333 u32 rf_reg_backup
[DPK_RF_REG_NUM
][DPK_RF_PATH_NUM
];
3334 u32 bb_reg
[DPK_BB_REG_NUM
] = {
3335 0x520, 0x820, 0x824, 0x1c3c, 0x1d58, 0x1864,
3336 0x4164, 0x180c, 0x410c, 0x186c, 0x416c,
3337 0x1a14, 0x1e70, 0x80c, 0x1d70, 0x1e7c, 0x18a4, 0x41a4};
3338 u32 rf_reg
[DPK_RF_REG_NUM
] = {
3339 0x0, 0x1a, 0x55, 0x63, 0x87, 0x8f, 0xde};
3342 if (!dpk_info
->is_dpk_pwr_on
) {
3343 rtw_dbg(rtwdev
, RTW_DBG_RFK
, "[DPK] Skip DPK due to DPD PWR off\n");
3345 } else if (rtw8822c_dpk_reload(rtwdev
)) {
3349 for (path
= RF_PATH_A
; path
< DPK_RF_PATH_NUM
; path
++)
3350 ewma_thermal_init(&dpk_info
->avg_thermal
[path
]);
3352 rtw8822c_dpk_information(rtwdev
);
3354 rtw8822c_dpk_backup_registers(rtwdev
, bb_reg
, DPK_BB_REG_NUM
, bckp
);
3355 rtw8822c_dpk_backup_rf_registers(rtwdev
, rf_reg
, rf_reg_backup
);
3357 rtw8822c_dpk_mac_bb_setting(rtwdev
);
3358 rtw8822c_dpk_afe_setting(rtwdev
, true);
3359 rtw8822c_dpk_pre_setting(rtwdev
);
3360 rtw8822c_dpk_result_reset(rtwdev
);
3361 rtw8822c_dpk_path_select(rtwdev
);
3362 rtw8822c_dpk_afe_setting(rtwdev
, false);
3363 rtw8822c_dpk_enable_disable(rtwdev
);
3365 rtw8822c_dpk_reload_rf_registers(rtwdev
, rf_reg
, rf_reg_backup
);
3366 for (path
= 0; path
< rtwdev
->hal
.rf_path_num
; path
++)
3367 rtw8822c_dpk_rxbb_dc_cal(rtwdev
, path
);
3368 rtw8822c_dpk_restore_registers(rtwdev
, DPK_BB_REG_NUM
, bckp
);
3371 static void rtw8822c_phy_calibration(struct rtw_dev
*rtwdev
)
3373 rtw8822c_do_iqk(rtwdev
);
3374 rtw8822c_do_dpk(rtwdev
);
3377 static void rtw8822c_dpk_track(struct rtw_dev
*rtwdev
)
3379 struct rtw_dpk_info
*dpk_info
= &rtwdev
->dm_info
.dpk_info
;
3381 u8 thermal_value
[DPK_RF_PATH_NUM
] = {0};
3382 s8 offset
[DPK_RF_PATH_NUM
], delta_dpk
[DPK_RF_PATH_NUM
];
3384 if (dpk_info
->thermal_dpk
[0] == 0 && dpk_info
->thermal_dpk
[1] == 0)
3387 for (path
= 0; path
< DPK_RF_PATH_NUM
; path
++) {
3388 thermal_value
[path
] = rtw8822c_dpk_thermal_read(rtwdev
, path
);
3389 ewma_thermal_add(&dpk_info
->avg_thermal
[path
],
3390 thermal_value
[path
]);
3391 thermal_value
[path
] =
3392 ewma_thermal_read(&dpk_info
->avg_thermal
[path
]);
3393 delta_dpk
[path
] = dpk_info
->thermal_dpk
[path
] -
3394 thermal_value
[path
];
3395 offset
[path
] = delta_dpk
[path
] -
3396 dpk_info
->thermal_dpk_delta
[path
];
3397 offset
[path
] &= 0x7f;
3399 if (offset
[path
] != dpk_info
->pre_pwsf
[path
]) {
3400 rtw_write32_mask(rtwdev
, REG_NCTL0
, BIT_SUBPAGE
,
3402 rtw_write32_mask(rtwdev
, 0x1b58, GENMASK(6, 0),
3404 dpk_info
->pre_pwsf
[path
] = offset
[path
];
3409 static const struct rtw_phy_cck_pd_reg
3410 rtw8822c_cck_pd_reg
[RTW_CHANNEL_WIDTH_40
+ 1][RTW_RF_PATH_MAX
] = {
3412 {0x1ac8, 0x00ff, 0x1ad0, 0x01f},
3413 {0x1ac8, 0xff00, 0x1ad0, 0x3e0}
3416 {0x1acc, 0x00ff, 0x1ad0, 0x01F00000},
3417 {0x1acc, 0xff00, 0x1ad0, 0x3E000000}
3421 #define RTW_CCK_PD_MAX 255
3422 #define RTW_CCK_CS_MAX 31
3423 #define RTW_CCK_CS_ERR1 27
3424 #define RTW_CCK_CS_ERR2 29
3426 rtw8822c_phy_cck_pd_set_reg(struct rtw_dev
*rtwdev
,
3427 s8 pd_diff
, s8 cs_diff
, u8 bw
, u8 nrx
)
3431 if (WARN_ON(bw
> RTW_CHANNEL_WIDTH_40
|| nrx
>= RTW_RF_PATH_MAX
))
3434 pd
= rtw_read32_mask(rtwdev
,
3435 rtw8822c_cck_pd_reg
[bw
][nrx
].reg_pd
,
3436 rtw8822c_cck_pd_reg
[bw
][nrx
].mask_pd
);
3437 cs
= rtw_read32_mask(rtwdev
,
3438 rtw8822c_cck_pd_reg
[bw
][nrx
].reg_cs
,
3439 rtw8822c_cck_pd_reg
[bw
][nrx
].mask_cs
);
3442 if (pd
> RTW_CCK_PD_MAX
)
3443 pd
= RTW_CCK_PD_MAX
;
3444 if (cs
== RTW_CCK_CS_ERR1
|| cs
== RTW_CCK_CS_ERR2
)
3446 else if (cs
> RTW_CCK_CS_MAX
)
3447 cs
= RTW_CCK_CS_MAX
;
3448 rtw_write32_mask(rtwdev
,
3449 rtw8822c_cck_pd_reg
[bw
][nrx
].reg_pd
,
3450 rtw8822c_cck_pd_reg
[bw
][nrx
].mask_pd
,
3452 rtw_write32_mask(rtwdev
,
3453 rtw8822c_cck_pd_reg
[bw
][nrx
].reg_cs
,
3454 rtw8822c_cck_pd_reg
[bw
][nrx
].mask_cs
,
3457 rtw_dbg(rtwdev
, RTW_DBG_PHY
,
3458 "is_linked=%d, bw=%d, nrx=%d, cs_ratio=0x%x, pd_th=0x%x\n",
3459 rtw_is_assoc(rtwdev
), bw
, nrx
, cs
, pd
);
3462 static void rtw8822c_phy_cck_pd_set(struct rtw_dev
*rtwdev
, u8 new_lvl
)
3464 struct rtw_dm_info
*dm_info
= &rtwdev
->dm_info
;
3465 s8 pd_lvl
[CCK_PD_LV_MAX
] = {0, 2, 4, 6, 8};
3466 s8 cs_lvl
[CCK_PD_LV_MAX
] = {0, 2, 2, 2, 4};
3470 nrx
= (u8
)rtw_read32_mask(rtwdev
, 0x1a2c, 0x60000);
3471 bw
= (u8
)rtw_read32_mask(rtwdev
, 0x9b0, 0xc);
3473 rtw_dbg(rtwdev
, RTW_DBG_PHY
, "lv: (%d) -> (%d) bw=%d nr=%d cck_fa_avg=%d\n",
3474 dm_info
->cck_pd_lv
[bw
][nrx
], new_lvl
, bw
, nrx
,
3475 dm_info
->cck_fa_avg
);
3477 if (dm_info
->cck_pd_lv
[bw
][nrx
] == new_lvl
)
3480 cur_lvl
= dm_info
->cck_pd_lv
[bw
][nrx
];
3482 /* update cck pd info */
3483 dm_info
->cck_fa_avg
= CCK_FA_AVG_RESET
;
3485 rtw8822c_phy_cck_pd_set_reg(rtwdev
,
3486 pd_lvl
[new_lvl
] - pd_lvl
[cur_lvl
],
3487 cs_lvl
[new_lvl
] - cs_lvl
[cur_lvl
],
3489 dm_info
->cck_pd_lv
[bw
][nrx
] = new_lvl
;
3492 #define PWR_TRACK_MASK 0x7f
3493 static void rtw8822c_pwrtrack_set(struct rtw_dev
*rtwdev
, u8 rf_path
)
3495 struct rtw_dm_info
*dm_info
= &rtwdev
->dm_info
;
3499 rtw_write32_mask(rtwdev
, 0x18a0, PWR_TRACK_MASK
,
3500 dm_info
->delta_power_index
[rf_path
]);
3503 rtw_write32_mask(rtwdev
, 0x41a0, PWR_TRACK_MASK
,
3504 dm_info
->delta_power_index
[rf_path
]);
3511 static void rtw8822c_pwr_track_path(struct rtw_dev
*rtwdev
,
3512 struct rtw_swing_table
*swing_table
,
3515 struct rtw_dm_info
*dm_info
= &rtwdev
->dm_info
;
3516 u8 thermal_value
, delta
;
3518 if (rtwdev
->efuse
.thermal_meter
[path
] == 0xff)
3521 thermal_value
= rtw_read_rf(rtwdev
, path
, RF_T_METER
, 0x7e);
3523 rtw_phy_pwrtrack_avg(rtwdev
, thermal_value
, path
);
3525 delta
= rtw_phy_pwrtrack_get_delta(rtwdev
, path
);
3527 dm_info
->delta_power_index
[path
] =
3528 rtw_phy_pwrtrack_get_pwridx(rtwdev
, swing_table
, path
, path
,
3531 rtw8822c_pwrtrack_set(rtwdev
, path
);
3534 static void __rtw8822c_pwr_track(struct rtw_dev
*rtwdev
)
3536 struct rtw_swing_table swing_table
;
3539 rtw_phy_config_swing_table(rtwdev
, &swing_table
);
3541 for (i
= 0; i
< rtwdev
->hal
.rf_path_num
; i
++)
3542 rtw8822c_pwr_track_path(rtwdev
, &swing_table
, i
);
3544 if (rtw_phy_pwrtrack_need_iqk(rtwdev
))
3545 rtw8822c_do_iqk(rtwdev
);
3548 static void rtw8822c_pwr_track(struct rtw_dev
*rtwdev
)
3550 struct rtw_efuse
*efuse
= &rtwdev
->efuse
;
3551 struct rtw_dm_info
*dm_info
= &rtwdev
->dm_info
;
3553 if (efuse
->power_track_type
!= 0)
3556 if (!dm_info
->pwr_trk_triggered
) {
3557 rtw_write_rf(rtwdev
, RF_PATH_A
, RF_T_METER
, BIT(19), 0x01);
3558 rtw_write_rf(rtwdev
, RF_PATH_A
, RF_T_METER
, BIT(19), 0x00);
3559 rtw_write_rf(rtwdev
, RF_PATH_A
, RF_T_METER
, BIT(19), 0x01);
3561 rtw_write_rf(rtwdev
, RF_PATH_B
, RF_T_METER
, BIT(19), 0x01);
3562 rtw_write_rf(rtwdev
, RF_PATH_B
, RF_T_METER
, BIT(19), 0x00);
3563 rtw_write_rf(rtwdev
, RF_PATH_B
, RF_T_METER
, BIT(19), 0x01);
3565 dm_info
->pwr_trk_triggered
= true;
3569 __rtw8822c_pwr_track(rtwdev
);
3570 dm_info
->pwr_trk_triggered
= false;
3573 static const struct rtw_pwr_seq_cmd trans_carddis_to_cardemu_8822c
[] = {
3575 RTW_PWR_CUT_ALL_MSK
,
3576 RTW_PWR_INTF_SDIO_MSK
,
3578 RTW_PWR_CMD_WRITE
, BIT(0), 0},
3580 RTW_PWR_CUT_ALL_MSK
,
3581 RTW_PWR_INTF_SDIO_MSK
,
3583 RTW_PWR_CMD_POLLING
, BIT(1), BIT(1)},
3585 RTW_PWR_CUT_ALL_MSK
,
3586 RTW_PWR_INTF_ALL_MSK
,
3588 RTW_PWR_CMD_WRITE
, BIT(2), BIT(2)},
3590 RTW_PWR_CUT_ALL_MSK
,
3591 RTW_PWR_INTF_ALL_MSK
,
3593 RTW_PWR_CMD_WRITE
, BIT(0), 0},
3595 RTW_PWR_CUT_ALL_MSK
,
3596 RTW_PWR_INTF_ALL_MSK
,
3598 RTW_PWR_CMD_WRITE
, BIT(7), 0},
3600 RTW_PWR_CUT_ALL_MSK
,
3601 RTW_PWR_INTF_USB_MSK
,
3603 RTW_PWR_CMD_WRITE
, BIT(0), 0},
3605 RTW_PWR_CUT_ALL_MSK
,
3606 RTW_PWR_INTF_ALL_MSK
,
3608 RTW_PWR_CMD_WRITE
, BIT(3) | BIT(4) | BIT(7), 0},
3610 RTW_PWR_CUT_ALL_MSK
,
3611 RTW_PWR_INTF_ALL_MSK
,
3613 RTW_PWR_CMD_END
, 0, 0},
3616 static const struct rtw_pwr_seq_cmd trans_cardemu_to_act_8822c
[] = {
3618 RTW_PWR_CUT_ALL_MSK
,
3619 RTW_PWR_INTF_USB_MSK
| RTW_PWR_INTF_SDIO_MSK
,
3621 RTW_PWR_CMD_WRITE
, BIT(5), 0},
3623 RTW_PWR_CUT_ALL_MSK
,
3624 RTW_PWR_INTF_ALL_MSK
,
3626 RTW_PWR_CMD_WRITE
, (BIT(4) | BIT(3) | BIT(2)), 0},
3628 RTW_PWR_CUT_ALL_MSK
,
3629 RTW_PWR_INTF_PCI_MSK
,
3631 RTW_PWR_CMD_WRITE
, BIT(0), BIT(0)},
3633 RTW_PWR_CUT_ALL_MSK
,
3634 RTW_PWR_INTF_ALL_MSK
,
3636 RTW_PWR_CMD_POLLING
, BIT(1), BIT(1)},
3638 RTW_PWR_CUT_ALL_MSK
,
3639 RTW_PWR_INTF_PCI_MSK
,
3641 RTW_PWR_CMD_WRITE
, BIT(0), 0},
3643 RTW_PWR_CUT_ALL_MSK
,
3644 RTW_PWR_INTF_USB_MSK
,
3646 RTW_PWR_CMD_WRITE
, 0xFF, 0},
3648 RTW_PWR_CUT_ALL_MSK
,
3649 RTW_PWR_INTF_ALL_MSK
,
3651 RTW_PWR_CMD_WRITE
, BIT(3), 0},
3653 RTW_PWR_CUT_ALL_MSK
,
3654 RTW_PWR_INTF_ALL_MSK
,
3656 RTW_PWR_CMD_WRITE
, BIT(0), BIT(0)},
3658 RTW_PWR_CUT_ALL_MSK
,
3659 RTW_PWR_INTF_ALL_MSK
,
3661 RTW_PWR_CMD_WRITE
, (BIT(4) | BIT(3)), 0},
3663 RTW_PWR_CUT_ALL_MSK
,
3664 RTW_PWR_INTF_ALL_MSK
,
3666 RTW_PWR_CMD_WRITE
, BIT(2), BIT(2)},
3668 RTW_PWR_CUT_ALL_MSK
,
3669 RTW_PWR_INTF_ALL_MSK
,
3671 RTW_PWR_CMD_WRITE
, BIT(0), BIT(0)},
3673 RTW_PWR_CUT_ALL_MSK
,
3674 RTW_PWR_INTF_ALL_MSK
,
3676 RTW_PWR_CMD_POLLING
, BIT(0), 0},
3678 RTW_PWR_CUT_ALL_MSK
,
3679 RTW_PWR_INTF_PCI_MSK
,
3681 RTW_PWR_CMD_WRITE
, BIT(5), BIT(5)},
3683 RTW_PWR_CUT_ALL_MSK
,
3684 RTW_PWR_INTF_PCI_MSK
,
3686 RTW_PWR_CMD_WRITE
, BIT(4), 0},
3688 RTW_PWR_CUT_ALL_MSK
,
3689 RTW_PWR_INTF_PCI_MSK
,
3691 RTW_PWR_CMD_WRITE
, (BIT(7) | BIT(6) | BIT(5)),
3692 (BIT(7) | BIT(6) | BIT(5))},
3694 RTW_PWR_CUT_ALL_MSK
,
3695 RTW_PWR_INTF_PCI_MSK
,
3697 RTW_PWR_CMD_WRITE
, (BIT(7) | BIT(6) | BIT(5)), 0},
3699 RTW_PWR_CUT_ALL_MSK
,
3700 RTW_PWR_INTF_ALL_MSK
,
3702 RTW_PWR_CMD_WRITE
, (BIT(7) | BIT(6)), BIT(7)},
3704 RTW_PWR_CUT_ALL_MSK
,
3705 RTW_PWR_INTF_ALL_MSK
,
3707 RTW_PWR_CMD_WRITE
, (BIT(7) | BIT(6)), BIT(7)},
3709 RTW_PWR_CUT_ALL_MSK
,
3710 RTW_PWR_INTF_ALL_MSK
,
3712 RTW_PWR_CMD_WRITE
, BIT(4), BIT(4)},
3714 RTW_PWR_CUT_ALL_MSK
,
3715 RTW_PWR_INTF_ALL_MSK
,
3717 RTW_PWR_CMD_WRITE
, BIT(2), BIT(2)},
3719 RTW_PWR_CUT_ALL_MSK
,
3720 RTW_PWR_INTF_ALL_MSK
,
3722 RTW_PWR_CMD_WRITE
, BIT(1), BIT(1)},
3724 RTW_PWR_CUT_ALL_MSK
,
3725 RTW_PWR_INTF_ALL_MSK
,
3727 RTW_PWR_CMD_END
, 0, 0},
3730 static const struct rtw_pwr_seq_cmd trans_act_to_cardemu_8822c
[] = {
3732 RTW_PWR_CUT_ALL_MSK
,
3733 RTW_PWR_INTF_ALL_MSK
,
3735 RTW_PWR_CMD_WRITE
, BIT(3), 0},
3737 RTW_PWR_CUT_ALL_MSK
,
3738 RTW_PWR_INTF_ALL_MSK
,
3740 RTW_PWR_CMD_WRITE
, 0xFF, 0},
3742 RTW_PWR_CUT_ALL_MSK
,
3743 RTW_PWR_INTF_ALL_MSK
,
3745 RTW_PWR_CMD_WRITE
, 0xFF, 0},
3747 RTW_PWR_CUT_ALL_MSK
,
3748 RTW_PWR_INTF_ALL_MSK
,
3750 RTW_PWR_CMD_WRITE
, BIT(4), 0},
3752 RTW_PWR_CUT_ALL_MSK
,
3753 RTW_PWR_INTF_USB_MSK
,
3755 RTW_PWR_CMD_WRITE
, 0xFF, 0x30},
3757 RTW_PWR_CUT_ALL_MSK
,
3758 RTW_PWR_INTF_ALL_MSK
,
3760 RTW_PWR_CMD_WRITE
, BIT(1), 0},
3762 RTW_PWR_CUT_ALL_MSK
,
3763 RTW_PWR_INTF_ALL_MSK
,
3765 RTW_PWR_CMD_WRITE
, BIT(0), BIT(0)},
3767 RTW_PWR_CUT_ALL_MSK
,
3768 RTW_PWR_INTF_ALL_MSK
,
3770 RTW_PWR_CMD_WRITE
, BIT(1), 0},
3772 RTW_PWR_CUT_ALL_MSK
,
3773 RTW_PWR_INTF_ALL_MSK
,
3775 RTW_PWR_CMD_WRITE
, BIT(1), BIT(1)},
3777 RTW_PWR_CUT_ALL_MSK
,
3778 RTW_PWR_INTF_ALL_MSK
,
3780 RTW_PWR_CMD_POLLING
, BIT(1), 0},
3782 RTW_PWR_CUT_ALL_MSK
,
3783 RTW_PWR_INTF_USB_MSK
| RTW_PWR_INTF_SDIO_MSK
,
3785 RTW_PWR_CMD_WRITE
, BIT(5), BIT(5)},
3787 RTW_PWR_CUT_ALL_MSK
,
3788 RTW_PWR_INTF_ALL_MSK
,
3790 RTW_PWR_CMD_END
, 0, 0},
3793 static const struct rtw_pwr_seq_cmd trans_cardemu_to_carddis_8822c
[] = {
3795 RTW_PWR_CUT_ALL_MSK
,
3796 RTW_PWR_INTF_SDIO_MSK
,
3798 RTW_PWR_CMD_WRITE
, BIT(7), BIT(7)},
3800 RTW_PWR_CUT_ALL_MSK
,
3801 RTW_PWR_INTF_USB_MSK
| RTW_PWR_INTF_SDIO_MSK
,
3803 RTW_PWR_CMD_WRITE
, 0xFF, 0x00},
3805 RTW_PWR_CUT_ALL_MSK
,
3806 RTW_PWR_INTF_ALL_MSK
,
3808 RTW_PWR_CMD_WRITE
, BIT(5), 0},
3810 RTW_PWR_CUT_ALL_MSK
,
3811 RTW_PWR_INTF_USB_MSK
,
3813 RTW_PWR_CMD_WRITE
, BIT(0), 0},
3815 RTW_PWR_CUT_ALL_MSK
,
3816 RTW_PWR_INTF_ALL_MSK
,
3818 RTW_PWR_CMD_WRITE
, BIT(7) | BIT(6), 0},
3820 RTW_PWR_CUT_ALL_MSK
,
3821 RTW_PWR_INTF_ALL_MSK
,
3823 RTW_PWR_CMD_WRITE
, BIT(1), 0},
3825 RTW_PWR_CUT_ALL_MSK
,
3826 RTW_PWR_INTF_PCI_MSK
,
3828 RTW_PWR_CMD_WRITE
, 0xFF, 0x20},
3830 RTW_PWR_CUT_ALL_MSK
,
3831 RTW_PWR_INTF_PCI_MSK
,
3833 RTW_PWR_CMD_WRITE
, 0xFF, 0x04},
3835 RTW_PWR_CUT_ALL_MSK
,
3836 RTW_PWR_INTF_USB_MSK
| RTW_PWR_INTF_SDIO_MSK
,
3838 RTW_PWR_CMD_WRITE
, BIT(3) | BIT(4), BIT(3)},
3840 RTW_PWR_CUT_ALL_MSK
,
3841 RTW_PWR_INTF_PCI_MSK
,
3843 RTW_PWR_CMD_WRITE
, BIT(2), BIT(2)},
3845 RTW_PWR_CUT_ALL_MSK
,
3846 RTW_PWR_INTF_SDIO_MSK
,
3848 RTW_PWR_CMD_WRITE
, BIT(0), BIT(0)},
3850 RTW_PWR_CUT_ALL_MSK
,
3851 RTW_PWR_INTF_ALL_MSK
,
3853 RTW_PWR_CMD_END
, 0, 0},
3856 static const struct rtw_pwr_seq_cmd
*card_enable_flow_8822c
[] = {
3857 trans_carddis_to_cardemu_8822c
,
3858 trans_cardemu_to_act_8822c
,
3862 static const struct rtw_pwr_seq_cmd
*card_disable_flow_8822c
[] = {
3863 trans_act_to_cardemu_8822c
,
3864 trans_cardemu_to_carddis_8822c
,
3868 static const struct rtw_intf_phy_para usb2_param_8822c
[] = {
3871 RTW_INTF_PHY_CUT_ALL
,
3872 RTW_INTF_PHY_PLATFORM_ALL
},
3875 static const struct rtw_intf_phy_para usb3_param_8822c
[] = {
3878 RTW_INTF_PHY_CUT_ALL
,
3879 RTW_INTF_PHY_PLATFORM_ALL
},
3882 static const struct rtw_intf_phy_para pcie_gen1_param_8822c
[] = {
3885 RTW_INTF_PHY_CUT_ALL
,
3886 RTW_INTF_PHY_PLATFORM_ALL
},
3889 static const struct rtw_intf_phy_para pcie_gen2_param_8822c
[] = {
3892 RTW_INTF_PHY_CUT_ALL
,
3893 RTW_INTF_PHY_PLATFORM_ALL
},
3896 static const struct rtw_intf_phy_para_table phy_para_table_8822c
= {
3897 .usb2_para
= usb2_param_8822c
,
3898 .usb3_para
= usb3_param_8822c
,
3899 .gen1_para
= pcie_gen1_param_8822c
,
3900 .gen2_para
= pcie_gen2_param_8822c
,
3901 .n_usb2_para
= ARRAY_SIZE(usb2_param_8822c
),
3902 .n_usb3_para
= ARRAY_SIZE(usb2_param_8822c
),
3903 .n_gen1_para
= ARRAY_SIZE(pcie_gen1_param_8822c
),
3904 .n_gen2_para
= ARRAY_SIZE(pcie_gen2_param_8822c
),
3907 static const struct rtw_rfe_def rtw8822c_rfe_defs
[] = {
3908 [0] = RTW_DEF_RFE(8822c
, 0, 0),
3909 [1] = RTW_DEF_RFE(8822c
, 0, 0),
3910 [2] = RTW_DEF_RFE(8822c
, 0, 0),
3911 [5] = RTW_DEF_RFE(8822c
, 0, 5),
3912 [6] = RTW_DEF_RFE(8822c
, 0, 0),
3915 static const struct rtw_hw_reg rtw8822c_dig
[] = {
3916 [0] = { .addr
= 0x1d70, .mask
= 0x7f },
3917 [1] = { .addr
= 0x1d70, .mask
= 0x7f00 },
3920 static const struct rtw_ltecoex_addr rtw8822c_ltecoex_addr
= {
3921 .ctrl
= LTECOEX_ACCESS_CTRL
,
3922 .wdata
= LTECOEX_WRITE_DATA
,
3923 .rdata
= LTECOEX_READ_DATA
,
3926 static const struct rtw_page_table page_table_8822c
[] = {
3927 {64, 64, 64, 64, 1},
3928 {64, 64, 64, 64, 1},
3931 {64, 64, 64, 64, 1},
3934 static const struct rtw_rqpn rqpn_table_8822c
[] = {
3935 {RTW_DMA_MAPPING_NORMAL
, RTW_DMA_MAPPING_NORMAL
,
3936 RTW_DMA_MAPPING_LOW
, RTW_DMA_MAPPING_LOW
,
3937 RTW_DMA_MAPPING_EXTRA
, RTW_DMA_MAPPING_HIGH
},
3938 {RTW_DMA_MAPPING_NORMAL
, RTW_DMA_MAPPING_NORMAL
,
3939 RTW_DMA_MAPPING_LOW
, RTW_DMA_MAPPING_LOW
,
3940 RTW_DMA_MAPPING_EXTRA
, RTW_DMA_MAPPING_HIGH
},
3941 {RTW_DMA_MAPPING_NORMAL
, RTW_DMA_MAPPING_NORMAL
,
3942 RTW_DMA_MAPPING_NORMAL
, RTW_DMA_MAPPING_HIGH
,
3943 RTW_DMA_MAPPING_HIGH
, RTW_DMA_MAPPING_HIGH
},
3944 {RTW_DMA_MAPPING_NORMAL
, RTW_DMA_MAPPING_NORMAL
,
3945 RTW_DMA_MAPPING_LOW
, RTW_DMA_MAPPING_LOW
,
3946 RTW_DMA_MAPPING_HIGH
, RTW_DMA_MAPPING_HIGH
},
3947 {RTW_DMA_MAPPING_NORMAL
, RTW_DMA_MAPPING_NORMAL
,
3948 RTW_DMA_MAPPING_LOW
, RTW_DMA_MAPPING_LOW
,
3949 RTW_DMA_MAPPING_EXTRA
, RTW_DMA_MAPPING_HIGH
},
3952 static struct rtw_prioq_addrs prioq_addrs_8822c
= {
3953 .prio
[RTW_DMA_MAPPING_EXTRA
] = {
3954 .rsvd
= REG_FIFOPAGE_INFO_4
, .avail
= REG_FIFOPAGE_INFO_4
+ 2,
3956 .prio
[RTW_DMA_MAPPING_LOW
] = {
3957 .rsvd
= REG_FIFOPAGE_INFO_2
, .avail
= REG_FIFOPAGE_INFO_2
+ 2,
3959 .prio
[RTW_DMA_MAPPING_NORMAL
] = {
3960 .rsvd
= REG_FIFOPAGE_INFO_3
, .avail
= REG_FIFOPAGE_INFO_3
+ 2,
3962 .prio
[RTW_DMA_MAPPING_HIGH
] = {
3963 .rsvd
= REG_FIFOPAGE_INFO_1
, .avail
= REG_FIFOPAGE_INFO_1
+ 2,
3968 static struct rtw_chip_ops rtw8822c_ops
= {
3969 .phy_set_param
= rtw8822c_phy_set_param
,
3970 .read_efuse
= rtw8822c_read_efuse
,
3971 .query_rx_desc
= rtw8822c_query_rx_desc
,
3972 .set_channel
= rtw8822c_set_channel
,
3973 .mac_init
= rtw8822c_mac_init
,
3974 .read_rf
= rtw_phy_read_rf
,
3975 .write_rf
= rtw_phy_write_rf_reg_mix
,
3976 .set_tx_power_index
= rtw8822c_set_tx_power_index
,
3977 .set_antenna
= rtw8822c_set_antenna
,
3978 .cfg_ldo25
= rtw8822c_cfg_ldo25
,
3979 .false_alarm_statistics
= rtw8822c_false_alarm_statistics
,
3980 .dpk_track
= rtw8822c_dpk_track
,
3981 .phy_calibration
= rtw8822c_phy_calibration
,
3982 .cck_pd_set
= rtw8822c_phy_cck_pd_set
,
3983 .pwr_track
= rtw8822c_pwr_track
,
3984 .config_bfee
= rtw8822c_bf_config_bfee
,
3985 .set_gid_table
= rtw_bf_set_gid_table
,
3986 .cfg_csi_rate
= rtw_bf_cfg_csi_rate
,
3988 .coex_set_init
= rtw8822c_coex_cfg_init
,
3989 .coex_set_ant_switch
= NULL
,
3990 .coex_set_gnt_fix
= rtw8822c_coex_cfg_gnt_fix
,
3991 .coex_set_gnt_debug
= rtw8822c_coex_cfg_gnt_debug
,
3992 .coex_set_rfe_type
= rtw8822c_coex_cfg_rfe_type
,
3993 .coex_set_wl_tx_power
= rtw8822c_coex_cfg_wl_tx_power
,
3994 .coex_set_wl_rx_gain
= rtw8822c_coex_cfg_wl_rx_gain
,
3997 /* Shared-Antenna Coex Table */
3998 static const struct coex_table_para table_sant_8822c
[] = {
3999 {0xffffffff, 0xffffffff}, /* case-0 */
4000 {0x55555555, 0x55555555},
4001 {0x66555555, 0x66555555},
4002 {0xaaaaaaaa, 0xaaaaaaaa},
4003 {0x5a5a5a5a, 0x5a5a5a5a},
4004 {0xfafafafa, 0xfafafafa}, /* case-5 */
4005 {0x6a5a5555, 0xaaaaaaaa},
4006 {0x6a5a56aa, 0x6a5a56aa},
4007 {0x6a5a5a5a, 0x6a5a5a5a},
4008 {0x66555555, 0x5a5a5a5a},
4009 {0x66555555, 0x6a5a5a5a}, /* case-10 */
4010 {0x66555555, 0x6a5a5aaa},
4011 {0x66555555, 0x5a5a5aaa},
4012 {0x66555555, 0x6aaa5aaa},
4013 {0x66555555, 0xaaaa5aaa},
4014 {0x66555555, 0xaaaaaaaa}, /* case-15 */
4015 {0xffff55ff, 0xfafafafa},
4016 {0xffff55ff, 0x6afa5afa},
4017 {0xaaffffaa, 0xfafafafa},
4018 {0xaa5555aa, 0x5a5a5a5a},
4019 {0xaa5555aa, 0x6a5a5a5a}, /* case-20 */
4020 {0xaa5555aa, 0xaaaaaaaa},
4021 {0xffffffff, 0x5a5a5a5a},
4022 {0xffffffff, 0x5a5a5a5a},
4023 {0xffffffff, 0x55555555},
4024 {0xffffffff, 0x5a5a5aaa}, /* case-25 */
4025 {0x55555555, 0x5a5a5a5a},
4026 {0x55555555, 0xaaaaaaaa},
4027 {0x55555555, 0x6a5a6a5a},
4028 {0x66556655, 0x66556655},
4029 {0x66556aaa, 0x6a5a6aaa}, /*case-30*/
4030 {0xffffffff, 0x5aaa5aaa},
4031 {0x56555555, 0x5a5a5aaa},
4034 /* Non-Shared-Antenna Coex Table */
4035 static const struct coex_table_para table_nsant_8822c
[] = {
4036 {0xffffffff, 0xffffffff}, /* case-100 */
4037 {0x55555555, 0x55555555},
4038 {0x66555555, 0x66555555},
4039 {0xaaaaaaaa, 0xaaaaaaaa},
4040 {0x5a5a5a5a, 0x5a5a5a5a},
4041 {0xfafafafa, 0xfafafafa}, /* case-105 */
4042 {0x5afa5afa, 0x5afa5afa},
4043 {0x55555555, 0xfafafafa},
4044 {0x66555555, 0xfafafafa},
4045 {0x66555555, 0x5a5a5a5a},
4046 {0x66555555, 0x6a5a5a5a}, /* case-110 */
4047 {0x66555555, 0xaaaaaaaa},
4048 {0xffff55ff, 0xfafafafa},
4049 {0xffff55ff, 0x5afa5afa},
4050 {0xffff55ff, 0xaaaaaaaa},
4051 {0xffff55ff, 0xffff55ff}, /* case-115 */
4052 {0xaaffffaa, 0x5afa5afa},
4053 {0xaaffffaa, 0xaaaaaaaa},
4054 {0xffffffff, 0xfafafafa},
4055 {0xffffffff, 0x5afa5afa},
4056 {0xffffffff, 0xaaaaaaaa}, /* case-120 */
4057 {0x55ff55ff, 0x5afa5afa},
4058 {0x55ff55ff, 0xaaaaaaaa},
4059 {0x55ff55ff, 0x55ff55ff}
4062 /* Shared-Antenna TDMA */
4063 static const struct coex_tdma_para tdma_sant_8822c
[] = {
4064 { {0x00, 0x00, 0x00, 0x00, 0x00} }, /* case-0 */
4065 { {0x61, 0x45, 0x03, 0x11, 0x11} }, /* case-1 */
4066 { {0x61, 0x3a, 0x03, 0x11, 0x11} },
4067 { {0x61, 0x30, 0x03, 0x11, 0x11} },
4068 { {0x61, 0x20, 0x03, 0x11, 0x11} },
4069 { {0x61, 0x10, 0x03, 0x11, 0x11} }, /* case-5 */
4070 { {0x61, 0x45, 0x03, 0x11, 0x10} },
4071 { {0x61, 0x3a, 0x03, 0x11, 0x10} },
4072 { {0x61, 0x30, 0x03, 0x11, 0x10} },
4073 { {0x61, 0x20, 0x03, 0x11, 0x10} },
4074 { {0x61, 0x10, 0x03, 0x11, 0x10} }, /* case-10 */
4075 { {0x61, 0x08, 0x03, 0x11, 0x14} },
4076 { {0x61, 0x08, 0x03, 0x10, 0x14} },
4077 { {0x51, 0x08, 0x03, 0x10, 0x54} },
4078 { {0x51, 0x08, 0x03, 0x10, 0x55} },
4079 { {0x51, 0x08, 0x07, 0x10, 0x54} }, /* case-15 */
4080 { {0x51, 0x45, 0x03, 0x10, 0x50} },
4081 { {0x51, 0x3a, 0x03, 0x10, 0x50} },
4082 { {0x51, 0x30, 0x03, 0x10, 0x50} },
4083 { {0x51, 0x20, 0x03, 0x10, 0x50} },
4084 { {0x51, 0x10, 0x03, 0x10, 0x50} }, /* case-20 */
4085 { {0x51, 0x4a, 0x03, 0x10, 0x50} },
4086 { {0x51, 0x0c, 0x03, 0x10, 0x54} },
4087 { {0x55, 0x08, 0x03, 0x10, 0x54} },
4088 { {0x65, 0x10, 0x03, 0x11, 0x10} },
4089 { {0x51, 0x10, 0x03, 0x10, 0x51} }, /* case-25 */
4090 { {0x51, 0x08, 0x03, 0x10, 0x50} },
4091 { {0x61, 0x08, 0x03, 0x11, 0x11} }
4094 /* Non-Shared-Antenna TDMA */
4095 static const struct coex_tdma_para tdma_nsant_8822c
[] = {
4096 { {0x00, 0x00, 0x00, 0x00, 0x00} }, /* case-100 */
4097 { {0x61, 0x45, 0x03, 0x11, 0x11} },
4098 { {0x61, 0x3a, 0x03, 0x11, 0x11} },
4099 { {0x61, 0x30, 0x03, 0x11, 0x11} },
4100 { {0x61, 0x20, 0x03, 0x11, 0x11} },
4101 { {0x61, 0x10, 0x03, 0x11, 0x11} }, /* case-105 */
4102 { {0x61, 0x45, 0x03, 0x11, 0x10} },
4103 { {0x61, 0x3a, 0x03, 0x11, 0x10} },
4104 { {0x61, 0x30, 0x03, 0x11, 0x10} },
4105 { {0x61, 0x20, 0x03, 0x11, 0x10} },
4106 { {0x61, 0x10, 0x03, 0x11, 0x10} }, /* case-110 */
4107 { {0x61, 0x08, 0x03, 0x11, 0x14} },
4108 { {0x61, 0x08, 0x03, 0x10, 0x14} },
4109 { {0x51, 0x08, 0x03, 0x10, 0x54} },
4110 { {0x51, 0x08, 0x03, 0x10, 0x55} },
4111 { {0x51, 0x08, 0x07, 0x10, 0x54} }, /* case-115 */
4112 { {0x51, 0x45, 0x03, 0x10, 0x50} },
4113 { {0x51, 0x3a, 0x03, 0x10, 0x50} },
4114 { {0x51, 0x30, 0x03, 0x10, 0x50} },
4115 { {0x51, 0x20, 0x03, 0x10, 0x50} },
4116 { {0x51, 0x10, 0x03, 0x10, 0x50} }, /* case-120 */
4117 { {0x51, 0x08, 0x03, 0x10, 0x50} }
4120 /* rssi in percentage % (dbm = % - 100) */
4121 static const u8 wl_rssi_step_8822c
[] = {60, 50, 44, 30};
4122 static const u8 bt_rssi_step_8822c
[] = {8, 15, 20, 25};
4123 static const struct coex_5g_afh_map afh_5g_8822c
[] = { {0, 0, 0} };
4125 /* wl_tx_dec_power, bt_tx_dec_power, wl_rx_gain, bt_rx_lna_constrain */
4126 static const struct coex_rf_para rf_para_tx_8822c
[] = {
4127 {0, 0, false, 7}, /* for normal */
4128 {0, 16, false, 7}, /* for WL-CPT */
4135 static const struct coex_rf_para rf_para_rx_8822c
[] = {
4136 {0, 0, false, 7}, /* for normal */
4137 {0, 16, false, 7}, /* for WL-CPT */
4144 static_assert(ARRAY_SIZE(rf_para_tx_8822c
) == ARRAY_SIZE(rf_para_rx_8822c
));
4147 rtw8822c_pwrtrk_5gb_n
[RTW_PWR_TRK_5G_NUM
][RTW_PWR_TRK_TBL_SZ
] = {
4148 { 0, 1, 2, 3, 5, 6, 7, 8, 9, 10,
4149 11, 12, 13, 14, 15, 16, 18, 19, 20, 21,
4150 22, 23, 24, 25, 26, 27, 28, 29, 30, 32 },
4151 { 0, 1, 2, 3, 5, 6, 7, 8, 9, 10,
4152 11, 12, 13, 14, 15, 16, 18, 19, 20, 21,
4153 22, 23, 24, 25, 26, 27, 28, 29, 30, 32 },
4154 { 0, 1, 2, 3, 5, 6, 7, 8, 9, 10,
4155 11, 12, 13, 14, 15, 16, 18, 19, 20, 21,
4156 22, 23, 24, 25, 26, 27, 28, 29, 30, 32 },
4160 rtw8822c_pwrtrk_5gb_p
[RTW_PWR_TRK_5G_NUM
][RTW_PWR_TRK_TBL_SZ
] = {
4161 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
4162 10, 10, 11, 12, 13, 14, 15, 16, 17, 18,
4163 19, 20, 21, 22, 22, 23, 24, 25, 26, 27 },
4164 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
4165 10, 10, 11, 12, 13, 14, 15, 16, 17, 18,
4166 19, 20, 21, 22, 22, 23, 24, 25, 26, 27 },
4167 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
4168 10, 10, 11, 12, 13, 14, 15, 16, 17, 18,
4169 19, 20, 21, 22, 22, 23, 24, 25, 26, 27 },
4173 rtw8822c_pwrtrk_5ga_n
[RTW_PWR_TRK_5G_NUM
][RTW_PWR_TRK_TBL_SZ
] = {
4174 { 0, 1, 2, 4, 5, 6, 7, 8, 9, 10,
4175 11, 13, 14, 15, 16, 17, 18, 19, 20, 21,
4176 23, 24, 25, 26, 27, 28, 29, 30, 31, 33 },
4177 { 0, 1, 2, 4, 5, 6, 7, 8, 9, 10,
4178 11, 13, 14, 15, 16, 17, 18, 19, 20, 21,
4179 23, 24, 25, 26, 27, 28, 29, 30, 31, 33 },
4180 { 0, 1, 2, 4, 5, 6, 7, 8, 9, 10,
4181 11, 13, 14, 15, 16, 17, 18, 19, 20, 21,
4182 23, 24, 25, 26, 27, 28, 29, 30, 31, 33 },
4186 rtw8822c_pwrtrk_5ga_p
[RTW_PWR_TRK_5G_NUM
][RTW_PWR_TRK_TBL_SZ
] = {
4187 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
4188 10, 11, 12, 13, 14, 15, 16, 17, 18, 20,
4189 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 },
4190 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
4191 10, 11, 12, 13, 14, 15, 16, 17, 18, 20,
4192 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 },
4193 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
4194 10, 11, 12, 13, 14, 15, 16, 17, 18, 20,
4195 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 },
4198 static const u8 rtw8822c_pwrtrk_2gb_n
[RTW_PWR_TRK_TBL_SZ
] = {
4199 0, 1, 2, 3, 4, 4, 5, 6, 7, 8,
4200 9, 9, 10, 11, 12, 13, 14, 15, 15, 16,
4201 17, 18, 19, 20, 20, 21, 22, 23, 24, 25
4204 static const u8 rtw8822c_pwrtrk_2gb_p
[RTW_PWR_TRK_TBL_SZ
] = {
4205 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
4206 10, 11, 12, 13, 14, 14, 15, 16, 17, 18,
4207 19, 20, 21, 22, 23, 24, 25, 26, 27, 28
4210 static const u8 rtw8822c_pwrtrk_2ga_n
[RTW_PWR_TRK_TBL_SZ
] = {
4211 0, 1, 2, 2, 3, 4, 4, 5, 6, 6,
4212 7, 8, 8, 9, 9, 10, 11, 11, 12, 13,
4213 13, 14, 15, 15, 16, 17, 17, 18, 19, 19
4216 static const u8 rtw8822c_pwrtrk_2ga_p
[RTW_PWR_TRK_TBL_SZ
] = {
4217 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
4218 10, 11, 11, 12, 13, 14, 15, 16, 17, 18,
4219 19, 20, 21, 22, 23, 24, 25, 25, 26, 27
4222 static const u8 rtw8822c_pwrtrk_2g_cck_b_n
[RTW_PWR_TRK_TBL_SZ
] = {
4223 0, 1, 2, 3, 4, 5, 5, 6, 7, 8,
4224 9, 10, 11, 11, 12, 13, 14, 15, 16, 17,
4225 17, 18, 19, 20, 21, 22, 23, 23, 24, 25
4228 static const u8 rtw8822c_pwrtrk_2g_cck_b_p
[RTW_PWR_TRK_TBL_SZ
] = {
4229 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
4230 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
4231 20, 21, 22, 23, 24, 25, 26, 27, 28, 29
4234 static const u8 rtw8822c_pwrtrk_2g_cck_a_n
[RTW_PWR_TRK_TBL_SZ
] = {
4235 0, 1, 2, 3, 3, 4, 5, 6, 6, 7,
4236 8, 9, 9, 10, 11, 12, 12, 13, 14, 15,
4237 15, 16, 17, 18, 18, 19, 20, 21, 21, 22
4240 static const u8 rtw8822c_pwrtrk_2g_cck_a_p
[RTW_PWR_TRK_TBL_SZ
] = {
4241 0, 1, 2, 3, 4, 5, 5, 6, 7, 8,
4242 9, 10, 11, 11, 12, 13, 14, 15, 16, 17,
4243 18, 18, 19, 20, 21, 22, 23, 24, 24, 25
4246 static const struct rtw_pwr_track_tbl rtw8822c_rtw_pwr_track_tbl
= {
4247 .pwrtrk_5gb_n
[RTW_PWR_TRK_5G_1
] = rtw8822c_pwrtrk_5gb_n
[RTW_PWR_TRK_5G_1
],
4248 .pwrtrk_5gb_n
[RTW_PWR_TRK_5G_2
] = rtw8822c_pwrtrk_5gb_n
[RTW_PWR_TRK_5G_2
],
4249 .pwrtrk_5gb_n
[RTW_PWR_TRK_5G_3
] = rtw8822c_pwrtrk_5gb_n
[RTW_PWR_TRK_5G_3
],
4250 .pwrtrk_5gb_p
[RTW_PWR_TRK_5G_1
] = rtw8822c_pwrtrk_5gb_p
[RTW_PWR_TRK_5G_1
],
4251 .pwrtrk_5gb_p
[RTW_PWR_TRK_5G_2
] = rtw8822c_pwrtrk_5gb_p
[RTW_PWR_TRK_5G_2
],
4252 .pwrtrk_5gb_p
[RTW_PWR_TRK_5G_3
] = rtw8822c_pwrtrk_5gb_p
[RTW_PWR_TRK_5G_3
],
4253 .pwrtrk_5ga_n
[RTW_PWR_TRK_5G_1
] = rtw8822c_pwrtrk_5ga_n
[RTW_PWR_TRK_5G_1
],
4254 .pwrtrk_5ga_n
[RTW_PWR_TRK_5G_2
] = rtw8822c_pwrtrk_5ga_n
[RTW_PWR_TRK_5G_2
],
4255 .pwrtrk_5ga_n
[RTW_PWR_TRK_5G_3
] = rtw8822c_pwrtrk_5ga_n
[RTW_PWR_TRK_5G_3
],
4256 .pwrtrk_5ga_p
[RTW_PWR_TRK_5G_1
] = rtw8822c_pwrtrk_5ga_p
[RTW_PWR_TRK_5G_1
],
4257 .pwrtrk_5ga_p
[RTW_PWR_TRK_5G_2
] = rtw8822c_pwrtrk_5ga_p
[RTW_PWR_TRK_5G_2
],
4258 .pwrtrk_5ga_p
[RTW_PWR_TRK_5G_3
] = rtw8822c_pwrtrk_5ga_p
[RTW_PWR_TRK_5G_3
],
4259 .pwrtrk_2gb_n
= rtw8822c_pwrtrk_2gb_n
,
4260 .pwrtrk_2gb_p
= rtw8822c_pwrtrk_2gb_p
,
4261 .pwrtrk_2ga_n
= rtw8822c_pwrtrk_2ga_n
,
4262 .pwrtrk_2ga_p
= rtw8822c_pwrtrk_2ga_p
,
4263 .pwrtrk_2g_cckb_n
= rtw8822c_pwrtrk_2g_cck_b_n
,
4264 .pwrtrk_2g_cckb_p
= rtw8822c_pwrtrk_2g_cck_b_p
,
4265 .pwrtrk_2g_ccka_n
= rtw8822c_pwrtrk_2g_cck_a_n
,
4266 .pwrtrk_2g_ccka_p
= rtw8822c_pwrtrk_2g_cck_a_p
,
4270 static const struct wiphy_wowlan_support rtw_wowlan_stub_8822c
= {
4271 .flags
= WIPHY_WOWLAN_MAGIC_PKT
| WIPHY_WOWLAN_GTK_REKEY_FAILURE
|
4272 WIPHY_WOWLAN_DISCONNECT
| WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
|
4273 WIPHY_WOWLAN_NET_DETECT
,
4274 .n_patterns
= RTW_MAX_PATTERN_NUM
,
4275 .pattern_max_len
= RTW_MAX_PATTERN_SIZE
,
4276 .pattern_min_len
= 1,
4277 .max_nd_match_sets
= 4,
4281 static const struct rtw_reg_domain coex_info_hw_regs_8822c
[] = {
4282 {0x1860, BIT(3), RTW_REG_DOMAIN_MAC8
},
4283 {0x4160, BIT(3), RTW_REG_DOMAIN_MAC8
},
4284 {0x1c32, BIT(6), RTW_REG_DOMAIN_MAC8
},
4285 {0x1c38, BIT(28), RTW_REG_DOMAIN_MAC32
},
4286 {0, 0, RTW_REG_DOMAIN_NL
},
4287 {0x430, MASKDWORD
, RTW_REG_DOMAIN_MAC32
},
4288 {0x434, MASKDWORD
, RTW_REG_DOMAIN_MAC32
},
4289 {0x42a, MASKLWORD
, RTW_REG_DOMAIN_MAC16
},
4290 {0x426, MASKBYTE0
, RTW_REG_DOMAIN_MAC8
},
4291 {0x45e, BIT(3), RTW_REG_DOMAIN_MAC8
},
4292 {0x454, MASKLWORD
, RTW_REG_DOMAIN_MAC16
},
4293 {0, 0, RTW_REG_DOMAIN_NL
},
4294 {0x4c, BIT(24) | BIT(23), RTW_REG_DOMAIN_MAC32
},
4295 {0x64, BIT(0), RTW_REG_DOMAIN_MAC8
},
4296 {0x4c6, BIT(4), RTW_REG_DOMAIN_MAC8
},
4297 {0x40, BIT(5), RTW_REG_DOMAIN_MAC8
},
4298 {0x1, RFREG_MASK
, RTW_REG_DOMAIN_RF_B
},
4299 {0, 0, RTW_REG_DOMAIN_NL
},
4300 {0x550, MASKDWORD
, RTW_REG_DOMAIN_MAC32
},
4301 {0x522, MASKBYTE0
, RTW_REG_DOMAIN_MAC8
},
4302 {0x953, BIT(1), RTW_REG_DOMAIN_MAC8
},
4303 {0xc50, MASKBYTE0
, RTW_REG_DOMAIN_MAC8
},
4306 struct rtw_chip_info rtw8822c_hw_spec
= {
4307 .ops
= &rtw8822c_ops
,
4308 .id
= RTW_CHIP_TYPE_8822C
,
4309 .fw_name
= "rtw88/rtw8822c_fw.bin",
4310 .wlan_cpu
= RTW_WCPU_11AC
,
4311 .tx_pkt_desc_sz
= 48,
4312 .tx_buf_desc_sz
= 16,
4313 .rx_pkt_desc_sz
= 24,
4314 .rx_buf_desc_sz
= 8,
4315 .phy_efuse_size
= 512,
4316 .log_efuse_size
= 768,
4317 .ptct_efuse_size
= 124,
4318 .txff_size
= 262144,
4320 .fw_rxff_size
= 12288,
4322 .is_pwr_by_rate_dec
= false,
4323 .max_power_index
= 0x7f,
4324 .csi_buf_pg_num
= 50,
4325 .band
= RTW_BAND_2G
| RTW_BAND_5G
,
4328 .ht_supported
= true,
4329 .vht_supported
= true,
4330 .lps_deep_mode_supported
= BIT(LPS_DEEP_MODE_LCLK
) | BIT(LPS_DEEP_MODE_PG
),
4331 .sys_func_en
= 0xD8,
4332 .pwr_on_seq
= card_enable_flow_8822c
,
4333 .pwr_off_seq
= card_disable_flow_8822c
,
4334 .page_table
= page_table_8822c
,
4335 .rqpn_table
= rqpn_table_8822c
,
4336 .prioq_addrs
= &prioq_addrs_8822c
,
4337 .intf_table
= &phy_para_table_8822c
,
4338 .dig
= rtw8822c_dig
,
4340 .rf_base_addr
= {0x3c00, 0x4c00},
4341 .rf_sipi_addr
= {0x1808, 0x4108},
4342 .ltecoex_addr
= &rtw8822c_ltecoex_addr
,
4343 .mac_tbl
= &rtw8822c_mac_tbl
,
4344 .agc_tbl
= &rtw8822c_agc_tbl
,
4345 .bb_tbl
= &rtw8822c_bb_tbl
,
4346 .rfk_init_tbl
= &rtw8822c_array_mp_cal_init_tbl
,
4347 .rf_tbl
= {&rtw8822c_rf_b_tbl
, &rtw8822c_rf_a_tbl
},
4348 .rfe_defs
= rtw8822c_rfe_defs
,
4349 .rfe_defs_size
= ARRAY_SIZE(rtw8822c_rfe_defs
),
4351 .dpd_ratemask
= DIS_DPD_RATEALL
,
4352 .pwr_track_tbl
= &rtw8822c_rtw_pwr_track_tbl
,
4354 .bfer_su_max_num
= 2,
4355 .bfer_mu_max_num
= 1,
4359 .wow_fw_name
= "rtw88/rtw8822c_wow_fw.bin",
4360 .wowlan_stub
= &rtw_wowlan_stub_8822c
,
4361 .max_sched_scan_ssids
= 4,
4363 .coex_para_ver
= 0x201029,
4364 .bt_desired_ver
= 0x1c,
4365 .scbd_support
= true,
4366 .new_scbd10_def
= true,
4367 .ble_hid_profile_support
= true,
4368 .pstdma_type
= COEX_PSTDMA_FORCE_LPSOFF
,
4369 .bt_rssi_type
= COEX_BTRSSI_DBM
,
4370 .ant_isolation
= 15,
4371 .rssi_tolerance
= 2,
4372 .wl_rssi_step
= wl_rssi_step_8822c
,
4373 .bt_rssi_step
= bt_rssi_step_8822c
,
4374 .table_sant_num
= ARRAY_SIZE(table_sant_8822c
),
4375 .table_sant
= table_sant_8822c
,
4376 .table_nsant_num
= ARRAY_SIZE(table_nsant_8822c
),
4377 .table_nsant
= table_nsant_8822c
,
4378 .tdma_sant_num
= ARRAY_SIZE(tdma_sant_8822c
),
4379 .tdma_sant
= tdma_sant_8822c
,
4380 .tdma_nsant_num
= ARRAY_SIZE(tdma_nsant_8822c
),
4381 .tdma_nsant
= tdma_nsant_8822c
,
4382 .wl_rf_para_num
= ARRAY_SIZE(rf_para_tx_8822c
),
4383 .wl_rf_para_tx
= rf_para_tx_8822c
,
4384 .wl_rf_para_rx
= rf_para_rx_8822c
,
4385 .bt_afh_span_bw20
= 0x24,
4386 .bt_afh_span_bw40
= 0x36,
4387 .afh_5g_num
= ARRAY_SIZE(afh_5g_8822c
),
4388 .afh_5g
= afh_5g_8822c
,
4390 .coex_info_hw_regs_num
= ARRAY_SIZE(coex_info_hw_regs_8822c
),
4391 .coex_info_hw_regs
= coex_info_hw_regs_8822c
,
4393 .fw_fifo_addr
= {0x780, 0x700, 0x780, 0x660, 0x650, 0x680},
4395 EXPORT_SYMBOL(rtw8822c_hw_spec
);
4397 MODULE_FIRMWARE("rtw88/rtw8822c_fw.bin");
4398 MODULE_FIRMWARE("rtw88/rtw8822c_wow_fw.bin");
4400 MODULE_AUTHOR("Realtek Corporation");
4401 MODULE_DESCRIPTION("Realtek 802.11ac wireless 8822c driver");
4402 MODULE_LICENSE("Dual BSD/GPL");