Lines Matching refs:rtwdev
18 static void rtw8822c_config_trx_mode(struct rtw_dev *rtwdev, u8 tx_path,
27 static int rtw8822c_read_efuse(struct rtw_dev *rtwdev, u8 *log_map) in rtw8822c_read_efuse() argument
29 struct rtw_efuse *efuse = &rtwdev->efuse; in rtw8822c_read_efuse()
47 switch (rtw_hci_type(rtwdev)) { in rtw8822c_read_efuse()
59 static void rtw8822c_header_file_init(struct rtw_dev *rtwdev, bool pre) in rtw8822c_header_file_init() argument
61 rtw_write32_set(rtwdev, REG_3WIRE, BIT_3WIRE_TX_EN | BIT_3WIRE_RX_EN); in rtw8822c_header_file_init()
62 rtw_write32_set(rtwdev, REG_3WIRE, BIT_3WIRE_PI_ON); in rtw8822c_header_file_init()
63 rtw_write32_set(rtwdev, REG_3WIRE2, BIT_3WIRE_TX_EN | BIT_3WIRE_RX_EN); in rtw8822c_header_file_init()
64 rtw_write32_set(rtwdev, REG_3WIRE2, BIT_3WIRE_PI_ON); in rtw8822c_header_file_init()
67 rtw_write32_clr(rtwdev, REG_ENCCK, BIT_CCK_OFDM_BLK_EN); in rtw8822c_header_file_init()
69 rtw_write32_set(rtwdev, REG_ENCCK, BIT_CCK_OFDM_BLK_EN); in rtw8822c_header_file_init()
72 static void rtw8822c_dac_backup_reg(struct rtw_dev *rtwdev, in rtw8822c_dac_backup_reg() argument
88 backup[i].val = rtw_read32(rtwdev, addrs[i]); in rtw8822c_dac_backup_reg()
94 val = rtw_read_rf(rtwdev, path, reg, RFREG_MASK); in rtw8822c_dac_backup_reg()
101 static void rtw8822c_dac_restore_reg(struct rtw_dev *rtwdev, in rtw8822c_dac_restore_reg() argument
109 rtw_restore_reg(rtwdev, backup, DACK_REG_8822C); in rtw8822c_dac_restore_reg()
115 rtw_write_rf(rtwdev, path, reg, RFREG_MASK, val); in rtw8822c_dac_restore_reg()
120 static void rtw8822c_rf_minmax_cmp(struct rtw_dev *rtwdev, u32 value, in rtw8822c_rf_minmax_cmp() argument
158 static void __rtw8822c_dac_iq_sort(struct rtw_dev *rtwdev, u32 *v1, u32 *v2) in __rtw8822c_dac_iq_sort() argument
171 static void rtw8822c_dac_iq_sort(struct rtw_dev *rtwdev, u32 *iv, u32 *qv) in rtw8822c_dac_iq_sort() argument
177 __rtw8822c_dac_iq_sort(rtwdev, &iv[j], &iv[j + 1]); in rtw8822c_dac_iq_sort()
178 __rtw8822c_dac_iq_sort(rtwdev, &qv[j], &qv[j + 1]); in rtw8822c_dac_iq_sort()
183 static void rtw8822c_dac_iq_offset(struct rtw_dev *rtwdev, u32 *vec, u32 *val) in rtw8822c_dac_iq_offset() argument
247 static bool rtw8822c_dac_iq_check(struct rtw_dev *rtwdev, u32 value) in rtw8822c_dac_iq_check() argument
254 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] Error overflow\n"); in rtw8822c_dac_iq_check()
260 static void rtw8822c_dac_cal_iq_sample(struct rtw_dev *rtwdev, u32 *iv, u32 *qv) in rtw8822c_dac_cal_iq_sample() argument
267 temp = rtw_read32_mask(rtwdev, 0x2dbc, 0x3fffff); in rtw8822c_dac_cal_iq_sample()
271 if (rtw8822c_dac_iq_check(rtwdev, iv[i]) && in rtw8822c_dac_cal_iq_sample()
272 rtw8822c_dac_iq_check(rtwdev, qv[i])) in rtw8822c_dac_cal_iq_sample()
277 static void rtw8822c_dac_cal_iq_search(struct rtw_dev *rtwdev, in rtw8822c_dac_cal_iq_search() argument
292 rtw8822c_rf_minmax_cmp(rtwdev, iv[i], &i_min, &i_max); in rtw8822c_dac_cal_iq_search()
293 rtw8822c_rf_minmax_cmp(rtwdev, qv[i], &q_min, &q_max); in rtw8822c_dac_cal_iq_search()
310 rtw_dbg(rtwdev, RTW_DBG_RFK, in rtw8822c_dac_cal_iq_search()
313 rtw_dbg(rtwdev, RTW_DBG_RFK, in rtw8822c_dac_cal_iq_search()
317 rtw8822c_dac_iq_sort(rtwdev, iv, qv); in rtw8822c_dac_cal_iq_search()
320 temp = rtw_read32_mask(rtwdev, 0x2dbc, 0x3fffff); in rtw8822c_dac_cal_iq_search()
323 temp = rtw_read32_mask(rtwdev, 0x2dbc, 0x3fffff); in rtw8822c_dac_cal_iq_search()
331 rtw8822c_dac_iq_offset(rtwdev, iv, i_value); in rtw8822c_dac_cal_iq_search()
332 rtw8822c_dac_iq_offset(rtwdev, qv, q_value); in rtw8822c_dac_cal_iq_search()
335 static void rtw8822c_dac_cal_rf_mode(struct rtw_dev *rtwdev, in rtw8822c_dac_cal_rf_mode() argument
341 rf_a = rtw_read_rf(rtwdev, RF_PATH_A, 0x0, RFREG_MASK); in rtw8822c_dac_cal_rf_mode()
342 rf_b = rtw_read_rf(rtwdev, RF_PATH_B, 0x0, RFREG_MASK); in rtw8822c_dac_cal_rf_mode()
344 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] RF path-A=0x%05x\n", rf_a); in rtw8822c_dac_cal_rf_mode()
345 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] RF path-B=0x%05x\n", rf_b); in rtw8822c_dac_cal_rf_mode()
347 rtw8822c_dac_cal_iq_sample(rtwdev, iv, qv); in rtw8822c_dac_cal_rf_mode()
348 rtw8822c_dac_cal_iq_search(rtwdev, iv, qv, i_value, q_value); in rtw8822c_dac_cal_rf_mode()
351 static void rtw8822c_dac_bb_setting(struct rtw_dev *rtwdev) in rtw8822c_dac_bb_setting() argument
353 rtw_write32_mask(rtwdev, 0x1d58, 0xff8, 0x1ff); in rtw8822c_dac_bb_setting()
354 rtw_write32_mask(rtwdev, 0x1a00, 0x3, 0x2); in rtw8822c_dac_bb_setting()
355 rtw_write32_mask(rtwdev, 0x1a14, 0x300, 0x3); in rtw8822c_dac_bb_setting()
356 rtw_write32(rtwdev, 0x1d70, 0x7e7e7e7e); in rtw8822c_dac_bb_setting()
357 rtw_write32_mask(rtwdev, 0x180c, 0x3, 0x0); in rtw8822c_dac_bb_setting()
358 rtw_write32_mask(rtwdev, 0x410c, 0x3, 0x0); in rtw8822c_dac_bb_setting()
359 rtw_write32(rtwdev, 0x1b00, 0x00000008); in rtw8822c_dac_bb_setting()
360 rtw_write8(rtwdev, 0x1bcc, 0x3f); in rtw8822c_dac_bb_setting()
361 rtw_write32(rtwdev, 0x1b00, 0x0000000a); in rtw8822c_dac_bb_setting()
362 rtw_write8(rtwdev, 0x1bcc, 0x3f); in rtw8822c_dac_bb_setting()
363 rtw_write32_mask(rtwdev, 0x1e24, BIT(31), 0x0); in rtw8822c_dac_bb_setting()
364 rtw_write32_mask(rtwdev, 0x1e28, 0xf, 0x3); in rtw8822c_dac_bb_setting()
367 static void rtw8822c_dac_cal_adc(struct rtw_dev *rtwdev, in rtw8822c_dac_cal_adc() argument
370 struct rtw_dm_info *dm_info = &rtwdev->dm_info; in rtw8822c_dac_cal_adc()
376 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] ADCK path(%d)\n", path); in rtw8822c_dac_cal_adc()
392 rtw_write32_mask(rtwdev, base_addr + 0x30, BIT(30), 0x0); in rtw8822c_dac_cal_adc()
394 rtw_write32(rtwdev, base_addr + 0x30, 0x30db8041); in rtw8822c_dac_cal_adc()
395 rtw_write32(rtwdev, base_addr + 0x60, 0xf0040ff0); in rtw8822c_dac_cal_adc()
396 rtw_write32(rtwdev, base_addr + 0x0c, 0xdff00220); in rtw8822c_dac_cal_adc()
397 rtw_write32(rtwdev, base_addr + 0x10, 0x02dd08c4); in rtw8822c_dac_cal_adc()
398 rtw_write32(rtwdev, base_addr + 0x0c, 0x10000260); in rtw8822c_dac_cal_adc()
399 rtw_write_rf(rtwdev, RF_PATH_A, 0x0, RFREG_MASK, 0x10000); in rtw8822c_dac_cal_adc()
400 rtw_write_rf(rtwdev, RF_PATH_B, 0x0, RFREG_MASK, 0x10000); in rtw8822c_dac_cal_adc()
402 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] ADCK count=%d\n", i); in rtw8822c_dac_cal_adc()
403 rtw_write32(rtwdev, 0x1c3c, path_sel + 0x8003); in rtw8822c_dac_cal_adc()
404 rtw_write32(rtwdev, 0x1c24, 0x00010002); in rtw8822c_dac_cal_adc()
405 rtw8822c_dac_cal_rf_mode(rtwdev, &ic, &qc); in rtw8822c_dac_cal_adc()
406 rtw_dbg(rtwdev, RTW_DBG_RFK, in rtw8822c_dac_cal_adc()
419 rtw_write32(rtwdev, base_addr + 0x68, temp); in rtw8822c_dac_cal_adc()
421 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] ADCK 0x%08x=0x08%x\n", in rtw8822c_dac_cal_adc()
424 rtw_write32(rtwdev, 0x1c3c, path_sel + 0x8103); in rtw8822c_dac_cal_adc()
425 rtw8822c_dac_cal_rf_mode(rtwdev, &ic, &qc); in rtw8822c_dac_cal_adc()
426 rtw_dbg(rtwdev, RTW_DBG_RFK, in rtw8822c_dac_cal_adc()
437 rtw_write32(rtwdev, 0x1c3c, 0x00000003); in rtw8822c_dac_cal_adc()
438 rtw_write32(rtwdev, base_addr + 0x0c, 0x10000260); in rtw8822c_dac_cal_adc()
439 rtw_write32(rtwdev, base_addr + 0x10, 0x02d508c4); in rtw8822c_dac_cal_adc()
442 rtw_write_rf(rtwdev, path, 0x8f, BIT(13), 0x1); in rtw8822c_dac_cal_adc()
445 static void rtw8822c_dac_cal_step1(struct rtw_dev *rtwdev, u8 path) in rtw8822c_dac_cal_step1() argument
447 struct rtw_dm_info *dm_info = &rtwdev->dm_info; in rtw8822c_dac_cal_step1()
454 rtw_write32(rtwdev, base_addr + 0x68, dm_info->dack_adck[path]); in rtw8822c_dac_cal_step1()
455 rtw_write32(rtwdev, base_addr + 0x0c, 0xdff00220); in rtw8822c_dac_cal_step1()
457 rtw_write32(rtwdev, base_addr + 0x60, 0xf0040ff0); in rtw8822c_dac_cal_step1()
458 rtw_write32(rtwdev, 0x1c38, 0xffffffff); in rtw8822c_dac_cal_step1()
460 rtw_write32(rtwdev, base_addr + 0x10, 0x02d508c5); in rtw8822c_dac_cal_step1()
461 rtw_write32(rtwdev, 0x9b4, 0xdb66db00); in rtw8822c_dac_cal_step1()
462 rtw_write32(rtwdev, base_addr + 0xb0, 0x0a11fb88); in rtw8822c_dac_cal_step1()
463 rtw_write32(rtwdev, base_addr + 0xbc, 0x0008ff81); in rtw8822c_dac_cal_step1()
464 rtw_write32(rtwdev, base_addr + 0xc0, 0x0003d208); in rtw8822c_dac_cal_step1()
465 rtw_write32(rtwdev, base_addr + 0xcc, 0x0a11fb88); in rtw8822c_dac_cal_step1()
466 rtw_write32(rtwdev, base_addr + 0xd8, 0x0008ff81); in rtw8822c_dac_cal_step1()
467 rtw_write32(rtwdev, base_addr + 0xdc, 0x0003d208); in rtw8822c_dac_cal_step1()
468 rtw_write32(rtwdev, base_addr + 0xb8, 0x60000000); in rtw8822c_dac_cal_step1()
470 rtw_write32(rtwdev, base_addr + 0xbc, 0x000aff8d); in rtw8822c_dac_cal_step1()
472 rtw_write32(rtwdev, base_addr + 0xb0, 0x0a11fb89); in rtw8822c_dac_cal_step1()
473 rtw_write32(rtwdev, base_addr + 0xcc, 0x0a11fb89); in rtw8822c_dac_cal_step1()
475 rtw_write32(rtwdev, base_addr + 0xb8, 0x62000000); in rtw8822c_dac_cal_step1()
476 rtw_write32(rtwdev, base_addr + 0xd4, 0x62000000); in rtw8822c_dac_cal_step1()
478 if (!check_hw_ready(rtwdev, read_addr + 0x08, 0x7fff80, 0xffff) || in rtw8822c_dac_cal_step1()
479 !check_hw_ready(rtwdev, read_addr + 0x34, 0x7fff80, 0xffff)) in rtw8822c_dac_cal_step1()
480 rtw_err(rtwdev, "failed to wait for dack ready\n"); in rtw8822c_dac_cal_step1()
481 rtw_write32(rtwdev, base_addr + 0xb8, 0x02000000); in rtw8822c_dac_cal_step1()
483 rtw_write32(rtwdev, base_addr + 0xbc, 0x0008ff87); in rtw8822c_dac_cal_step1()
484 rtw_write32(rtwdev, 0x9b4, 0xdb6db600); in rtw8822c_dac_cal_step1()
485 rtw_write32(rtwdev, base_addr + 0x10, 0x02d508c5); in rtw8822c_dac_cal_step1()
486 rtw_write32(rtwdev, base_addr + 0xbc, 0x0008ff87); in rtw8822c_dac_cal_step1()
487 rtw_write32(rtwdev, base_addr + 0x60, 0xf0000000); in rtw8822c_dac_cal_step1()
490 static void rtw8822c_dac_cal_step2(struct rtw_dev *rtwdev, in rtw8822c_dac_cal_step2() argument
497 rtw_write32_mask(rtwdev, base_addr + 0xbc, 0xf0000000, 0x0); in rtw8822c_dac_cal_step2()
498 rtw_write32_mask(rtwdev, base_addr + 0xc0, 0xf, 0x8); in rtw8822c_dac_cal_step2()
499 rtw_write32_mask(rtwdev, base_addr + 0xd8, 0xf0000000, 0x0); in rtw8822c_dac_cal_step2()
500 rtw_write32_mask(rtwdev, base_addr + 0xdc, 0xf, 0x8); in rtw8822c_dac_cal_step2()
502 rtw_write32(rtwdev, 0x1b00, 0x00000008); in rtw8822c_dac_cal_step2()
503 rtw_write8(rtwdev, 0x1bcc, 0x03f); in rtw8822c_dac_cal_step2()
504 rtw_write32(rtwdev, base_addr + 0x0c, 0xdff00220); in rtw8822c_dac_cal_step2()
505 rtw_write32(rtwdev, base_addr + 0x10, 0x02d508c5); in rtw8822c_dac_cal_step2()
506 rtw_write32(rtwdev, 0x1c3c, 0x00088103); in rtw8822c_dac_cal_step2()
508 rtw8822c_dac_cal_rf_mode(rtwdev, &ic_in, &qc_in); in rtw8822c_dac_cal_step2()
535 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] before i=0x%x, q=0x%x\n", ic_in, qc_in); in rtw8822c_dac_cal_step2()
536 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] after i=0x%x, q=0x%x\n", ic, qc); in rtw8822c_dac_cal_step2()
539 static void rtw8822c_dac_cal_step3(struct rtw_dev *rtwdev, u8 path, in rtw8822c_dac_cal_step3() argument
554 rtw_write32(rtwdev, base_addr + 0x0c, 0xdff00220); in rtw8822c_dac_cal_step3()
555 rtw_write32(rtwdev, base_addr + 0x10, 0x02d508c5); in rtw8822c_dac_cal_step3()
556 rtw_write32(rtwdev, 0x9b4, 0xdb66db00); in rtw8822c_dac_cal_step3()
557 rtw_write32(rtwdev, base_addr + 0xb0, 0x0a11fb88); in rtw8822c_dac_cal_step3()
558 rtw_write32(rtwdev, base_addr + 0xbc, 0xc008ff81); in rtw8822c_dac_cal_step3()
559 rtw_write32(rtwdev, base_addr + 0xc0, 0x0003d208); in rtw8822c_dac_cal_step3()
560 rtw_write32_mask(rtwdev, base_addr + 0xbc, 0xf0000000, ic & 0xf); in rtw8822c_dac_cal_step3()
561 rtw_write32_mask(rtwdev, base_addr + 0xc0, 0xf, (ic & 0xf0) >> 4); in rtw8822c_dac_cal_step3()
562 rtw_write32(rtwdev, base_addr + 0xcc, 0x0a11fb88); in rtw8822c_dac_cal_step3()
563 rtw_write32(rtwdev, base_addr + 0xd8, 0xe008ff81); in rtw8822c_dac_cal_step3()
564 rtw_write32(rtwdev, base_addr + 0xdc, 0x0003d208); in rtw8822c_dac_cal_step3()
565 rtw_write32_mask(rtwdev, base_addr + 0xd8, 0xf0000000, qc & 0xf); in rtw8822c_dac_cal_step3()
566 rtw_write32_mask(rtwdev, base_addr + 0xdc, 0xf, (qc & 0xf0) >> 4); in rtw8822c_dac_cal_step3()
567 rtw_write32(rtwdev, base_addr + 0xb8, 0x60000000); in rtw8822c_dac_cal_step3()
569 rtw_write32_mask(rtwdev, base_addr + 0xbc, 0xe, 0x6); in rtw8822c_dac_cal_step3()
571 rtw_write32(rtwdev, base_addr + 0xb0, 0x0a11fb89); in rtw8822c_dac_cal_step3()
572 rtw_write32(rtwdev, base_addr + 0xcc, 0x0a11fb89); in rtw8822c_dac_cal_step3()
574 rtw_write32(rtwdev, base_addr + 0xb8, 0x62000000); in rtw8822c_dac_cal_step3()
575 rtw_write32(rtwdev, base_addr + 0xd4, 0x62000000); in rtw8822c_dac_cal_step3()
577 if (!check_hw_ready(rtwdev, read_addr + 0x24, 0x07f80000, ic) || in rtw8822c_dac_cal_step3()
578 !check_hw_ready(rtwdev, read_addr + 0x50, 0x07f80000, qc)) in rtw8822c_dac_cal_step3()
579 rtw_err(rtwdev, "failed to write IQ vector to hardware\n"); in rtw8822c_dac_cal_step3()
580 rtw_write32(rtwdev, base_addr + 0xb8, 0x02000000); in rtw8822c_dac_cal_step3()
582 rtw_write32_mask(rtwdev, base_addr + 0xbc, 0xe, 0x3); in rtw8822c_dac_cal_step3()
583 rtw_write32(rtwdev, 0x9b4, 0xdb6db600); in rtw8822c_dac_cal_step3()
587 rtw_write32(rtwdev, base_addr + 0x68, temp); in rtw8822c_dac_cal_step3()
588 rtw_write32(rtwdev, base_addr + 0x10, 0x02d508c5); in rtw8822c_dac_cal_step3()
589 rtw_write32(rtwdev, base_addr + 0x60, 0xf0000000); in rtw8822c_dac_cal_step3()
590 rtw8822c_dac_cal_rf_mode(rtwdev, &ic, &qc); in rtw8822c_dac_cal_step3()
612 rtw_dbg(rtwdev, RTW_DBG_RFK, in rtw8822c_dac_cal_step3()
616 static void rtw8822c_dac_cal_step4(struct rtw_dev *rtwdev, u8 path) in rtw8822c_dac_cal_step4() argument
620 rtw_write32(rtwdev, base_addr + 0x68, 0x0); in rtw8822c_dac_cal_step4()
621 rtw_write32(rtwdev, base_addr + 0x10, 0x02d508c4); in rtw8822c_dac_cal_step4()
622 rtw_write32_mask(rtwdev, base_addr + 0xbc, 0x1, 0x0); in rtw8822c_dac_cal_step4()
623 rtw_write32_mask(rtwdev, base_addr + 0x30, BIT(30), 0x1); in rtw8822c_dac_cal_step4()
626 static void rtw8822c_dac_cal_backup_vec(struct rtw_dev *rtwdev, in rtw8822c_dac_cal_backup_vec() argument
629 struct rtw_dm_info *dm_info = &rtwdev->dm_info; in rtw8822c_dac_cal_backup_vec()
637 rtw_write32_mask(rtwdev, w_addr, 0xf0000000, i); in rtw8822c_dac_cal_backup_vec()
638 val = (u16)rtw_read32_mask(rtwdev, r_addr, 0x7fc0000); in rtw8822c_dac_cal_backup_vec()
643 static void rtw8822c_dac_cal_backup_path(struct rtw_dev *rtwdev, u8 path) in rtw8822c_dac_cal_backup_path() argument
655 rtw8822c_dac_cal_backup_vec(rtwdev, path, 0, w_addr, r_addr); in rtw8822c_dac_cal_backup_path()
660 rtw8822c_dac_cal_backup_vec(rtwdev, path, 1, w_addr, r_addr); in rtw8822c_dac_cal_backup_path()
663 static void rtw8822c_dac_cal_backup_dck(struct rtw_dev *rtwdev) in rtw8822c_dac_cal_backup_dck() argument
665 struct rtw_dm_info *dm_info = &rtwdev->dm_info; in rtw8822c_dac_cal_backup_dck()
668 val = (u8)rtw_read32_mask(rtwdev, REG_DCKA_I_0, 0xf0000000); in rtw8822c_dac_cal_backup_dck()
670 val = (u8)rtw_read32_mask(rtwdev, REG_DCKA_I_1, 0xf); in rtw8822c_dac_cal_backup_dck()
672 val = (u8)rtw_read32_mask(rtwdev, REG_DCKA_Q_0, 0xf0000000); in rtw8822c_dac_cal_backup_dck()
674 val = (u8)rtw_read32_mask(rtwdev, REG_DCKA_Q_1, 0xf); in rtw8822c_dac_cal_backup_dck()
677 val = (u8)rtw_read32_mask(rtwdev, REG_DCKB_I_0, 0xf0000000); in rtw8822c_dac_cal_backup_dck()
679 val = (u8)rtw_read32_mask(rtwdev, REG_DCKB_I_1, 0xf); in rtw8822c_dac_cal_backup_dck()
681 val = (u8)rtw_read32_mask(rtwdev, REG_DCKB_Q_0, 0xf0000000); in rtw8822c_dac_cal_backup_dck()
683 val = (u8)rtw_read32_mask(rtwdev, REG_DCKB_Q_1, 0xf); in rtw8822c_dac_cal_backup_dck()
687 static void rtw8822c_dac_cal_backup(struct rtw_dev *rtwdev) in rtw8822c_dac_cal_backup() argument
691 temp[0] = rtw_read32(rtwdev, 0x1860); in rtw8822c_dac_cal_backup()
692 temp[1] = rtw_read32(rtwdev, 0x4160); in rtw8822c_dac_cal_backup()
693 temp[2] = rtw_read32(rtwdev, 0x9b4); in rtw8822c_dac_cal_backup()
696 rtw_write32(rtwdev, 0x9b4, 0xdb66db00); in rtw8822c_dac_cal_backup()
699 rtw_write32_clr(rtwdev, 0x1830, BIT(30)); in rtw8822c_dac_cal_backup()
700 rtw_write32_mask(rtwdev, 0x1860, 0xfc000000, 0x3c); in rtw8822c_dac_cal_backup()
701 rtw8822c_dac_cal_backup_path(rtwdev, RF_PATH_A); in rtw8822c_dac_cal_backup()
704 rtw_write32_clr(rtwdev, 0x4130, BIT(30)); in rtw8822c_dac_cal_backup()
705 rtw_write32_mask(rtwdev, 0x4160, 0xfc000000, 0x3c); in rtw8822c_dac_cal_backup()
706 rtw8822c_dac_cal_backup_path(rtwdev, RF_PATH_B); in rtw8822c_dac_cal_backup()
708 rtw8822c_dac_cal_backup_dck(rtwdev); in rtw8822c_dac_cal_backup()
709 rtw_write32_set(rtwdev, 0x1830, BIT(30)); in rtw8822c_dac_cal_backup()
710 rtw_write32_set(rtwdev, 0x4130, BIT(30)); in rtw8822c_dac_cal_backup()
712 rtw_write32(rtwdev, 0x1860, temp[0]); in rtw8822c_dac_cal_backup()
713 rtw_write32(rtwdev, 0x4160, temp[1]); in rtw8822c_dac_cal_backup()
714 rtw_write32(rtwdev, 0x9b4, temp[2]); in rtw8822c_dac_cal_backup()
717 static void rtw8822c_dac_cal_restore_dck(struct rtw_dev *rtwdev) in rtw8822c_dac_cal_restore_dck() argument
719 struct rtw_dm_info *dm_info = &rtwdev->dm_info; in rtw8822c_dac_cal_restore_dck()
722 rtw_write32_set(rtwdev, REG_DCKA_I_0, BIT(19)); in rtw8822c_dac_cal_restore_dck()
724 rtw_write32_mask(rtwdev, REG_DCKA_I_0, 0xf0000000, val); in rtw8822c_dac_cal_restore_dck()
726 rtw_write32_mask(rtwdev, REG_DCKA_I_1, 0xf, val); in rtw8822c_dac_cal_restore_dck()
728 rtw_write32_set(rtwdev, REG_DCKA_Q_0, BIT(19)); in rtw8822c_dac_cal_restore_dck()
730 rtw_write32_mask(rtwdev, REG_DCKA_Q_0, 0xf0000000, val); in rtw8822c_dac_cal_restore_dck()
732 rtw_write32_mask(rtwdev, REG_DCKA_Q_1, 0xf, val); in rtw8822c_dac_cal_restore_dck()
734 rtw_write32_set(rtwdev, REG_DCKB_I_0, BIT(19)); in rtw8822c_dac_cal_restore_dck()
736 rtw_write32_mask(rtwdev, REG_DCKB_I_0, 0xf0000000, val); in rtw8822c_dac_cal_restore_dck()
738 rtw_write32_mask(rtwdev, REG_DCKB_I_1, 0xf, val); in rtw8822c_dac_cal_restore_dck()
740 rtw_write32_set(rtwdev, REG_DCKB_Q_0, BIT(19)); in rtw8822c_dac_cal_restore_dck()
742 rtw_write32_mask(rtwdev, REG_DCKB_Q_0, 0xf0000000, val); in rtw8822c_dac_cal_restore_dck()
744 rtw_write32_mask(rtwdev, REG_DCKB_Q_1, 0xf, val); in rtw8822c_dac_cal_restore_dck()
747 static void rtw8822c_dac_cal_restore_prepare(struct rtw_dev *rtwdev) in rtw8822c_dac_cal_restore_prepare() argument
749 rtw_write32(rtwdev, 0x9b4, 0xdb66db00); in rtw8822c_dac_cal_restore_prepare()
751 rtw_write32_mask(rtwdev, 0x18b0, BIT(27), 0x0); in rtw8822c_dac_cal_restore_prepare()
752 rtw_write32_mask(rtwdev, 0x18cc, BIT(27), 0x0); in rtw8822c_dac_cal_restore_prepare()
753 rtw_write32_mask(rtwdev, 0x41b0, BIT(27), 0x0); in rtw8822c_dac_cal_restore_prepare()
754 rtw_write32_mask(rtwdev, 0x41cc, BIT(27), 0x0); in rtw8822c_dac_cal_restore_prepare()
756 rtw_write32_mask(rtwdev, 0x1830, BIT(30), 0x0); in rtw8822c_dac_cal_restore_prepare()
757 rtw_write32_mask(rtwdev, 0x1860, 0xfc000000, 0x3c); in rtw8822c_dac_cal_restore_prepare()
758 rtw_write32_mask(rtwdev, 0x18b4, BIT(0), 0x1); in rtw8822c_dac_cal_restore_prepare()
759 rtw_write32_mask(rtwdev, 0x18d0, BIT(0), 0x1); in rtw8822c_dac_cal_restore_prepare()
761 rtw_write32_mask(rtwdev, 0x4130, BIT(30), 0x0); in rtw8822c_dac_cal_restore_prepare()
762 rtw_write32_mask(rtwdev, 0x4160, 0xfc000000, 0x3c); in rtw8822c_dac_cal_restore_prepare()
763 rtw_write32_mask(rtwdev, 0x41b4, BIT(0), 0x1); in rtw8822c_dac_cal_restore_prepare()
764 rtw_write32_mask(rtwdev, 0x41d0, BIT(0), 0x1); in rtw8822c_dac_cal_restore_prepare()
766 rtw_write32_mask(rtwdev, 0x18b0, 0xf00, 0x0); in rtw8822c_dac_cal_restore_prepare()
767 rtw_write32_mask(rtwdev, 0x18c0, BIT(14), 0x0); in rtw8822c_dac_cal_restore_prepare()
768 rtw_write32_mask(rtwdev, 0x18cc, 0xf00, 0x0); in rtw8822c_dac_cal_restore_prepare()
769 rtw_write32_mask(rtwdev, 0x18dc, BIT(14), 0x0); in rtw8822c_dac_cal_restore_prepare()
771 rtw_write32_mask(rtwdev, 0x18b0, BIT(0), 0x0); in rtw8822c_dac_cal_restore_prepare()
772 rtw_write32_mask(rtwdev, 0x18cc, BIT(0), 0x0); in rtw8822c_dac_cal_restore_prepare()
773 rtw_write32_mask(rtwdev, 0x18b0, BIT(0), 0x1); in rtw8822c_dac_cal_restore_prepare()
774 rtw_write32_mask(rtwdev, 0x18cc, BIT(0), 0x1); in rtw8822c_dac_cal_restore_prepare()
776 rtw8822c_dac_cal_restore_dck(rtwdev); in rtw8822c_dac_cal_restore_prepare()
778 rtw_write32_mask(rtwdev, 0x18c0, 0x38000, 0x7); in rtw8822c_dac_cal_restore_prepare()
779 rtw_write32_mask(rtwdev, 0x18dc, 0x38000, 0x7); in rtw8822c_dac_cal_restore_prepare()
780 rtw_write32_mask(rtwdev, 0x41c0, 0x38000, 0x7); in rtw8822c_dac_cal_restore_prepare()
781 rtw_write32_mask(rtwdev, 0x41dc, 0x38000, 0x7); in rtw8822c_dac_cal_restore_prepare()
783 rtw_write32_mask(rtwdev, 0x18b8, BIT(26) | BIT(25), 0x1); in rtw8822c_dac_cal_restore_prepare()
784 rtw_write32_mask(rtwdev, 0x18d4, BIT(26) | BIT(25), 0x1); in rtw8822c_dac_cal_restore_prepare()
786 rtw_write32_mask(rtwdev, 0x41b0, 0xf00, 0x0); in rtw8822c_dac_cal_restore_prepare()
787 rtw_write32_mask(rtwdev, 0x41c0, BIT(14), 0x0); in rtw8822c_dac_cal_restore_prepare()
788 rtw_write32_mask(rtwdev, 0x41cc, 0xf00, 0x0); in rtw8822c_dac_cal_restore_prepare()
789 rtw_write32_mask(rtwdev, 0x41dc, BIT(14), 0x0); in rtw8822c_dac_cal_restore_prepare()
791 rtw_write32_mask(rtwdev, 0x41b0, BIT(0), 0x0); in rtw8822c_dac_cal_restore_prepare()
792 rtw_write32_mask(rtwdev, 0x41cc, BIT(0), 0x0); in rtw8822c_dac_cal_restore_prepare()
793 rtw_write32_mask(rtwdev, 0x41b0, BIT(0), 0x1); in rtw8822c_dac_cal_restore_prepare()
794 rtw_write32_mask(rtwdev, 0x41cc, BIT(0), 0x1); in rtw8822c_dac_cal_restore_prepare()
796 rtw_write32_mask(rtwdev, 0x41b8, BIT(26) | BIT(25), 0x1); in rtw8822c_dac_cal_restore_prepare()
797 rtw_write32_mask(rtwdev, 0x41d4, BIT(26) | BIT(25), 0x1); in rtw8822c_dac_cal_restore_prepare()
800 static bool rtw8822c_dac_cal_restore_wait(struct rtw_dev *rtwdev, in rtw8822c_dac_cal_restore_wait() argument
806 rtw_write32_mask(rtwdev, toggle_addr, BIT(26) | BIT(25), 0x0); in rtw8822c_dac_cal_restore_wait()
807 rtw_write32_mask(rtwdev, toggle_addr, BIT(26) | BIT(25), 0x2); in rtw8822c_dac_cal_restore_wait()
809 if (rtw_read32_mask(rtwdev, target_addr, 0xf) == 0x6) in rtw8822c_dac_cal_restore_wait()
817 static bool rtw8822c_dac_cal_restore_path(struct rtw_dev *rtwdev, u8 path) in rtw8822c_dac_cal_restore_path() argument
819 struct rtw_dm_info *dm_info = &rtwdev->dm_info; in rtw8822c_dac_cal_restore_path()
831 if (!rtw8822c_dac_cal_restore_wait(rtwdev, r_i, w_i + 0x8)) in rtw8822c_dac_cal_restore_path()
835 rtw_write32_mask(rtwdev, w_i + 0x4, BIT(2), 0x0); in rtw8822c_dac_cal_restore_path()
837 rtw_write32_mask(rtwdev, w_i + 0x4, 0xff8, value); in rtw8822c_dac_cal_restore_path()
838 rtw_write32_mask(rtwdev, w_i, 0xf0000000, i); in rtw8822c_dac_cal_restore_path()
839 rtw_write32_mask(rtwdev, w_i + 0x4, BIT(2), 0x1); in rtw8822c_dac_cal_restore_path()
842 rtw_write32_mask(rtwdev, w_i + 0x4, BIT(2), 0x0); in rtw8822c_dac_cal_restore_path()
844 if (!rtw8822c_dac_cal_restore_wait(rtwdev, r_q, w_q + 0x8)) in rtw8822c_dac_cal_restore_path()
848 rtw_write32_mask(rtwdev, w_q + 0x4, BIT(2), 0x0); in rtw8822c_dac_cal_restore_path()
850 rtw_write32_mask(rtwdev, w_q + 0x4, 0xff8, value); in rtw8822c_dac_cal_restore_path()
851 rtw_write32_mask(rtwdev, w_q, 0xf0000000, i); in rtw8822c_dac_cal_restore_path()
852 rtw_write32_mask(rtwdev, w_q + 0x4, BIT(2), 0x1); in rtw8822c_dac_cal_restore_path()
854 rtw_write32_mask(rtwdev, w_q + 0x4, BIT(2), 0x0); in rtw8822c_dac_cal_restore_path()
856 rtw_write32_mask(rtwdev, w_i + 0x8, BIT(26) | BIT(25), 0x0); in rtw8822c_dac_cal_restore_path()
857 rtw_write32_mask(rtwdev, w_q + 0x8, BIT(26) | BIT(25), 0x0); in rtw8822c_dac_cal_restore_path()
858 rtw_write32_mask(rtwdev, w_i + 0x4, BIT(0), 0x0); in rtw8822c_dac_cal_restore_path()
859 rtw_write32_mask(rtwdev, w_q + 0x4, BIT(0), 0x0); in rtw8822c_dac_cal_restore_path()
864 static bool __rtw8822c_dac_cal_restore(struct rtw_dev *rtwdev) in __rtw8822c_dac_cal_restore() argument
866 if (!rtw8822c_dac_cal_restore_path(rtwdev, RF_PATH_A)) in __rtw8822c_dac_cal_restore()
869 if (!rtw8822c_dac_cal_restore_path(rtwdev, RF_PATH_B)) in __rtw8822c_dac_cal_restore()
875 static bool rtw8822c_dac_cal_restore(struct rtw_dev *rtwdev) in rtw8822c_dac_cal_restore() argument
877 struct rtw_dm_info *dm_info = &rtwdev->dm_info; in rtw8822c_dac_cal_restore()
887 temp[0] = rtw_read32(rtwdev, 0x1860); in rtw8822c_dac_cal_restore()
888 temp[1] = rtw_read32(rtwdev, 0x4160); in rtw8822c_dac_cal_restore()
889 temp[2] = rtw_read32(rtwdev, 0x9b4); in rtw8822c_dac_cal_restore()
891 rtw8822c_dac_cal_restore_prepare(rtwdev); in rtw8822c_dac_cal_restore()
892 if (!check_hw_ready(rtwdev, 0x2808, 0x7fff80, 0xffff) || in rtw8822c_dac_cal_restore()
893 !check_hw_ready(rtwdev, 0x2834, 0x7fff80, 0xffff) || in rtw8822c_dac_cal_restore()
894 !check_hw_ready(rtwdev, 0x4508, 0x7fff80, 0xffff) || in rtw8822c_dac_cal_restore()
895 !check_hw_ready(rtwdev, 0x4534, 0x7fff80, 0xffff)) in rtw8822c_dac_cal_restore()
898 if (!__rtw8822c_dac_cal_restore(rtwdev)) { in rtw8822c_dac_cal_restore()
899 rtw_err(rtwdev, "failed to restore dack vectors\n"); in rtw8822c_dac_cal_restore()
903 rtw_write32_mask(rtwdev, 0x1830, BIT(30), 0x1); in rtw8822c_dac_cal_restore()
904 rtw_write32_mask(rtwdev, 0x4130, BIT(30), 0x1); in rtw8822c_dac_cal_restore()
905 rtw_write32(rtwdev, 0x1860, temp[0]); in rtw8822c_dac_cal_restore()
906 rtw_write32(rtwdev, 0x4160, temp[1]); in rtw8822c_dac_cal_restore()
907 rtw_write32_mask(rtwdev, 0x18b0, BIT(27), 0x1); in rtw8822c_dac_cal_restore()
908 rtw_write32_mask(rtwdev, 0x18cc, BIT(27), 0x1); in rtw8822c_dac_cal_restore()
909 rtw_write32_mask(rtwdev, 0x41b0, BIT(27), 0x1); in rtw8822c_dac_cal_restore()
910 rtw_write32_mask(rtwdev, 0x41cc, BIT(27), 0x1); in rtw8822c_dac_cal_restore()
911 rtw_write32(rtwdev, 0x9b4, temp[2]); in rtw8822c_dac_cal_restore()
916 static void rtw8822c_rf_dac_cal(struct rtw_dev *rtwdev) in rtw8822c_rf_dac_cal() argument
925 if (rtw8822c_dac_cal_restore(rtwdev)) in rtw8822c_rf_dac_cal()
930 rtw8822c_dac_backup_reg(rtwdev, backup, backup_rf); in rtw8822c_rf_dac_cal()
932 rtw8822c_dac_bb_setting(rtwdev); in rtw8822c_rf_dac_cal()
935 rtw8822c_dac_cal_adc(rtwdev, RF_PATH_A, &adc_ic_a, &adc_qc_a); in rtw8822c_rf_dac_cal()
937 rtw8822c_dac_cal_step1(rtwdev, RF_PATH_A); in rtw8822c_rf_dac_cal()
938 rtw8822c_dac_cal_step2(rtwdev, RF_PATH_A, &ic, &qc); in rtw8822c_rf_dac_cal()
942 rtw8822c_dac_cal_step3(rtwdev, RF_PATH_A, adc_ic_a, adc_qc_a, in rtw8822c_rf_dac_cal()
948 rtw8822c_dac_cal_step4(rtwdev, RF_PATH_A); in rtw8822c_rf_dac_cal()
951 rtw8822c_dac_cal_adc(rtwdev, RF_PATH_B, &adc_ic_b, &adc_qc_b); in rtw8822c_rf_dac_cal()
953 rtw8822c_dac_cal_step1(rtwdev, RF_PATH_B); in rtw8822c_rf_dac_cal()
954 rtw8822c_dac_cal_step2(rtwdev, RF_PATH_B, &ic, &qc); in rtw8822c_rf_dac_cal()
958 rtw8822c_dac_cal_step3(rtwdev, RF_PATH_B, adc_ic_b, adc_qc_b, in rtw8822c_rf_dac_cal()
964 rtw8822c_dac_cal_step4(rtwdev, RF_PATH_B); in rtw8822c_rf_dac_cal()
966 rtw_write32(rtwdev, 0x1b00, 0x00000008); in rtw8822c_rf_dac_cal()
967 rtw_write32_mask(rtwdev, 0x4130, BIT(30), 0x1); in rtw8822c_rf_dac_cal()
968 rtw_write8(rtwdev, 0x1bcc, 0x0); in rtw8822c_rf_dac_cal()
969 rtw_write32(rtwdev, 0x1b00, 0x0000000a); in rtw8822c_rf_dac_cal()
970 rtw_write8(rtwdev, 0x1bcc, 0x0); in rtw8822c_rf_dac_cal()
972 rtw8822c_dac_restore_reg(rtwdev, backup, backup_rf); in rtw8822c_rf_dac_cal()
975 rtw8822c_dac_cal_backup(rtwdev); in rtw8822c_rf_dac_cal()
977 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] path A: ic=0x%x, qc=0x%x\n", ic_a, qc_a); in rtw8822c_rf_dac_cal()
978 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] path B: ic=0x%x, qc=0x%x\n", ic_b, qc_b); in rtw8822c_rf_dac_cal()
979 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] path A: i=0x%x, q=0x%x\n", i_a, q_a); in rtw8822c_rf_dac_cal()
980 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] path B: i=0x%x, q=0x%x\n", i_b, q_b); in rtw8822c_rf_dac_cal()
983 static void rtw8822c_rf_x2_check(struct rtw_dev *rtwdev) in rtw8822c_rf_x2_check() argument
988 x2k_busy = rtw_read_rf(rtwdev, RF_PATH_A, 0xb8, BIT(15)); in rtw8822c_rf_x2_check()
990 rtw_write_rf(rtwdev, RF_PATH_A, 0xb8, RFREG_MASK, 0xC4440); in rtw8822c_rf_x2_check()
991 rtw_write_rf(rtwdev, RF_PATH_A, 0xba, RFREG_MASK, 0x6840D); in rtw8822c_rf_x2_check()
992 rtw_write_rf(rtwdev, RF_PATH_A, 0xb8, RFREG_MASK, 0x80440); in rtw8822c_rf_x2_check()
997 static void rtw8822c_rf_init(struct rtw_dev *rtwdev) in rtw8822c_rf_init() argument
999 rtw8822c_rf_dac_cal(rtwdev); in rtw8822c_rf_init()
1000 rtw8822c_rf_x2_check(rtwdev); in rtw8822c_rf_init()
1003 static void rtw8822c_phy_set_param(struct rtw_dev *rtwdev) in rtw8822c_phy_set_param() argument
1005 struct rtw_dm_info *dm_info = &rtwdev->dm_info; in rtw8822c_phy_set_param()
1006 struct rtw_hal *hal = &rtwdev->hal; in rtw8822c_phy_set_param()
1015 rtw_write8_set(rtwdev, REG_SYS_FUNC_EN, in rtw8822c_phy_set_param()
1017 rtw_write8_set(rtwdev, REG_RF_CTRL, in rtw8822c_phy_set_param()
1019 rtw_write32_set(rtwdev, REG_WLRF1, BIT_WLRF1_BBRF_EN); in rtw8822c_phy_set_param()
1022 rtw_write32_mask(rtwdev, REG_DIS_DPD, DIS_DPD_MASK, DIS_DPD_RATEALL); in rtw8822c_phy_set_param()
1025 rtw8822c_header_file_init(rtwdev, true); in rtw8822c_phy_set_param()
1027 rtw_phy_load_tables(rtwdev); in rtw8822c_phy_set_param()
1029 crystal_cap = rtwdev->efuse.crystal_cap & 0x7f; in rtw8822c_phy_set_param()
1030 rtw_write32_mask(rtwdev, REG_ANAPAR_XTAL_0, 0xfffc00, in rtw8822c_phy_set_param()
1034 rtw8822c_header_file_init(rtwdev, false); in rtw8822c_phy_set_param()
1037 rtw8822c_config_trx_mode(rtwdev, hal->antenna_tx, hal->antenna_rx, in rtw8822c_phy_set_param()
1039 rtw_phy_init(rtwdev); in rtw8822c_phy_set_param()
1041 cck_gi_u_bnd_msb = (u8)rtw_read32_mask(rtwdev, 0x1a98, 0xc000); in rtw8822c_phy_set_param()
1042 cck_gi_u_bnd_lsb = (u8)rtw_read32_mask(rtwdev, 0x1aa8, 0xf0000); in rtw8822c_phy_set_param()
1043 cck_gi_l_bnd_msb = (u8)rtw_read32_mask(rtwdev, 0x1a98, 0xc0); in rtw8822c_phy_set_param()
1044 cck_gi_l_bnd_lsb = (u8)rtw_read32_mask(rtwdev, 0x1a70, 0x0f000000); in rtw8822c_phy_set_param()
1049 rtw8822c_rf_init(rtwdev); in rtw8822c_phy_set_param()
1140 static int rtw8822c_mac_init(struct rtw_dev *rtwdev) in rtw8822c_mac_init() argument
1148 value8 = rtw_read8(rtwdev, REG_FWHW_TXQ_CTRL); in rtw8822c_mac_init()
1150 rtw_write8(rtwdev, REG_FWHW_TXQ_CTRL, value8); in rtw8822c_mac_init()
1151 rtw_write8(rtwdev, REG_FWHW_TXQ_CTRL + 1, WLAN_TXQ_RPT_EN); in rtw8822c_mac_init()
1153 rtw_write16(rtwdev, REG_SPEC_SIFS, WLAN_SIFS_DUR_TUNE); in rtw8822c_mac_init()
1154 rtw_write32(rtwdev, REG_SIFS, WLAN_SIFS_CFG); in rtw8822c_mac_init()
1155 rtw_write16(rtwdev, REG_RESP_SIFS_CCK, in rtw8822c_mac_init()
1157 rtw_write16(rtwdev, REG_RESP_SIFS_OFDM, in rtw8822c_mac_init()
1160 rtw_write32(rtwdev, REG_DARFRC, WLAN_DATA_RATE_FB_CNT_1_4); in rtw8822c_mac_init()
1161 rtw_write32(rtwdev, REG_DARFRCH, WLAN_DATA_RATE_FB_CNT_5_8); in rtw8822c_mac_init()
1162 rtw_write32(rtwdev, REG_RARFRCH, WLAN_RTS_RATE_FB_CNT_5_8); in rtw8822c_mac_init()
1163 rtw_write32(rtwdev, REG_ARFR0, WLAN_DATA_RATE_FB_RATE0); in rtw8822c_mac_init()
1164 rtw_write32(rtwdev, REG_ARFRH0, WLAN_DATA_RATE_FB_RATE0_H); in rtw8822c_mac_init()
1165 rtw_write32(rtwdev, REG_ARFR1_V1, WLAN_RTS_RATE_FB_RATE1); in rtw8822c_mac_init()
1166 rtw_write32(rtwdev, REG_ARFRH1_V1, WLAN_RTS_RATE_FB_RATE1_H); in rtw8822c_mac_init()
1167 rtw_write32(rtwdev, REG_ARFR4, WLAN_RTS_RATE_FB_RATE4); in rtw8822c_mac_init()
1168 rtw_write32(rtwdev, REG_ARFRH4, WLAN_RTS_RATE_FB_RATE4_H); in rtw8822c_mac_init()
1169 rtw_write32(rtwdev, REG_ARFR5, WLAN_RTS_RATE_FB_RATE5); in rtw8822c_mac_init()
1170 rtw_write32(rtwdev, REG_ARFRH5, WLAN_RTS_RATE_FB_RATE5_H); in rtw8822c_mac_init()
1172 rtw_write8(rtwdev, REG_AMPDU_MAX_TIME_V1, WLAN_AMPDU_MAX_TIME); in rtw8822c_mac_init()
1173 rtw_write8_set(rtwdev, REG_TX_HANG_CTRL, BIT_EN_EOF_V1); in rtw8822c_mac_init()
1175 rtw_write8(rtwdev, REG_PRECNT_CTRL, (u8)(pre_txcnt & 0xFF)); in rtw8822c_mac_init()
1176 rtw_write8(rtwdev, REG_PRECNT_CTRL + 1, (u8)(pre_txcnt >> 8)); in rtw8822c_mac_init()
1180 rtw_write32(rtwdev, REG_PROT_MODE_CTRL, value32); in rtw8822c_mac_init()
1181 rtw_write16(rtwdev, REG_BAR_MODE_CTRL + 2, in rtw8822c_mac_init()
1183 rtw_write8(rtwdev, REG_FAST_EDCA_VOVI_SETTING, FAST_EDCA_VO_TH); in rtw8822c_mac_init()
1184 rtw_write8(rtwdev, REG_FAST_EDCA_VOVI_SETTING + 2, FAST_EDCA_VI_TH); in rtw8822c_mac_init()
1185 rtw_write8(rtwdev, REG_FAST_EDCA_BEBK_SETTING, FAST_EDCA_BE_TH); in rtw8822c_mac_init()
1186 rtw_write8(rtwdev, REG_FAST_EDCA_BEBK_SETTING + 2, FAST_EDCA_BK_TH); in rtw8822c_mac_init()
1188 rtw_write8_clr(rtwdev, REG_LIFETIME_EN, BIT_BA_PARSER_EN); in rtw8822c_mac_init()
1189 rtw_write32_clr(rtwdev, REG_RRSR, BITS_RRSR_RSC); in rtw8822c_mac_init()
1192 rtw_write32(rtwdev, REG_EDCA_VO_PARAM, WLAN_EDCA_VO_PARAM); in rtw8822c_mac_init()
1193 rtw_write32(rtwdev, REG_EDCA_VI_PARAM, WLAN_EDCA_VI_PARAM); in rtw8822c_mac_init()
1194 rtw_write32(rtwdev, REG_EDCA_BE_PARAM, WLAN_EDCA_BE_PARAM); in rtw8822c_mac_init()
1195 rtw_write32(rtwdev, REG_EDCA_BK_PARAM, WLAN_EDCA_BK_PARAM); in rtw8822c_mac_init()
1196 rtw_write8(rtwdev, REG_PIFS, WLAN_PIFS_TIME); in rtw8822c_mac_init()
1197 rtw_write8_clr(rtwdev, REG_TX_PTCL_CTRL + 1, BIT_SIFS_BK_EN >> 8); in rtw8822c_mac_init()
1198 rtw_write8_set(rtwdev, REG_RD_CTRL + 1, in rtw8822c_mac_init()
1203 rtw_write32_clr(rtwdev, REG_AFE_CTRL1, BIT_MAC_CLK_SEL); in rtw8822c_mac_init()
1204 rtw_write8(rtwdev, REG_USTIME_TSF, MAC_CLK_SPEED); in rtw8822c_mac_init()
1205 rtw_write8(rtwdev, REG_USTIME_EDCA, MAC_CLK_SPEED); in rtw8822c_mac_init()
1207 rtw_write8_set(rtwdev, REG_MISC_CTRL, in rtw8822c_mac_init()
1209 rtw_write8_clr(rtwdev, REG_TIMER0_SRC_SEL, BIT_TSFT_SEL_TIMER0); in rtw8822c_mac_init()
1210 rtw_write16(rtwdev, REG_TXPAUSE, 0x0000); in rtw8822c_mac_init()
1211 rtw_write8(rtwdev, REG_SLOT, WLAN_SLOT_TIME); in rtw8822c_mac_init()
1212 rtw_write32(rtwdev, REG_RD_NAV_NXT, WLAN_NAV_CFG); in rtw8822c_mac_init()
1213 rtw_write16(rtwdev, REG_RXTSF_OFFSET_CCK, WLAN_RX_TSF_CFG); in rtw8822c_mac_init()
1215 rtw_write8_set(rtwdev, REG_BCN_CTRL, BIT_EN_BCN_FUNCTION); in rtw8822c_mac_init()
1217 rtw_write32(rtwdev, REG_TBTT_PROHIBIT, WLAN_TBTT_TIME); in rtw8822c_mac_init()
1218 rtw_write8(rtwdev, REG_DRVERLYINT, WLAN_DRV_EARLY_INT); in rtw8822c_mac_init()
1219 rtw_write8(rtwdev, REG_BCN_CTRL_CLINT0, WLAN_BCN_CTRL_CLT0); in rtw8822c_mac_init()
1220 rtw_write8(rtwdev, REG_BCNDMATIM, WLAN_BCN_DMA_TIME); in rtw8822c_mac_init()
1221 rtw_write8(rtwdev, REG_BCN_MAX_ERR, WLAN_BCN_MAX_ERR); in rtw8822c_mac_init()
1224 rtw_write8(rtwdev, REG_BBPSF_CTRL + 2, WLAN_RESP_TXRATE); in rtw8822c_mac_init()
1225 rtw_write8(rtwdev, REG_ACKTO, WLAN_ACK_TO); in rtw8822c_mac_init()
1226 rtw_write8(rtwdev, REG_ACKTO_CCK, WLAN_ACK_TO_CCK); in rtw8822c_mac_init()
1227 rtw_write16(rtwdev, REG_EIFS, WLAN_EIFS_DUR_TUNE); in rtw8822c_mac_init()
1228 rtw_write8(rtwdev, REG_NAV_CTRL + 2, WLAN_NAV_MAX); in rtw8822c_mac_init()
1229 rtw_write8(rtwdev, REG_WMAC_TRXPTCL_CTL_H + 2, WLAN_BAR_ACK_TYPE); in rtw8822c_mac_init()
1230 rtw_write32(rtwdev, REG_RXFLTMAP0, WLAN_RX_FILTER0); in rtw8822c_mac_init()
1231 rtw_write16(rtwdev, REG_RXFLTMAP2, WLAN_RX_FILTER2); in rtw8822c_mac_init()
1232 rtw_write32(rtwdev, REG_RCR, WLAN_RCR_CFG); in rtw8822c_mac_init()
1233 rtw_write8(rtwdev, REG_RX_PKT_LIMIT, WLAN_RXPKT_MAX_SZ_512); in rtw8822c_mac_init()
1234 rtw_write8(rtwdev, REG_TCR + 2, WLAN_TX_FUNC_CFG2); in rtw8822c_mac_init()
1235 rtw_write8(rtwdev, REG_TCR + 1, WLAN_TX_FUNC_CFG1); in rtw8822c_mac_init()
1236 rtw_write32_set(rtwdev, REG_GENERAL_OPTION, BIT_DUMMY_FCS_READY_MASK_EN); in rtw8822c_mac_init()
1237 rtw_write32(rtwdev, REG_WMAC_OPTION_FUNCTION + 8, WLAN_MAC_OPT_FUNC2); in rtw8822c_mac_init()
1238 rtw_write8(rtwdev, REG_WMAC_OPTION_FUNCTION_1, WLAN_MAC_OPT_NORM_FUNC1); in rtw8822c_mac_init()
1241 value16 = rtw_read16(rtwdev, REG_RXPSF_CTRL + 2) & 0xF00F; in rtw8822c_mac_init()
1244 rtw_write16(rtwdev, REG_RXPSF_CTRL + 2, value16); in rtw8822c_mac_init()
1250 rtw_write16(rtwdev, REG_RXPSF_CTRL, value16); in rtw8822c_mac_init()
1251 rtw_write32(rtwdev, REG_RXPSF_TYPE_CTRL, 0xFFFFFFFF); in rtw8822c_mac_init()
1253 value16 = rtw_read16(rtwdev, REG_RXPSF_CTRL); in rtw8822c_mac_init()
1257 rtw_write16(rtwdev, REG_RXPSF_CTRL, value16); in rtw8822c_mac_init()
1260 rtw_write32(rtwdev, REG_INT_MIG, WLAN_MAC_INT_MIG_CFG); in rtw8822c_mac_init()
1265 static void rtw8822c_set_channel_rf(struct rtw_dev *rtwdev, u8 channel, u8 bw) in rtw8822c_set_channel_rf() argument
1282 rf_reg18 = rtw_read_rf(rtwdev, RF_PATH_A, 0x18, RFREG_MASK); in rtw8822c_set_channel_rf()
1313 rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWE2, 0x04, 0x01); in rtw8822c_set_channel_rf()
1314 rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWA, 0x1f, 0x12); in rtw8822c_set_channel_rf()
1315 rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWD0, 0xfffff, rf_rxbb); in rtw8822c_set_channel_rf()
1316 rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWE2, 0x04, 0x00); in rtw8822c_set_channel_rf()
1318 rtw_write_rf(rtwdev, RF_PATH_B, RF_LUTWE2, 0x04, 0x01); in rtw8822c_set_channel_rf()
1319 rtw_write_rf(rtwdev, RF_PATH_B, RF_LUTWA, 0x1f, 0x12); in rtw8822c_set_channel_rf()
1320 rtw_write_rf(rtwdev, RF_PATH_B, RF_LUTWD0, 0xfffff, rf_rxbb); in rtw8822c_set_channel_rf()
1321 rtw_write_rf(rtwdev, RF_PATH_B, RF_LUTWE2, 0x04, 0x00); in rtw8822c_set_channel_rf()
1323 rtw_write_rf(rtwdev, RF_PATH_A, RF_CFGCH, RFREG_MASK, rf_reg18); in rtw8822c_set_channel_rf()
1324 rtw_write_rf(rtwdev, RF_PATH_B, RF_CFGCH, RFREG_MASK, rf_reg18); in rtw8822c_set_channel_rf()
1327 static void rtw8822c_toggle_igi(struct rtw_dev *rtwdev) in rtw8822c_toggle_igi() argument
1331 igi = rtw_read32_mask(rtwdev, REG_RXIGI, 0x7f); in rtw8822c_toggle_igi()
1332 rtw_write32_mask(rtwdev, REG_RXIGI, 0x7f, igi - 2); in rtw8822c_toggle_igi()
1333 rtw_write32_mask(rtwdev, REG_RXIGI, 0x7f00, igi - 2); in rtw8822c_toggle_igi()
1334 rtw_write32_mask(rtwdev, REG_RXIGI, 0x7f, igi); in rtw8822c_toggle_igi()
1335 rtw_write32_mask(rtwdev, REG_RXIGI, 0x7f00, igi); in rtw8822c_toggle_igi()
1338 static void rtw8822c_set_channel_bb(struct rtw_dev *rtwdev, u8 channel, u8 bw, in rtw8822c_set_channel_bb() argument
1342 rtw_write32_clr(rtwdev, REG_BGCTRL, BITS_RX_IQ_WEIGHT); in rtw8822c_set_channel_bb()
1343 rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0xf0000000, 0x8); in rtw8822c_set_channel_bb()
1344 rtw_write32_set(rtwdev, REG_TXF4, BIT(20)); in rtw8822c_set_channel_bb()
1345 rtw_write32_clr(rtwdev, REG_CCK_CHECK, BIT_CHECK_CCK_EN); in rtw8822c_set_channel_bb()
1346 rtw_write32_clr(rtwdev, REG_CCKTXONLY, BIT_BB_CCK_CHECK_EN); in rtw8822c_set_channel_bb()
1347 rtw_write32_mask(rtwdev, REG_CCAMSK, 0x3F000000, 0xF); in rtw8822c_set_channel_bb()
1351 rtw_write32_mask(rtwdev, REG_RXAGCCTL0, BITS_RXAGC_CCK, in rtw8822c_set_channel_bb()
1353 rtw_write32_mask(rtwdev, REG_RXAGCCTL, BITS_RXAGC_CCK, in rtw8822c_set_channel_bb()
1355 rtw_write32_mask(rtwdev, REG_RXAGCCTL0, BITS_RXAGC_OFDM, in rtw8822c_set_channel_bb()
1357 rtw_write32_mask(rtwdev, REG_RXAGCCTL, BITS_RXAGC_OFDM, in rtw8822c_set_channel_bb()
1361 rtw_write32_mask(rtwdev, REG_RXAGCCTL0, BITS_RXAGC_CCK, in rtw8822c_set_channel_bb()
1363 rtw_write32_mask(rtwdev, REG_RXAGCCTL, BITS_RXAGC_CCK, in rtw8822c_set_channel_bb()
1365 rtw_write32_mask(rtwdev, REG_RXAGCCTL0, BITS_RXAGC_OFDM, in rtw8822c_set_channel_bb()
1367 rtw_write32_mask(rtwdev, REG_RXAGCCTL, BITS_RXAGC_OFDM, in rtw8822c_set_channel_bb()
1372 rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x969); in rtw8822c_set_channel_bb()
1374 rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x96a); in rtw8822c_set_channel_bb()
1376 rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x9aa); in rtw8822c_set_channel_bb()
1378 rtw_write32_mask(rtwdev, REG_TXF0, MASKHWORD, 0x3da0); in rtw8822c_set_channel_bb()
1379 rtw_write32_mask(rtwdev, REG_TXF1, MASKDWORD, in rtw8822c_set_channel_bb()
1381 rtw_write32_mask(rtwdev, REG_TXF2, MASKLWORD, 0x6aa3); in rtw8822c_set_channel_bb()
1382 rtw_write32_mask(rtwdev, REG_TXF3, MASKHWORD, 0xaa7b); in rtw8822c_set_channel_bb()
1383 rtw_write32_mask(rtwdev, REG_TXF4, MASKLWORD, 0xf3d7); in rtw8822c_set_channel_bb()
1384 rtw_write32_mask(rtwdev, REG_TXF5, MASKDWORD, 0x0); in rtw8822c_set_channel_bb()
1385 rtw_write32_mask(rtwdev, REG_TXF6, MASKDWORD, in rtw8822c_set_channel_bb()
1387 rtw_write32_mask(rtwdev, REG_TXF7, MASKDWORD, 0xffff); in rtw8822c_set_channel_bb()
1389 rtw_write32_mask(rtwdev, REG_TXF0, MASKHWORD, 0x5284); in rtw8822c_set_channel_bb()
1390 rtw_write32_mask(rtwdev, REG_TXF1, MASKDWORD, in rtw8822c_set_channel_bb()
1392 rtw_write32_mask(rtwdev, REG_TXF2, MASKLWORD, 0x0a88); in rtw8822c_set_channel_bb()
1393 rtw_write32_mask(rtwdev, REG_TXF3, MASKHWORD, 0xacc4); in rtw8822c_set_channel_bb()
1394 rtw_write32_mask(rtwdev, REG_TXF4, MASKLWORD, 0xc8b2); in rtw8822c_set_channel_bb()
1395 rtw_write32_mask(rtwdev, REG_TXF5, MASKDWORD, in rtw8822c_set_channel_bb()
1397 rtw_write32_mask(rtwdev, REG_TXF6, MASKDWORD, in rtw8822c_set_channel_bb()
1399 rtw_write32_mask(rtwdev, REG_TXF7, MASKDWORD, in rtw8822c_set_channel_bb()
1403 rtw_write32_mask(rtwdev, REG_TXDFIR0, 0x70, 0x3); in rtw8822c_set_channel_bb()
1405 rtw_write32_mask(rtwdev, REG_TXDFIR0, 0x70, 0x1); in rtw8822c_set_channel_bb()
1407 rtw_write32_set(rtwdev, REG_CCKTXONLY, BIT_BB_CCK_CHECK_EN); in rtw8822c_set_channel_bb()
1408 rtw_write32_set(rtwdev, REG_CCK_CHECK, BIT_CHECK_CCK_EN); in rtw8822c_set_channel_bb()
1409 rtw_write32_set(rtwdev, REG_BGCTRL, BITS_RX_IQ_WEIGHT); in rtw8822c_set_channel_bb()
1410 rtw_write32_clr(rtwdev, REG_TXF4, BIT(20)); in rtw8822c_set_channel_bb()
1411 rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0xf0000000, 0x0); in rtw8822c_set_channel_bb()
1412 rtw_write32_mask(rtwdev, REG_CCAMSK, 0x3F000000, 0x22); in rtw8822c_set_channel_bb()
1413 rtw_write32_mask(rtwdev, REG_TXDFIR0, 0x70, 0x3); in rtw8822c_set_channel_bb()
1415 rtw_write32_mask(rtwdev, REG_RXAGCCTL0, BITS_RXAGC_OFDM, in rtw8822c_set_channel_bb()
1417 rtw_write32_mask(rtwdev, REG_RXAGCCTL, BITS_RXAGC_OFDM, in rtw8822c_set_channel_bb()
1420 rtw_write32_mask(rtwdev, REG_RXAGCCTL0, BITS_RXAGC_OFDM, in rtw8822c_set_channel_bb()
1422 rtw_write32_mask(rtwdev, REG_RXAGCCTL, BITS_RXAGC_OFDM, in rtw8822c_set_channel_bb()
1425 rtw_write32_mask(rtwdev, REG_RXAGCCTL0, BITS_RXAGC_OFDM, in rtw8822c_set_channel_bb()
1427 rtw_write32_mask(rtwdev, REG_RXAGCCTL, BITS_RXAGC_OFDM, in rtw8822c_set_channel_bb()
1432 rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x494); in rtw8822c_set_channel_bb()
1434 rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x493); in rtw8822c_set_channel_bb()
1436 rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x453); in rtw8822c_set_channel_bb()
1438 rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x452); in rtw8822c_set_channel_bb()
1440 rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x412); in rtw8822c_set_channel_bb()
1442 rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x411); in rtw8822c_set_channel_bb()
1447 rtw_write32_mask(rtwdev, REG_DFIRBW, 0x3FF0, 0x19B); in rtw8822c_set_channel_bb()
1448 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xf, 0x0); in rtw8822c_set_channel_bb()
1449 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xffc0, 0x0); in rtw8822c_set_channel_bb()
1450 rtw_write32_mask(rtwdev, REG_TXCLK, 0x700, 0x7); in rtw8822c_set_channel_bb()
1451 rtw_write32_mask(rtwdev, REG_TXCLK, 0x700000, 0x6); in rtw8822c_set_channel_bb()
1452 rtw_write32_mask(rtwdev, REG_CCK_SOURCE, BIT_NBI_EN, 0x0); in rtw8822c_set_channel_bb()
1453 rtw_write32_mask(rtwdev, REG_SBD, BITS_SUBTUNE, 0x1); in rtw8822c_set_channel_bb()
1454 rtw_write32_mask(rtwdev, REG_PT_CHSMO, BIT_PT_OPT, 0x0); in rtw8822c_set_channel_bb()
1457 rtw_write32_mask(rtwdev, REG_CCKSB, BIT(4), in rtw8822c_set_channel_bb()
1459 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xf, 0x5); in rtw8822c_set_channel_bb()
1460 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xc0, 0x0); in rtw8822c_set_channel_bb()
1461 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xff00, in rtw8822c_set_channel_bb()
1463 rtw_write32_mask(rtwdev, REG_CCK_SOURCE, BIT_NBI_EN, 0x1); in rtw8822c_set_channel_bb()
1464 rtw_write32_mask(rtwdev, REG_SBD, BITS_SUBTUNE, 0x1); in rtw8822c_set_channel_bb()
1465 rtw_write32_mask(rtwdev, REG_PT_CHSMO, BIT_PT_OPT, 0x1); in rtw8822c_set_channel_bb()
1468 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xf, 0xa); in rtw8822c_set_channel_bb()
1469 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xc0, 0x0); in rtw8822c_set_channel_bb()
1470 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xff00, in rtw8822c_set_channel_bb()
1472 rtw_write32_mask(rtwdev, REG_SBD, BITS_SUBTUNE, 0x6); in rtw8822c_set_channel_bb()
1473 rtw_write32_mask(rtwdev, REG_PT_CHSMO, BIT_PT_OPT, 0x1); in rtw8822c_set_channel_bb()
1476 rtw_write32_mask(rtwdev, REG_DFIRBW, 0x3FF0, 0x2AB); in rtw8822c_set_channel_bb()
1477 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xf, 0x0); in rtw8822c_set_channel_bb()
1478 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xffc0, 0x1); in rtw8822c_set_channel_bb()
1479 rtw_write32_mask(rtwdev, REG_TXCLK, 0x700, 0x4); in rtw8822c_set_channel_bb()
1480 rtw_write32_mask(rtwdev, REG_TXCLK, 0x700000, 0x4); in rtw8822c_set_channel_bb()
1481 rtw_write32_mask(rtwdev, REG_CCK_SOURCE, BIT_NBI_EN, 0x0); in rtw8822c_set_channel_bb()
1482 rtw_write32_mask(rtwdev, REG_SBD, BITS_SUBTUNE, 0x1); in rtw8822c_set_channel_bb()
1483 rtw_write32_mask(rtwdev, REG_PT_CHSMO, BIT_PT_OPT, 0x0); in rtw8822c_set_channel_bb()
1486 rtw_write32_mask(rtwdev, REG_DFIRBW, 0x3FF0, 0x2AB); in rtw8822c_set_channel_bb()
1487 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xf, 0x0); in rtw8822c_set_channel_bb()
1488 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xffc0, 0x2); in rtw8822c_set_channel_bb()
1489 rtw_write32_mask(rtwdev, REG_TXCLK, 0x700, 0x6); in rtw8822c_set_channel_bb()
1490 rtw_write32_mask(rtwdev, REG_TXCLK, 0x700000, 0x5); in rtw8822c_set_channel_bb()
1491 rtw_write32_mask(rtwdev, REG_CCK_SOURCE, BIT_NBI_EN, 0x0); in rtw8822c_set_channel_bb()
1492 rtw_write32_mask(rtwdev, REG_SBD, BITS_SUBTUNE, 0x1); in rtw8822c_set_channel_bb()
1493 rtw_write32_mask(rtwdev, REG_PT_CHSMO, BIT_PT_OPT, 0x0); in rtw8822c_set_channel_bb()
1498 static void rtw8822c_set_channel(struct rtw_dev *rtwdev, u8 channel, u8 bw, in rtw8822c_set_channel() argument
1501 rtw8822c_set_channel_bb(rtwdev, channel, bw, primary_chan_idx); in rtw8822c_set_channel()
1502 rtw_set_channel_mac(rtwdev, channel, bw, primary_chan_idx); in rtw8822c_set_channel()
1503 rtw8822c_set_channel_rf(rtwdev, channel, bw); in rtw8822c_set_channel()
1504 rtw8822c_toggle_igi(rtwdev); in rtw8822c_set_channel()
1507 static void rtw8822c_config_cck_rx_path(struct rtw_dev *rtwdev, u8 rx_path) in rtw8822c_config_cck_rx_path() argument
1510 rtw_write32_mask(rtwdev, REG_CCANRX, 0x00060000, 0x0); in rtw8822c_config_cck_rx_path()
1511 rtw_write32_mask(rtwdev, REG_CCANRX, 0x00600000, 0x0); in rtw8822c_config_cck_rx_path()
1513 rtw_write32_mask(rtwdev, REG_CCANRX, 0x00600000, 0x1); in rtw8822c_config_cck_rx_path()
1514 rtw_write32_mask(rtwdev, REG_CCANRX, 0x00060000, 0x1); in rtw8822c_config_cck_rx_path()
1518 rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0x0f000000, 0x0); in rtw8822c_config_cck_rx_path()
1520 rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0x0f000000, 0x5); in rtw8822c_config_cck_rx_path()
1522 rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0x0f000000, 0x1); in rtw8822c_config_cck_rx_path()
1525 static void rtw8822c_config_ofdm_rx_path(struct rtw_dev *rtwdev, u8 rx_path) in rtw8822c_config_ofdm_rx_path() argument
1528 rtw_write32_mask(rtwdev, REG_RXFNCTL, 0x300, 0x0); in rtw8822c_config_ofdm_rx_path()
1529 rtw_write32_mask(rtwdev, REG_RXFNCTL, 0x600000, 0x0); in rtw8822c_config_ofdm_rx_path()
1530 rtw_write32_mask(rtwdev, REG_AGCSWSH, BIT(17), 0x0); in rtw8822c_config_ofdm_rx_path()
1531 rtw_write32_mask(rtwdev, REG_ANTWTPD, BIT(20), 0x0); in rtw8822c_config_ofdm_rx_path()
1532 rtw_write32_mask(rtwdev, REG_MRCM, BIT(24), 0x0); in rtw8822c_config_ofdm_rx_path()
1534 rtw_write32_mask(rtwdev, REG_RXFNCTL, 0x300, 0x1); in rtw8822c_config_ofdm_rx_path()
1535 rtw_write32_mask(rtwdev, REG_RXFNCTL, 0x600000, 0x1); in rtw8822c_config_ofdm_rx_path()
1536 rtw_write32_mask(rtwdev, REG_AGCSWSH, BIT(17), 0x1); in rtw8822c_config_ofdm_rx_path()
1537 rtw_write32_mask(rtwdev, REG_ANTWTPD, BIT(20), 0x1); in rtw8822c_config_ofdm_rx_path()
1538 rtw_write32_mask(rtwdev, REG_MRCM, BIT(24), 0x1); in rtw8822c_config_ofdm_rx_path()
1541 rtw_write32_mask(rtwdev, 0x824, 0x0f000000, rx_path); in rtw8822c_config_ofdm_rx_path()
1542 rtw_write32_mask(rtwdev, 0x824, 0x000f0000, rx_path); in rtw8822c_config_ofdm_rx_path()
1545 static void rtw8822c_config_rx_path(struct rtw_dev *rtwdev, u8 rx_path) in rtw8822c_config_rx_path() argument
1547 rtw8822c_config_cck_rx_path(rtwdev, rx_path); in rtw8822c_config_rx_path()
1548 rtw8822c_config_ofdm_rx_path(rtwdev, rx_path); in rtw8822c_config_rx_path()
1551 static void rtw8822c_config_cck_tx_path(struct rtw_dev *rtwdev, u8 tx_path, in rtw8822c_config_cck_tx_path() argument
1555 rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0xf0000000, 0x8); in rtw8822c_config_cck_tx_path()
1557 rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0xf0000000, 0x4); in rtw8822c_config_cck_tx_path()
1560 rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0xf0000000, 0xc); in rtw8822c_config_cck_tx_path()
1562 rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0xf0000000, 0x8); in rtw8822c_config_cck_tx_path()
1566 static void rtw8822c_config_ofdm_tx_path(struct rtw_dev *rtwdev, u8 tx_path, in rtw8822c_config_ofdm_tx_path() argument
1570 rtw_write32_mask(rtwdev, REG_ANTMAP0, 0xff, 0x11); in rtw8822c_config_ofdm_tx_path()
1571 rtw_write32_mask(rtwdev, REG_TXLGMAP, 0xff, 0x0); in rtw8822c_config_ofdm_tx_path()
1573 rtw_write32_mask(rtwdev, REG_ANTMAP0, 0xff, 0x12); in rtw8822c_config_ofdm_tx_path()
1574 rtw_write32_mask(rtwdev, REG_TXLGMAP, 0xff, 0x0); in rtw8822c_config_ofdm_tx_path()
1577 rtw_write32_mask(rtwdev, REG_ANTMAP0, 0xff, 0x33); in rtw8822c_config_ofdm_tx_path()
1578 rtw_write32_mask(rtwdev, REG_TXLGMAP, 0xffff, 0x0404); in rtw8822c_config_ofdm_tx_path()
1580 rtw_write32_mask(rtwdev, REG_ANTMAP0, 0xff, 0x31); in rtw8822c_config_ofdm_tx_path()
1581 rtw_write32_mask(rtwdev, REG_TXLGMAP, 0xffff, 0x0400); in rtw8822c_config_ofdm_tx_path()
1586 static void rtw8822c_config_tx_path(struct rtw_dev *rtwdev, u8 tx_path, in rtw8822c_config_tx_path() argument
1589 rtw8822c_config_cck_tx_path(rtwdev, tx_path, is_tx2_path); in rtw8822c_config_tx_path()
1590 rtw8822c_config_ofdm_tx_path(rtwdev, tx_path, is_tx2_path); in rtw8822c_config_tx_path()
1593 static void rtw8822c_config_trx_mode(struct rtw_dev *rtwdev, u8 tx_path, in rtw8822c_config_trx_mode() argument
1597 rtw_write32_mask(rtwdev, REG_ORITXCODE, MASK20BITS, 0x33312); in rtw8822c_config_trx_mode()
1599 rtw_write32_mask(rtwdev, REG_ORITXCODE, MASK20BITS, 0x11111); in rtw8822c_config_trx_mode()
1601 rtw_write32_mask(rtwdev, REG_ORITXCODE2, MASK20BITS, 0x33312); in rtw8822c_config_trx_mode()
1603 rtw_write32_mask(rtwdev, REG_ORITXCODE2, MASK20BITS, 0x11111); in rtw8822c_config_trx_mode()
1605 rtw8822c_config_rx_path(rtwdev, rx_path); in rtw8822c_config_trx_mode()
1606 rtw8822c_config_tx_path(rtwdev, tx_path, is_tx2_path); in rtw8822c_config_trx_mode()
1608 rtw8822c_toggle_igi(rtwdev); in rtw8822c_config_trx_mode()
1611 static void query_phy_status_page0(struct rtw_dev *rtwdev, u8 *phy_status, in query_phy_status_page0() argument
1614 struct rtw_dm_info *dm_info = &rtwdev->dm_info; in query_phy_status_page0()
1647 static void query_phy_status_page1(struct rtw_dev *rtwdev, u8 *phy_status, in query_phy_status_page1() argument
1674 static void query_phy_status(struct rtw_dev *rtwdev, u8 *phy_status, in query_phy_status() argument
1683 query_phy_status_page0(rtwdev, phy_status, pkt_stat); in query_phy_status()
1686 query_phy_status_page1(rtwdev, phy_status, pkt_stat); in query_phy_status()
1689 rtw_warn(rtwdev, "unused phy status page (%d)\n", page); in query_phy_status()
1694 static void rtw8822c_query_rx_desc(struct rtw_dev *rtwdev, u8 *rx_desc, in rtw8822c_query_rx_desc() argument
1699 u32 desc_sz = rtwdev->chip->rx_pkt_desc_sz; in rtw8822c_query_rx_desc()
1728 query_phy_status(rtwdev, phy_status, pkt_stat); in rtw8822c_query_rx_desc()
1731 rtw_rx_fill_rx_status(rtwdev, pkt_stat, hdr, rx_status, phy_status); in rtw8822c_query_rx_desc()
1735 rtw8822c_set_write_tx_power_ref(struct rtw_dev *rtwdev, u8 *tx_pwr_ref_cck, in rtw8822c_set_write_tx_power_ref() argument
1738 struct rtw_hal *hal = &rtwdev->hal; in rtw8822c_set_write_tx_power_ref()
1744 rtw_write32_mask(rtwdev, 0x1c90, BIT(15), 0); in rtw8822c_set_write_tx_power_ref()
1745 rtw_write32_mask(rtwdev, txref_cck[path], 0x7f0000, in rtw8822c_set_write_tx_power_ref()
1749 rtw_write32_mask(rtwdev, 0x1c90, BIT(15), 0); in rtw8822c_set_write_tx_power_ref()
1750 rtw_write32_mask(rtwdev, txref_ofdm[path], 0x1fc00, in rtw8822c_set_write_tx_power_ref()
1755 static void rtw8822c_set_tx_power_diff(struct rtw_dev *rtwdev, u8 rate, in rtw8822c_set_tx_power_diff() argument
1772 rtw_write32_mask(rtwdev, 0x1c90, BIT(15), 0x0); in rtw8822c_set_tx_power_diff()
1773 rtw_write32_mask(rtwdev, offset_txagc + rate_idx, MASKDWORD, in rtw8822c_set_tx_power_diff()
1777 static void rtw8822c_set_tx_power_index(struct rtw_dev *rtwdev) in rtw8822c_set_tx_power_index() argument
1779 struct rtw_hal *hal = &rtwdev->hal; in rtw8822c_set_tx_power_index()
1789 rtw8822c_set_write_tx_power_ref(rtwdev, pwr_ref_cck, pwr_ref_ofdm); in rtw8822c_set_tx_power_index()
1804 rtw8822c_set_tx_power_diff(rtwdev, rate - 3, in rtw8822c_set_tx_power_index()
1810 static void rtw8822c_cfg_ldo25(struct rtw_dev *rtwdev, bool enable) in rtw8822c_cfg_ldo25() argument
1814 ldo_pwr = rtw_read8(rtwdev, REG_ANAPARLDO_POW_MAC); in rtw8822c_cfg_ldo25()
1816 rtw_write8(rtwdev, REG_ANAPARLDO_POW_MAC, ldo_pwr); in rtw8822c_cfg_ldo25()
1819 static void rtw8822c_false_alarm_statistics(struct rtw_dev *rtwdev) in rtw8822c_false_alarm_statistics() argument
1821 struct rtw_dm_info *dm_info = &rtwdev->dm_info; in rtw8822c_false_alarm_statistics()
1830 cck_enable = rtw_read32(rtwdev, REG_ENCCK) & BIT_CCK_BLK_EN; in rtw8822c_false_alarm_statistics()
1831 cck_fa_cnt = rtw_read16(rtwdev, REG_CCK_FACNT); in rtw8822c_false_alarm_statistics()
1833 ofdm_fa_cnt1 = rtw_read32(rtwdev, REG_OFDM_FACNT1); in rtw8822c_false_alarm_statistics()
1834 ofdm_fa_cnt2 = rtw_read32(rtwdev, REG_OFDM_FACNT2); in rtw8822c_false_alarm_statistics()
1835 ofdm_fa_cnt3 = rtw_read32(rtwdev, REG_OFDM_FACNT3); in rtw8822c_false_alarm_statistics()
1836 ofdm_fa_cnt4 = rtw_read32(rtwdev, REG_OFDM_FACNT4); in rtw8822c_false_alarm_statistics()
1837 ofdm_fa_cnt5 = rtw_read32(rtwdev, REG_OFDM_FACNT5); in rtw8822c_false_alarm_statistics()
1856 crc32_cnt = rtw_read32(rtwdev, 0x2c04); in rtw8822c_false_alarm_statistics()
1859 crc32_cnt = rtw_read32(rtwdev, 0x2c14); in rtw8822c_false_alarm_statistics()
1862 crc32_cnt = rtw_read32(rtwdev, 0x2c10); in rtw8822c_false_alarm_statistics()
1865 crc32_cnt = rtw_read32(rtwdev, 0x2c0c); in rtw8822c_false_alarm_statistics()
1869 rtw_write32_mask(rtwdev, REG_CCANRX, BIT_CCK_FA_RST, 0); in rtw8822c_false_alarm_statistics()
1870 rtw_write32_mask(rtwdev, REG_CCANRX, BIT_CCK_FA_RST, 2); in rtw8822c_false_alarm_statistics()
1871 rtw_write32_mask(rtwdev, REG_CCANRX, BIT_OFDM_FA_RST, 0); in rtw8822c_false_alarm_statistics()
1872 rtw_write32_mask(rtwdev, REG_CCANRX, BIT_OFDM_FA_RST, 2); in rtw8822c_false_alarm_statistics()
1875 rtw_write32_clr(rtwdev, REG_RX_BREAK, BIT_COM_RX_GCK_EN); in rtw8822c_false_alarm_statistics()
1876 rtw_write32_set(rtwdev, REG_CNT_CTRL, BIT_ALL_CNT_RST); in rtw8822c_false_alarm_statistics()
1877 rtw_write32_clr(rtwdev, REG_CNT_CTRL, BIT_ALL_CNT_RST); in rtw8822c_false_alarm_statistics()
1878 rtw_write32_set(rtwdev, REG_RX_BREAK, BIT_COM_RX_GCK_EN); in rtw8822c_false_alarm_statistics()
1881 static void rtw8822c_do_iqk(struct rtw_dev *rtwdev) in rtw8822c_do_iqk() argument
1888 rtw_fw_do_iqk(rtwdev, ¶); in rtw8822c_do_iqk()
1891 iqk_chk = rtw_read8(rtwdev, REG_RPT_CIP); in rtw8822c_do_iqk()
1896 rtw_write8(rtwdev, REG_IQKSTAT, 0x0); in rtw8822c_do_iqk()
1898 rtw_dbg(rtwdev, RTW_DBG_RFK, "iqk counter=%d\n", counter); in rtw8822c_do_iqk()
1902 static void rtw8822c_coex_cfg_init(struct rtw_dev *rtwdev) in rtw8822c_coex_cfg_init() argument
1905 rtw_write8_set(rtwdev, REG_BCN_CTRL, BIT_EN_BCN_FUNCTION); in rtw8822c_coex_cfg_init()
1909 rtw_write8_set(rtwdev, REG_BT_TDMA_TIME, 0x05); in rtw8822c_coex_cfg_init()
1912 rtw_write8(rtwdev, REG_BT_STAT_CTRL, 0x1); in rtw8822c_coex_cfg_init()
1915 rtw_write32_set(rtwdev, REG_GPIO_MUXCFG, BIT_BT_PTA_EN); in rtw8822c_coex_cfg_init()
1916 rtw_write32_set(rtwdev, REG_GPIO_MUXCFG, BIT_BT_AOD_GPIO3); in rtw8822c_coex_cfg_init()
1919 rtw_write8_set(rtwdev, REG_QUEUE_CTRL, BIT_PTA_WL_TX_EN); in rtw8822c_coex_cfg_init()
1921 rtw_write8_clr(rtwdev, REG_QUEUE_CTRL, BIT_PTA_EDCCA_EN); in rtw8822c_coex_cfg_init()
1923 rtw_write8_set(rtwdev, REG_BT_COEX_V2, BIT_GNT_BT_POLARITY); in rtw8822c_coex_cfg_init()
1925 rtw_write8_clr(rtwdev, REG_DUMMY_PAGE4_V1, BIT_BTCCA_CTRL); in rtw8822c_coex_cfg_init()
1928 rtw_write_rf(rtwdev, RF_PATH_B, 0x1, 0xfffff, 0x40000); in rtw8822c_coex_cfg_init()
1931 static void rtw8822c_coex_cfg_gnt_fix(struct rtw_dev *rtwdev) in rtw8822c_coex_cfg_gnt_fix() argument
1933 struct rtw_coex *coex = &rtwdev->coex; in rtw8822c_coex_cfg_gnt_fix()
1935 struct rtw_efuse *efuse = &rtwdev->efuse; in rtw8822c_coex_cfg_gnt_fix()
1952 rtw_write_rf(rtwdev, RF_PATH_B, 0x1, 0xfffff, rf_0x1); in rtw8822c_coex_cfg_gnt_fix()
1965 rtw_write8_mask(rtwdev, 0x1c32, BIT(6), 1); in rtw8822c_coex_cfg_gnt_fix()
1966 rtw_write8_mask(rtwdev, 0x1c39, BIT(4), 0); in rtw8822c_coex_cfg_gnt_fix()
1967 rtw_write8_mask(rtwdev, 0x1c3b, BIT(4), 1); in rtw8822c_coex_cfg_gnt_fix()
1968 rtw_write8_mask(rtwdev, 0x4160, BIT(3), 1); in rtw8822c_coex_cfg_gnt_fix()
1976 rtw_write8_mask(rtwdev, 0x1860, BIT(3), 0); in rtw8822c_coex_cfg_gnt_fix()
1977 rtw_write8_mask(rtwdev, 0x1ca7, BIT(3), 1); in rtw8822c_coex_cfg_gnt_fix()
1979 rtw_write8_mask(rtwdev, 0x1860, BIT(3), 1); in rtw8822c_coex_cfg_gnt_fix()
1983 rtw_write8_mask(rtwdev, 0x1860, BIT(3), 0); in rtw8822c_coex_cfg_gnt_fix()
1985 rtw_write8_mask(rtwdev, 0x1ca7, BIT(3), 0); in rtw8822c_coex_cfg_gnt_fix()
1989 static void rtw8822c_coex_cfg_gnt_debug(struct rtw_dev *rtwdev) in rtw8822c_coex_cfg_gnt_debug() argument
1991 rtw_write8_mask(rtwdev, 0x66, BIT(4), 0); in rtw8822c_coex_cfg_gnt_debug()
1992 rtw_write8_mask(rtwdev, 0x67, BIT(0), 0); in rtw8822c_coex_cfg_gnt_debug()
1993 rtw_write8_mask(rtwdev, 0x42, BIT(3), 0); in rtw8822c_coex_cfg_gnt_debug()
1994 rtw_write8_mask(rtwdev, 0x65, BIT(7), 0); in rtw8822c_coex_cfg_gnt_debug()
1995 rtw_write8_mask(rtwdev, 0x73, BIT(3), 0); in rtw8822c_coex_cfg_gnt_debug()
1998 static void rtw8822c_coex_cfg_rfe_type(struct rtw_dev *rtwdev) in rtw8822c_coex_cfg_rfe_type() argument
2000 struct rtw_coex *coex = &rtwdev->coex; in rtw8822c_coex_cfg_rfe_type()
2002 struct rtw_efuse *efuse = &rtwdev->efuse; in rtw8822c_coex_cfg_rfe_type()
2004 coex_rfe->rfe_module_type = rtwdev->efuse.rfe_option; in rtw8822c_coex_cfg_rfe_type()
2016 rtw_coex_write_indirect_reg(rtwdev, 0x38, BIT_LTE_COEX_EN, 0x0); in rtw8822c_coex_cfg_rfe_type()
2017 rtw_coex_write_indirect_reg(rtwdev, 0xa0, MASKLWORD, 0xffff); in rtw8822c_coex_cfg_rfe_type()
2018 rtw_coex_write_indirect_reg(rtwdev, 0xa4, MASKLWORD, 0xffff); in rtw8822c_coex_cfg_rfe_type()
2021 static void rtw8822c_coex_cfg_wl_tx_power(struct rtw_dev *rtwdev, u8 wl_pwr) in rtw8822c_coex_cfg_wl_tx_power() argument
2023 struct rtw_coex *coex = &rtwdev->coex; in rtw8822c_coex_cfg_wl_tx_power()
2032 static void rtw8822c_coex_cfg_wl_rx_gain(struct rtw_dev *rtwdev, bool low_gain) in rtw8822c_coex_cfg_wl_rx_gain() argument
2034 struct rtw_coex *coex = &rtwdev->coex; in rtw8822c_coex_cfg_wl_rx_gain()
2044 rtw_write_rf(rtwdev, RF_PATH_A, 0xde, 0xfffff, 0x22); in rtw8822c_coex_cfg_wl_rx_gain()
2045 rtw_write_rf(rtwdev, RF_PATH_A, 0x1d, 0xfffff, 0x36); in rtw8822c_coex_cfg_wl_rx_gain()
2046 rtw_write_rf(rtwdev, RF_PATH_B, 0xde, 0xfffff, 0x22); in rtw8822c_coex_cfg_wl_rx_gain()
2047 rtw_write_rf(rtwdev, RF_PATH_B, 0x1d, 0xfffff, 0x36); in rtw8822c_coex_cfg_wl_rx_gain()
2050 rtw_write_rf(rtwdev, RF_PATH_A, 0xde, 0xfffff, 0x20); in rtw8822c_coex_cfg_wl_rx_gain()
2051 rtw_write_rf(rtwdev, RF_PATH_A, 0x1d, 0xfffff, 0x0); in rtw8822c_coex_cfg_wl_rx_gain()
2052 rtw_write_rf(rtwdev, RF_PATH_B, 0x1d, 0xfffff, 0x0); in rtw8822c_coex_cfg_wl_rx_gain()
2062 void rtw8822c_parse_tbl_dpk(struct rtw_dev *rtwdev, in rtw8822c_parse_tbl_dpk() argument
2071 rtw_write32_mask(rtwdev, p->addr, p->bitmask, p->data); in rtw8822c_parse_tbl_dpk()
2074 static void rtw8822c_dpk_set_gnt_wl(struct rtw_dev *rtwdev, bool is_before_k) in rtw8822c_dpk_set_gnt_wl() argument
2076 struct rtw_dpk_info *dpk_info = &rtwdev->dm_info.dpk_info; in rtw8822c_dpk_set_gnt_wl()
2079 dpk_info->gnt_control = rtw_read32(rtwdev, 0x70); in rtw8822c_dpk_set_gnt_wl()
2080 dpk_info->gnt_value = rtw_coex_read_indirect_reg(rtwdev, 0x38); in rtw8822c_dpk_set_gnt_wl()
2081 rtw_write32_mask(rtwdev, 0x70, BIT(26), 0x1); in rtw8822c_dpk_set_gnt_wl()
2082 rtw_coex_write_indirect_reg(rtwdev, 0x38, MASKBYTE1, 0x77); in rtw8822c_dpk_set_gnt_wl()
2084 rtw_coex_write_indirect_reg(rtwdev, 0x38, MASKDWORD, in rtw8822c_dpk_set_gnt_wl()
2086 rtw_write32(rtwdev, 0x70, dpk_info->gnt_control); in rtw8822c_dpk_set_gnt_wl()
2091 rtw8822c_dpk_restore_registers(struct rtw_dev *rtwdev, u32 reg_num, in rtw8822c_dpk_restore_registers() argument
2094 rtw_restore_reg(rtwdev, bckp, reg_num); in rtw8822c_dpk_restore_registers()
2095 rtw_write32_mask(rtwdev, REG_NCTL0, BIT_SUBPAGE, 0xc); in rtw8822c_dpk_restore_registers()
2096 rtw_write32_mask(rtwdev, REG_RXSRAM_CTL, BIT_DPD_CLK, 0x4); in rtw8822c_dpk_restore_registers()
2100 rtw8822c_dpk_backup_registers(struct rtw_dev *rtwdev, u32 *reg, in rtw8822c_dpk_backup_registers() argument
2108 bckp[i].val = rtw_read32(rtwdev, reg[i]); in rtw8822c_dpk_backup_registers()
2112 static void rtw8822c_dpk_backup_rf_registers(struct rtw_dev *rtwdev, in rtw8822c_dpk_backup_rf_registers() argument
2119 rf_reg_bak[i][RF_PATH_A] = rtw_read_rf(rtwdev, RF_PATH_A, in rtw8822c_dpk_backup_rf_registers()
2121 rf_reg_bak[i][RF_PATH_B] = rtw_read_rf(rtwdev, RF_PATH_B, in rtw8822c_dpk_backup_rf_registers()
2126 static void rtw8822c_dpk_reload_rf_registers(struct rtw_dev *rtwdev, in rtw8822c_dpk_reload_rf_registers() argument
2133 rtw_write_rf(rtwdev, RF_PATH_A, rf_reg[i], RFREG_MASK, in rtw8822c_dpk_reload_rf_registers()
2135 rtw_write_rf(rtwdev, RF_PATH_B, rf_reg[i], RFREG_MASK, in rtw8822c_dpk_reload_rf_registers()
2140 static void rtw8822c_dpk_information(struct rtw_dev *rtwdev) in rtw8822c_dpk_information() argument
2142 struct rtw_dpk_info *dpk_info = &rtwdev->dm_info.dpk_info; in rtw8822c_dpk_information()
2146 reg = rtw_read_rf(rtwdev, RF_PATH_A, 0x18, RFREG_MASK); in rtw8822c_dpk_information()
2154 static void rtw8822c_dpk_rxbb_dc_cal(struct rtw_dev *rtwdev, u8 path) in rtw8822c_dpk_rxbb_dc_cal() argument
2156 rtw_write_rf(rtwdev, path, 0x92, RFREG_MASK, 0x84800); in rtw8822c_dpk_rxbb_dc_cal()
2158 rtw_write_rf(rtwdev, path, 0x92, RFREG_MASK, 0x84801); in rtw8822c_dpk_rxbb_dc_cal()
2160 rtw_write_rf(rtwdev, path, 0x92, RFREG_MASK, 0x84800); in rtw8822c_dpk_rxbb_dc_cal()
2163 static u8 rtw8822c_dpk_dc_corr_check(struct rtw_dev *rtwdev, u8 path) in rtw8822c_dpk_dc_corr_check() argument
2168 rtw_write32(rtwdev, REG_RXSRAM_CTL, 0x000900f0); in rtw8822c_dpk_dc_corr_check()
2169 dc_i = (u16)rtw_read32_mask(rtwdev, REG_STAT_RPT, GENMASK(27, 16)); in rtw8822c_dpk_dc_corr_check()
2170 dc_q = (u16)rtw_read32_mask(rtwdev, REG_STAT_RPT, GENMASK(11, 0)); in rtw8822c_dpk_dc_corr_check()
2177 rtw_write32(rtwdev, REG_RXSRAM_CTL, 0x000000f0); in rtw8822c_dpk_dc_corr_check()
2178 corr_idx = (u8)rtw_read32_mask(rtwdev, REG_STAT_RPT, GENMASK(7, 0)); in rtw8822c_dpk_dc_corr_check()
2179 corr_val = (u8)rtw_read32_mask(rtwdev, REG_STAT_RPT, GENMASK(15, 8)); in rtw8822c_dpk_dc_corr_check()
2188 static void rtw8822c_dpk_tx_pause(struct rtw_dev *rtwdev) in rtw8822c_dpk_tx_pause() argument
2193 rtw_write8(rtwdev, 0x522, 0xff); in rtw8822c_dpk_tx_pause()
2194 rtw_write32_mask(rtwdev, 0x1e70, 0xf, 0x2); in rtw8822c_dpk_tx_pause()
2197 reg_a = (u8)rtw_read_rf(rtwdev, RF_PATH_A, 0x00, 0xf0000); in rtw8822c_dpk_tx_pause()
2198 reg_b = (u8)rtw_read_rf(rtwdev, RF_PATH_B, 0x00, 0xf0000); in rtw8822c_dpk_tx_pause()
2204 static void rtw8822c_dpk_mac_bb_setting(struct rtw_dev *rtwdev) in rtw8822c_dpk_mac_bb_setting() argument
2206 rtw8822c_dpk_tx_pause(rtwdev); in rtw8822c_dpk_mac_bb_setting()
2207 rtw_load_table(rtwdev, &rtw8822c_dpk_mac_bb_tbl); in rtw8822c_dpk_mac_bb_setting()
2210 static void rtw8822c_dpk_afe_setting(struct rtw_dev *rtwdev, bool is_do_dpk) in rtw8822c_dpk_afe_setting() argument
2213 rtw_load_table(rtwdev, &rtw8822c_dpk_afe_is_dpk_tbl); in rtw8822c_dpk_afe_setting()
2215 rtw_load_table(rtwdev, &rtw8822c_dpk_afe_no_dpk_tbl); in rtw8822c_dpk_afe_setting()
2218 static void rtw8822c_dpk_pre_setting(struct rtw_dev *rtwdev) in rtw8822c_dpk_pre_setting() argument
2222 for (path = 0; path < rtwdev->hal.rf_path_num; path++) { in rtw8822c_dpk_pre_setting()
2223 rtw_write_rf(rtwdev, path, RF_RXAGC_OFFSET, RFREG_MASK, 0x0); in rtw8822c_dpk_pre_setting()
2224 rtw_write32(rtwdev, REG_NCTL0, 0x8 | (path << 1)); in rtw8822c_dpk_pre_setting()
2225 if (rtwdev->dm_info.dpk_info.dpk_band == RTW_BAND_2G) in rtw8822c_dpk_pre_setting()
2226 rtw_write32(rtwdev, REG_DPD_LUT3, 0x1f100000); in rtw8822c_dpk_pre_setting()
2228 rtw_write32(rtwdev, REG_DPD_LUT3, 0x1f0d0000); in rtw8822c_dpk_pre_setting()
2229 rtw_write32_mask(rtwdev, REG_DPD_LUT0, BIT_GLOSS_DB, 0x4); in rtw8822c_dpk_pre_setting()
2230 rtw_write32_mask(rtwdev, REG_IQK_CTL1, BIT_TX_CFIR, 0x3); in rtw8822c_dpk_pre_setting()
2232 rtw_write32_mask(rtwdev, REG_NCTL0, BIT_SUBPAGE, 0xc); in rtw8822c_dpk_pre_setting()
2233 rtw_write32(rtwdev, REG_DPD_CTL11, 0x3b23170b); in rtw8822c_dpk_pre_setting()
2234 rtw_write32(rtwdev, REG_DPD_CTL12, 0x775f5347); in rtw8822c_dpk_pre_setting()
2237 static u32 rtw8822c_dpk_rf_setting(struct rtw_dev *rtwdev, u8 path) in rtw8822c_dpk_rf_setting() argument
2241 rtw_write_rf(rtwdev, path, RF_MODE_TRXAGC, RFREG_MASK, 0x50017); in rtw8822c_dpk_rf_setting()
2242 ori_txbb = rtw_read_rf(rtwdev, path, RF_TX_GAIN, RFREG_MASK); in rtw8822c_dpk_rf_setting()
2244 rtw_write_rf(rtwdev, path, RF_DEBUG, BIT_DE_TX_GAIN, 0x1); in rtw8822c_dpk_rf_setting()
2245 rtw_write_rf(rtwdev, path, RF_DEBUG, BIT_DE_PWR_TRIM, 0x1); in rtw8822c_dpk_rf_setting()
2246 rtw_write_rf(rtwdev, path, RF_TX_GAIN_OFFSET, BIT_TX_OFFSET_VAL, 0x0); in rtw8822c_dpk_rf_setting()
2247 rtw_write_rf(rtwdev, path, RF_TX_GAIN, RFREG_MASK, ori_txbb); in rtw8822c_dpk_rf_setting()
2249 if (rtwdev->dm_info.dpk_info.dpk_band == RTW_BAND_2G) { in rtw8822c_dpk_rf_setting()
2250 rtw_write_rf(rtwdev, path, RF_TX_GAIN_OFFSET, BIT_LB_ATT, 0x1); in rtw8822c_dpk_rf_setting()
2251 rtw_write_rf(rtwdev, path, RF_RXG_GAIN, BIT_RXG_GAIN, 0x0); in rtw8822c_dpk_rf_setting()
2253 rtw_write_rf(rtwdev, path, RF_TXA_LB_SW, BIT_TXA_LB_ATT, 0x0); in rtw8822c_dpk_rf_setting()
2254 rtw_write_rf(rtwdev, path, RF_TXA_LB_SW, BIT_LB_ATT, 0x6); in rtw8822c_dpk_rf_setting()
2255 rtw_write_rf(rtwdev, path, RF_TXA_LB_SW, BIT_LB_SW, 0x1); in rtw8822c_dpk_rf_setting()
2256 rtw_write_rf(rtwdev, path, RF_RXA_MIX_GAIN, BIT_RXA_MIX_GAIN, 0); in rtw8822c_dpk_rf_setting()
2259 rtw_write_rf(rtwdev, path, RF_MODE_TRXAGC, BIT_RXAGC, 0xf); in rtw8822c_dpk_rf_setting()
2260 rtw_write_rf(rtwdev, path, RF_DEBUG, BIT_DE_TRXBW, 0x1); in rtw8822c_dpk_rf_setting()
2261 rtw_write_rf(rtwdev, path, RF_BW_TRXBB, BIT_BW_RXBB, 0x0); in rtw8822c_dpk_rf_setting()
2263 if (rtwdev->dm_info.dpk_info.dpk_bw == DPK_CHANNEL_WIDTH_80) in rtw8822c_dpk_rf_setting()
2264 rtw_write_rf(rtwdev, path, RF_BW_TRXBB, BIT_BW_TXBB, 0x2); in rtw8822c_dpk_rf_setting()
2266 rtw_write_rf(rtwdev, path, RF_BW_TRXBB, BIT_BW_TXBB, 0x1); in rtw8822c_dpk_rf_setting()
2268 rtw_write_rf(rtwdev, path, RF_EXT_TIA_BW, BIT(1), 0x1); in rtw8822c_dpk_rf_setting()
2275 static u16 rtw8822c_dpk_get_cmd(struct rtw_dev *rtwdev, u8 action, u8 path) in rtw8822c_dpk_get_cmd() argument
2278 u8 bw = rtwdev->dm_info.dpk_info.dpk_bw == DPK_CHANNEL_WIDTH_80 ? 2 : 0; in rtw8822c_dpk_get_cmd()
2300 static u8 rtw8822c_dpk_one_shot(struct rtw_dev *rtwdev, u8 path, u8 action) in rtw8822c_dpk_one_shot() argument
2305 rtw8822c_dpk_set_gnt_wl(rtwdev, true); in rtw8822c_dpk_one_shot()
2308 rtw_write32_mask(rtwdev, REG_DPD_CTL0, BIT(12), 0x1); in rtw8822c_dpk_one_shot()
2309 rtw_write32_mask(rtwdev, REG_DPD_CTL0, BIT(12), 0x0); in rtw8822c_dpk_one_shot()
2310 rtw_write32_mask(rtwdev, REG_RXSRAM_CTL, BIT_RPT_SEL, 0x0); in rtw8822c_dpk_one_shot()
2312 if (!check_hw_ready(rtwdev, REG_STAT_RPT, BIT(31), 0x1)) { in rtw8822c_dpk_one_shot()
2314 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DPK] one-shot over 20ms\n"); in rtw8822c_dpk_one_shot()
2317 rtw_write32_mask(rtwdev, REG_NCTL0, BIT_SUBPAGE, in rtw8822c_dpk_one_shot()
2319 rtw_write32_mask(rtwdev, REG_R_CONFIG, BIT_IQ_SWITCH, 0x9); in rtw8822c_dpk_one_shot()
2321 dpk_cmd = rtw8822c_dpk_get_cmd(rtwdev, action, path); in rtw8822c_dpk_one_shot()
2322 rtw_write32(rtwdev, REG_NCTL0, dpk_cmd); in rtw8822c_dpk_one_shot()
2323 rtw_write32(rtwdev, REG_NCTL0, dpk_cmd + 1); in rtw8822c_dpk_one_shot()
2325 if (!check_hw_ready(rtwdev, 0x2d9c, 0xff, 0x55)) { in rtw8822c_dpk_one_shot()
2327 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DPK] one-shot over 20ms\n"); in rtw8822c_dpk_one_shot()
2329 rtw_write32_mask(rtwdev, REG_NCTL0, BIT_SUBPAGE, in rtw8822c_dpk_one_shot()
2331 rtw_write32_mask(rtwdev, REG_R_CONFIG, BIT_IQ_SWITCH, 0x0); in rtw8822c_dpk_one_shot()
2334 rtw8822c_dpk_set_gnt_wl(rtwdev, false); in rtw8822c_dpk_one_shot()
2336 rtw_write8(rtwdev, 0x1b10, 0x0); in rtw8822c_dpk_one_shot()
2341 static u16 rtw8822c_dpk_dgain_read(struct rtw_dev *rtwdev, u8 path) in rtw8822c_dpk_dgain_read() argument
2345 rtw_write32_mask(rtwdev, REG_NCTL0, BIT_SUBPAGE, 0xc); in rtw8822c_dpk_dgain_read()
2346 rtw_write32_mask(rtwdev, REG_RXSRAM_CTL, 0x00ff0000, 0x0); in rtw8822c_dpk_dgain_read()
2348 dgain = (u16)rtw_read32_mask(rtwdev, REG_STAT_RPT, GENMASK(27, 16)); in rtw8822c_dpk_dgain_read()
2353 static u8 rtw8822c_dpk_thermal_read(struct rtw_dev *rtwdev, u8 path) in rtw8822c_dpk_thermal_read() argument
2355 rtw_write_rf(rtwdev, path, RF_T_METER, BIT(19), 0x1); in rtw8822c_dpk_thermal_read()
2356 rtw_write_rf(rtwdev, path, RF_T_METER, BIT(19), 0x0); in rtw8822c_dpk_thermal_read()
2357 rtw_write_rf(rtwdev, path, RF_T_METER, BIT(19), 0x1); in rtw8822c_dpk_thermal_read()
2360 return (u8)rtw_read_rf(rtwdev, path, RF_T_METER, 0x0007e); in rtw8822c_dpk_thermal_read()
2363 static u32 rtw8822c_dpk_pas_read(struct rtw_dev *rtwdev, u8 path) in rtw8822c_dpk_pas_read() argument
2367 rtw_write32(rtwdev, REG_NCTL0, 0x8 | (path << 1)); in rtw8822c_dpk_pas_read()
2368 rtw_write32_mask(rtwdev, 0x1b48, BIT(14), 0x0); in rtw8822c_dpk_pas_read()
2369 rtw_write32(rtwdev, REG_RXSRAM_CTL, 0x00060001); in rtw8822c_dpk_pas_read()
2370 rtw_write32(rtwdev, 0x1b4c, 0x00000000); in rtw8822c_dpk_pas_read()
2371 rtw_write32(rtwdev, 0x1b4c, 0x00080000); in rtw8822c_dpk_pas_read()
2373 q_val = rtw_read32_mask(rtwdev, REG_STAT_RPT, MASKHWORD); in rtw8822c_dpk_pas_read()
2374 i_val = rtw_read32_mask(rtwdev, REG_STAT_RPT, MASKLWORD); in rtw8822c_dpk_pas_read()
2381 rtw_write32(rtwdev, 0x1b4c, 0x00000000); in rtw8822c_dpk_pas_read()
2412 static u8 rtw8822c_dpk_gainloss_result(struct rtw_dev *rtwdev, u8 path) in rtw8822c_dpk_gainloss_result() argument
2416 rtw_write32_mask(rtwdev, REG_NCTL0, BIT_SUBPAGE, 0x8 | (path << 1)); in rtw8822c_dpk_gainloss_result()
2417 rtw_write32_mask(rtwdev, 0x1b48, BIT(14), 0x1); in rtw8822c_dpk_gainloss_result()
2418 rtw_write32(rtwdev, REG_RXSRAM_CTL, 0x00060000); in rtw8822c_dpk_gainloss_result()
2420 result = (u8)rtw_read32_mask(rtwdev, REG_STAT_RPT, 0x000000f0); in rtw8822c_dpk_gainloss_result()
2422 rtw_write32_mask(rtwdev, 0x1b48, BIT(14), 0x0); in rtw8822c_dpk_gainloss_result()
2427 static u8 rtw8822c_dpk_agc_gain_chk(struct rtw_dev *rtwdev, u8 path, in rtw8822c_dpk_agc_gain_chk() argument
2433 rtw8822c_dpk_one_shot(rtwdev, path, RTW_DPK_DAGC); in rtw8822c_dpk_agc_gain_chk()
2434 dgain = rtw8822c_dpk_dgain_read(rtwdev, path); in rtw8822c_dpk_agc_gain_chk()
2444 static u8 rtw8822c_dpk_agc_loss_chk(struct rtw_dev *rtwdev, u8 path) in rtw8822c_dpk_agc_loss_chk() argument
2448 loss = rtw8822c_dpk_pas_read(rtwdev, path); in rtw8822c_dpk_agc_loss_chk()
2471 static u8 rtw8822c_gain_check_state(struct rtw_dev *rtwdev, in rtw8822c_gain_check_state() argument
2476 data->txbb = (u8)rtw_read_rf(rtwdev, data->path, RF_TX_GAIN, in rtw8822c_gain_check_state()
2478 data->pga = (u8)rtw_read_rf(rtwdev, data->path, RF_MODE_TRXAGC, in rtw8822c_gain_check_state()
2486 state = rtw8822c_dpk_agc_gain_chk(rtwdev, data->path, in rtw8822c_gain_check_state()
2501 static u8 rtw8822c_gain_large_state(struct rtw_dev *rtwdev, in rtw8822c_gain_large_state() argument
2507 rtw_write_rf(rtwdev, data->path, RF_MODE_TRXAGC, BIT_RXAGC, 0xc); in rtw8822c_gain_large_state()
2509 rtw_write_rf(rtwdev, data->path, RF_MODE_TRXAGC, BIT_RXAGC, 0x0); in rtw8822c_gain_large_state()
2516 static u8 rtw8822c_gain_less_state(struct rtw_dev *rtwdev, in rtw8822c_gain_less_state() argument
2522 rtw_write_rf(rtwdev, data->path, RF_MODE_TRXAGC, BIT_RXAGC, 0xc); in rtw8822c_gain_less_state()
2524 rtw_write_rf(rtwdev, data->path, RF_MODE_TRXAGC, BIT_RXAGC, 0xf); in rtw8822c_gain_less_state()
2531 static u8 rtw8822c_gl_state(struct rtw_dev *rtwdev, in rtw8822c_gl_state() argument
2544 rtw_write_rf(rtwdev, data->path, RF_TX_GAIN, BIT_GAIN_TXBB, data->txbb); in rtw8822c_gl_state()
2550 static u8 rtw8822c_gl_large_state(struct rtw_dev *rtwdev, in rtw8822c_gl_large_state() argument
2553 return rtw8822c_gl_state(rtwdev, data, 1); in rtw8822c_gl_large_state()
2556 static u8 rtw8822c_gl_less_state(struct rtw_dev *rtwdev, in rtw8822c_gl_less_state() argument
2559 return rtw8822c_gl_state(rtwdev, data, 0); in rtw8822c_gl_less_state()
2562 static u8 rtw8822c_loss_check_state(struct rtw_dev *rtwdev, in rtw8822c_loss_check_state() argument
2568 rtw8822c_dpk_one_shot(rtwdev, path, RTW_DPK_GAIN_LOSS); in rtw8822c_loss_check_state()
2569 state = rtw8822c_dpk_agc_loss_chk(rtwdev, path); in rtw8822c_loss_check_state()
2574 static u8 (*dpk_state[])(struct rtw_dev *rtwdev,
2580 static u8 rtw8822c_dpk_pas_agc(struct rtw_dev *rtwdev, u8 path, in rtw8822c_dpk_pas_agc() argument
2584 u8 (*func)(struct rtw_dev *rtwdev, struct rtw8822c_dpk_data *data); in rtw8822c_dpk_pas_agc()
2593 state = func(rtwdev, &data); in rtw8822c_dpk_pas_agc()
2601 static bool rtw8822c_dpk_coef_iq_check(struct rtw_dev *rtwdev, in rtw8822c_dpk_coef_iq_check() argument
2611 static u32 rtw8822c_dpk_coef_transfer(struct rtw_dev *rtwdev) in rtw8822c_dpk_coef_transfer() argument
2616 reg = rtw_read32(rtwdev, REG_STAT_RPT); in rtw8822c_dpk_coef_transfer()
2618 coef_i = (u16)rtw_read32_mask(rtwdev, REG_STAT_RPT, MASKHWORD) & 0x1fff; in rtw8822c_dpk_coef_transfer()
2619 coef_q = (u16)rtw_read32_mask(rtwdev, REG_STAT_RPT, MASKLWORD) & 0x1fff; in rtw8822c_dpk_coef_transfer()
2635 static void rtw8822c_dpk_coef_tbl_apply(struct rtw_dev *rtwdev, u8 path) in rtw8822c_dpk_coef_tbl_apply() argument
2637 struct rtw_dpk_info *dpk_info = &rtwdev->dm_info.dpk_info; in rtw8822c_dpk_coef_tbl_apply()
2641 rtw_write32(rtwdev, REG_RXSRAM_CTL, in rtw8822c_dpk_coef_tbl_apply()
2643 dpk_info->coef[path][i] = rtw8822c_dpk_coef_transfer(rtwdev); in rtw8822c_dpk_coef_tbl_apply()
2647 static void rtw8822c_dpk_get_coef(struct rtw_dev *rtwdev, u8 path) in rtw8822c_dpk_get_coef() argument
2649 rtw_write32(rtwdev, REG_NCTL0, 0x0000000c); in rtw8822c_dpk_get_coef()
2652 rtw_write32_mask(rtwdev, REG_DPD_CTL0, BIT(24), 0x0); in rtw8822c_dpk_get_coef()
2653 rtw_write32(rtwdev, REG_DPD_CTL0_S0, 0x30000080); in rtw8822c_dpk_get_coef()
2655 rtw_write32_mask(rtwdev, REG_DPD_CTL0, BIT(24), 0x1); in rtw8822c_dpk_get_coef()
2656 rtw_write32(rtwdev, REG_DPD_CTL0_S1, 0x30000080); in rtw8822c_dpk_get_coef()
2659 rtw8822c_dpk_coef_tbl_apply(rtwdev, path); in rtw8822c_dpk_get_coef()
2662 static u8 rtw8822c_dpk_coef_read(struct rtw_dev *rtwdev, u8 path) in rtw8822c_dpk_coef_read() argument
2664 struct rtw_dpk_info *dpk_info = &rtwdev->dm_info.dpk_info; in rtw8822c_dpk_coef_read()
2672 if (rtw8822c_dpk_coef_iq_check(rtwdev, coef_i, coef_q)) { in rtw8822c_dpk_coef_read()
2680 static void rtw8822c_dpk_coef_write(struct rtw_dev *rtwdev, u8 path, u8 result) in rtw8822c_dpk_coef_write() argument
2682 struct rtw_dpk_info *dpk_info = &rtwdev->dm_info.dpk_info; in rtw8822c_dpk_coef_write()
2687 rtw_write32(rtwdev, REG_NCTL0, 0x0000000c); in rtw8822c_dpk_coef_write()
2688 rtw_write32(rtwdev, REG_RXSRAM_CTL, 0x000000f0); in rtw8822c_dpk_coef_write()
2699 rtw_write32(rtwdev, reg[path] + addr * 4, coef); in rtw8822c_dpk_coef_write()
2703 static void rtw8822c_dpk_fill_result(struct rtw_dev *rtwdev, u32 dpk_txagc, in rtw8822c_dpk_fill_result() argument
2706 struct rtw_dpk_info *dpk_info = &rtwdev->dm_info.dpk_info; in rtw8822c_dpk_fill_result()
2708 rtw_write32_mask(rtwdev, REG_NCTL0, BIT_SUBPAGE, 0x8 | (path << 1)); in rtw8822c_dpk_fill_result()
2711 rtw_write8(rtwdev, REG_DPD_AGC, (u8)(dpk_txagc - 6)); in rtw8822c_dpk_fill_result()
2713 rtw_write8(rtwdev, REG_DPD_AGC, 0x00); in rtw8822c_dpk_fill_result()
2716 dpk_info->dpk_txagc[path] = rtw_read8(rtwdev, REG_DPD_AGC); in rtw8822c_dpk_fill_result()
2718 rtw8822c_dpk_coef_write(rtwdev, path, result); in rtw8822c_dpk_fill_result()
2721 static u32 rtw8822c_dpk_gainloss(struct rtw_dev *rtwdev, u8 path) in rtw8822c_dpk_gainloss() argument
2723 struct rtw_dpk_info *dpk_info = &rtwdev->dm_info.dpk_info; in rtw8822c_dpk_gainloss()
2726 ori_txbb = rtw8822c_dpk_rf_setting(rtwdev, path); in rtw8822c_dpk_gainloss()
2727 ori_txagc = (u8)rtw_read_rf(rtwdev, path, RF_MODE_TRXAGC, BIT_TXAGC); in rtw8822c_dpk_gainloss()
2729 rtw8822c_dpk_rxbb_dc_cal(rtwdev, path); in rtw8822c_dpk_gainloss()
2730 rtw8822c_dpk_one_shot(rtwdev, path, RTW_DPK_DAGC); in rtw8822c_dpk_gainloss()
2731 rtw8822c_dpk_dgain_read(rtwdev, path); in rtw8822c_dpk_gainloss()
2733 if (rtw8822c_dpk_dc_corr_check(rtwdev, path)) { in rtw8822c_dpk_gainloss()
2734 rtw8822c_dpk_rxbb_dc_cal(rtwdev, path); in rtw8822c_dpk_gainloss()
2735 rtw8822c_dpk_one_shot(rtwdev, path, RTW_DPK_DAGC); in rtw8822c_dpk_gainloss()
2736 rtw8822c_dpk_dc_corr_check(rtwdev, path); in rtw8822c_dpk_gainloss()
2739 t1 = rtw8822c_dpk_thermal_read(rtwdev, path); in rtw8822c_dpk_gainloss()
2740 tx_bb = rtw8822c_dpk_pas_agc(rtwdev, path, false, true); in rtw8822c_dpk_gainloss()
2741 tx_agc_search = rtw8822c_dpk_gainloss_result(rtwdev, path); in rtw8822c_dpk_gainloss()
2748 rtw_write_rf(rtwdev, path, RF_TX_GAIN, BIT_GAIN_TXBB, tx_bb); in rtw8822c_dpk_gainloss()
2752 t2 = rtw8822c_dpk_thermal_read(rtwdev, path); in rtw8822c_dpk_gainloss()
2759 static u8 rtw8822c_dpk_by_path(struct rtw_dev *rtwdev, u32 tx_agc, u8 path) in rtw8822c_dpk_by_path() argument
2763 result = rtw8822c_dpk_one_shot(rtwdev, path, RTW_DPK_DO_DPK); in rtw8822c_dpk_by_path()
2765 rtw_write32_mask(rtwdev, REG_NCTL0, BIT_SUBPAGE, 0x8 | (path << 1)); in rtw8822c_dpk_by_path()
2767 result = result | (u8)rtw_read32_mask(rtwdev, REG_DPD_CTL1_S0, BIT(26)); in rtw8822c_dpk_by_path()
2769 rtw_write_rf(rtwdev, path, RF_MODE_TRXAGC, RFREG_MASK, 0x33e14); in rtw8822c_dpk_by_path()
2771 rtw8822c_dpk_get_coef(rtwdev, path); in rtw8822c_dpk_by_path()
2776 static void rtw8822c_dpk_cal_gs(struct rtw_dev *rtwdev, u8 path) in rtw8822c_dpk_cal_gs() argument
2778 struct rtw_dpk_info *dpk_info = &rtwdev->dm_info.dpk_info; in rtw8822c_dpk_cal_gs()
2781 rtw_write32_mask(rtwdev, REG_NCTL0, BIT_SUBPAGE, 0x8 | (path << 1)); in rtw8822c_dpk_cal_gs()
2782 rtw_write32_mask(rtwdev, REG_IQK_CTL1, BIT_BYPASS_DPD, 0x0); in rtw8822c_dpk_cal_gs()
2783 rtw_write32_mask(rtwdev, REG_IQK_CTL1, BIT_TX_CFIR, 0x0); in rtw8822c_dpk_cal_gs()
2784 rtw_write32_mask(rtwdev, REG_R_CONFIG, BIT_IQ_SWITCH, 0x9); in rtw8822c_dpk_cal_gs()
2785 rtw_write32_mask(rtwdev, REG_R_CONFIG, BIT_INNER_LB, 0x1); in rtw8822c_dpk_cal_gs()
2786 rtw_write32_mask(rtwdev, REG_NCTL0, BIT_SUBPAGE, 0xc); in rtw8822c_dpk_cal_gs()
2787 rtw_write32_mask(rtwdev, REG_RXSRAM_CTL, BIT_DPD_CLK, 0xf); in rtw8822c_dpk_cal_gs()
2790 rtw_write32_mask(rtwdev, REG_DPD_CTL0_S0, BIT_GS_PWSF, in rtw8822c_dpk_cal_gs()
2792 rtw_write32_mask(rtwdev, REG_DPD_CTL1_S0, BIT_DPD_EN, 0x1); in rtw8822c_dpk_cal_gs()
2794 rtw_write32_mask(rtwdev, REG_DPD_CTL0_S1, BIT_GS_PWSF, in rtw8822c_dpk_cal_gs()
2796 rtw_write32_mask(rtwdev, REG_DPD_CTL1_S1, BIT_DPD_EN, 0x1); in rtw8822c_dpk_cal_gs()
2800 rtw_write32(rtwdev, REG_DPD_CTL16, 0x80001310); in rtw8822c_dpk_cal_gs()
2801 rtw_write32(rtwdev, REG_DPD_CTL16, 0x00001310); in rtw8822c_dpk_cal_gs()
2802 rtw_write32(rtwdev, REG_DPD_CTL16, 0x810000db); in rtw8822c_dpk_cal_gs()
2803 rtw_write32(rtwdev, REG_DPD_CTL16, 0x010000db); in rtw8822c_dpk_cal_gs()
2804 rtw_write32(rtwdev, REG_DPD_CTL16, 0x0000b428); in rtw8822c_dpk_cal_gs()
2805 rtw_write32(rtwdev, REG_DPD_CTL15, in rtw8822c_dpk_cal_gs()
2808 rtw_write32(rtwdev, REG_DPD_CTL16, 0x8200190c); in rtw8822c_dpk_cal_gs()
2809 rtw_write32(rtwdev, REG_DPD_CTL16, 0x0200190c); in rtw8822c_dpk_cal_gs()
2810 rtw_write32(rtwdev, REG_DPD_CTL16, 0x8301ee14); in rtw8822c_dpk_cal_gs()
2811 rtw_write32(rtwdev, REG_DPD_CTL16, 0x0301ee14); in rtw8822c_dpk_cal_gs()
2812 rtw_write32(rtwdev, REG_DPD_CTL16, 0x0000b428); in rtw8822c_dpk_cal_gs()
2813 rtw_write32(rtwdev, REG_DPD_CTL15, in rtw8822c_dpk_cal_gs()
2817 rtw_write32_mask(rtwdev, REG_DPD_CTL0, MASKBYTE3, 0x8 | path); in rtw8822c_dpk_cal_gs()
2819 rtw8822c_dpk_one_shot(rtwdev, path, RTW_DPK_CAL_PWR); in rtw8822c_dpk_cal_gs()
2821 rtw_write32_mask(rtwdev, REG_DPD_CTL15, MASKBYTE3, 0x0); in rtw8822c_dpk_cal_gs()
2822 rtw_write32_mask(rtwdev, REG_NCTL0, BIT_SUBPAGE, 0x8 | (path << 1)); in rtw8822c_dpk_cal_gs()
2823 rtw_write32_mask(rtwdev, REG_R_CONFIG, BIT_IQ_SWITCH, 0x0); in rtw8822c_dpk_cal_gs()
2824 rtw_write32_mask(rtwdev, REG_R_CONFIG, BIT_INNER_LB, 0x0); in rtw8822c_dpk_cal_gs()
2825 rtw_write32_mask(rtwdev, REG_NCTL0, BIT_SUBPAGE, 0xc); in rtw8822c_dpk_cal_gs()
2828 rtw_write32_mask(rtwdev, REG_DPD_CTL0_S0, BIT_GS_PWSF, 0x5b); in rtw8822c_dpk_cal_gs()
2830 rtw_write32_mask(rtwdev, REG_DPD_CTL0_S1, BIT_GS_PWSF, 0x5b); in rtw8822c_dpk_cal_gs()
2832 rtw_write32_mask(rtwdev, REG_RXSRAM_CTL, BIT_RPT_SEL, 0x0); in rtw8822c_dpk_cal_gs()
2834 tmp_gs = (u16)rtw_read32_mask(rtwdev, REG_STAT_RPT, BIT_RPT_DGAIN); in rtw8822c_dpk_cal_gs()
2839 rtw_write32_mask(rtwdev, REG_DPD_CTL0_S0, BIT_GS_PWSF, tmp_gs); in rtw8822c_dpk_cal_gs()
2841 rtw_write32_mask(rtwdev, REG_DPD_CTL0_S1, BIT_GS_PWSF, tmp_gs); in rtw8822c_dpk_cal_gs()
2846 void rtw8822c_dpk_cal_coef1(struct rtw_dev *rtwdev) in rtw8822c_dpk_cal_coef1() argument
2848 struct rtw_dpk_info *dpk_info = &rtwdev->dm_info.dpk_info; in rtw8822c_dpk_cal_coef1()
2853 rtw_write32_mask(rtwdev, REG_NCTL0, BIT_SUBPAGE, 0x0000000c); in rtw8822c_dpk_cal_coef1()
2854 rtw_write32(rtwdev, REG_RXSRAM_CTL, 0x000000f0); in rtw8822c_dpk_cal_coef1()
2855 rtw_write32(rtwdev, REG_NCTL0, 0x00001148); in rtw8822c_dpk_cal_coef1()
2856 rtw_write32(rtwdev, REG_NCTL0, 0x00001149); in rtw8822c_dpk_cal_coef1()
2858 check_hw_ready(rtwdev, 0x2d9c, MASKBYTE0, 0x55); in rtw8822c_dpk_cal_coef1()
2860 rtw_write8(rtwdev, 0x1b10, 0x0); in rtw8822c_dpk_cal_coef1()
2861 rtw_write32_mask(rtwdev, REG_NCTL0, BIT_SUBPAGE, 0x0000000c); in rtw8822c_dpk_cal_coef1()
2863 for (path = 0; path < rtwdev->hal.rf_path_num; path++) { in rtw8822c_dpk_cal_coef1()
2866 rtw_write32_mask(rtwdev, 0x1b18 + offset[path], MASKHWORD, in rtw8822c_dpk_cal_coef1()
2868 rtw_write32_mask(rtwdev, REG_DPD_CTL0_S0 + offset[path], in rtw8822c_dpk_cal_coef1()
2870 rtw_write32_mask(rtwdev, REG_DPD_CTL0_S0 + offset[path], in rtw8822c_dpk_cal_coef1()
2872 rtw_write32_mask(rtwdev, REG_DPD_CTL0_S0 + offset[path], in rtw8822c_dpk_cal_coef1()
2874 rtw_write32_mask(rtwdev, REG_DPD_CTL1_S0 + offset[path], in rtw8822c_dpk_cal_coef1()
2879 static void rtw8822c_dpk_on(struct rtw_dev *rtwdev, u8 path) in rtw8822c_dpk_on() argument
2881 struct rtw_dpk_info *dpk_info = &rtwdev->dm_info.dpk_info; in rtw8822c_dpk_on()
2883 rtw8822c_dpk_one_shot(rtwdev, path, RTW_DPK_DPK_ON); in rtw8822c_dpk_on()
2885 rtw_write32_mask(rtwdev, REG_NCTL0, BIT_SUBPAGE, 0x8 | (path << 1)); in rtw8822c_dpk_on()
2886 rtw_write32_mask(rtwdev, REG_IQK_CTL1, BIT_TX_CFIR, 0x0); in rtw8822c_dpk_on()
2889 rtw8822c_dpk_cal_gs(rtwdev, path); in rtw8822c_dpk_on()
2892 static bool rtw8822c_dpk_check_pass(struct rtw_dev *rtwdev, bool is_fail, in rtw8822c_dpk_check_pass() argument
2898 if (rtw8822c_dpk_coef_read(rtwdev, path)) in rtw8822c_dpk_check_pass()
2906 rtw8822c_dpk_fill_result(rtwdev, dpk_txagc, path, result); in rtw8822c_dpk_check_pass()
2911 static void rtw8822c_dpk_result_reset(struct rtw_dev *rtwdev) in rtw8822c_dpk_result_reset() argument
2913 struct rtw_dpk_info *dpk_info = &rtwdev->dm_info.dpk_info; in rtw8822c_dpk_result_reset()
2916 for (path = 0; path < rtwdev->hal.rf_path_num; path++) { in rtw8822c_dpk_result_reset()
2918 rtw_write32_mask(rtwdev, REG_NCTL0, BIT_SUBPAGE, in rtw8822c_dpk_result_reset()
2920 rtw_write32_mask(rtwdev, 0x1b58, 0x0000007f, 0x0); in rtw8822c_dpk_result_reset()
2926 dpk_info->thermal_dpk[path] = rtw8822c_dpk_thermal_read(rtwdev, in rtw8822c_dpk_result_reset()
2931 static void rtw8822c_dpk_calibrate(struct rtw_dev *rtwdev, u8 path) in rtw8822c_dpk_calibrate() argument
2933 struct rtw_dpk_info *dpk_info = &rtwdev->dm_info.dpk_info; in rtw8822c_dpk_calibrate()
2937 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DPK] s%d dpk start\n", path); in rtw8822c_dpk_calibrate()
2939 dpk_txagc = rtw8822c_dpk_gainloss(rtwdev, path); in rtw8822c_dpk_calibrate()
2941 dpk_fail = rtw8822c_dpk_by_path(rtwdev, dpk_txagc, path); in rtw8822c_dpk_calibrate()
2943 if (!rtw8822c_dpk_check_pass(rtwdev, dpk_fail, dpk_txagc, path)) in rtw8822c_dpk_calibrate()
2944 rtw_err(rtwdev, "failed to do dpk calibration\n"); in rtw8822c_dpk_calibrate()
2946 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DPK] s%d dpk finish\n", path); in rtw8822c_dpk_calibrate()
2952 static void rtw8822c_dpk_path_select(struct rtw_dev *rtwdev) in rtw8822c_dpk_path_select() argument
2954 rtw8822c_dpk_calibrate(rtwdev, RF_PATH_A); in rtw8822c_dpk_path_select()
2955 rtw8822c_dpk_calibrate(rtwdev, RF_PATH_B); in rtw8822c_dpk_path_select()
2956 rtw8822c_dpk_on(rtwdev, RF_PATH_A); in rtw8822c_dpk_path_select()
2957 rtw8822c_dpk_on(rtwdev, RF_PATH_B); in rtw8822c_dpk_path_select()
2958 rtw8822c_dpk_cal_coef1(rtwdev); in rtw8822c_dpk_path_select()
2961 static void rtw8822c_dpk_enable_disable(struct rtw_dev *rtwdev) in rtw8822c_dpk_enable_disable() argument
2963 struct rtw_dpk_info *dpk_info = &rtwdev->dm_info.dpk_info; in rtw8822c_dpk_enable_disable()
2966 rtw_write32_mask(rtwdev, REG_NCTL0, BIT_SUBPAGE, 0xc); in rtw8822c_dpk_enable_disable()
2968 rtw_write32_mask(rtwdev, REG_DPD_CTL1_S0, BIT_DPD_EN, in rtw8822c_dpk_enable_disable()
2970 rtw_write32_mask(rtwdev, REG_DPD_CTL1_S1, BIT_DPD_EN, in rtw8822c_dpk_enable_disable()
2974 rtw_write32_mask(rtwdev, REG_DPD_CTL1_S0, mask, 0x0); in rtw8822c_dpk_enable_disable()
2975 rtw_write8(rtwdev, REG_DPD_CTL0_S0, dpk_info->dpk_gs[RF_PATH_A]); in rtw8822c_dpk_enable_disable()
2978 rtw_write32_mask(rtwdev, REG_DPD_CTL1_S1, mask, 0x0); in rtw8822c_dpk_enable_disable()
2979 rtw_write8(rtwdev, REG_DPD_CTL0_S1, dpk_info->dpk_gs[RF_PATH_B]); in rtw8822c_dpk_enable_disable()
2983 static void rtw8822c_dpk_reload_data(struct rtw_dev *rtwdev) in rtw8822c_dpk_reload_data() argument
2985 struct rtw_dpk_info *dpk_info = &rtwdev->dm_info.dpk_info; in rtw8822c_dpk_reload_data()
2993 for (path = 0; path < rtwdev->hal.rf_path_num; path++) { in rtw8822c_dpk_reload_data()
2994 rtw_write32_mask(rtwdev, REG_NCTL0, BIT_SUBPAGE, in rtw8822c_dpk_reload_data()
2997 rtw_write32(rtwdev, REG_DPD_LUT3, 0x1f100000); in rtw8822c_dpk_reload_data()
2999 rtw_write32(rtwdev, REG_DPD_LUT3, 0x1f0d0000); in rtw8822c_dpk_reload_data()
3001 rtw_write8(rtwdev, REG_DPD_AGC, dpk_info->dpk_txagc[path]); in rtw8822c_dpk_reload_data()
3003 rtw8822c_dpk_coef_write(rtwdev, path, in rtw8822c_dpk_reload_data()
3006 rtw8822c_dpk_one_shot(rtwdev, path, RTW_DPK_DPK_ON); in rtw8822c_dpk_reload_data()
3008 rtw_write32_mask(rtwdev, REG_NCTL0, BIT_SUBPAGE, 0xc); in rtw8822c_dpk_reload_data()
3011 rtw_write32_mask(rtwdev, REG_DPD_CTL0_S0, BIT_GS_PWSF, in rtw8822c_dpk_reload_data()
3014 rtw_write32_mask(rtwdev, REG_DPD_CTL0_S1, BIT_GS_PWSF, in rtw8822c_dpk_reload_data()
3017 rtw8822c_dpk_cal_coef1(rtwdev); in rtw8822c_dpk_reload_data()
3020 static bool rtw8822c_dpk_reload(struct rtw_dev *rtwdev) in rtw8822c_dpk_reload() argument
3022 struct rtw_dpk_info *dpk_info = &rtwdev->dm_info.dpk_info; in rtw8822c_dpk_reload()
3027 channel = (u8)(rtw_read_rf(rtwdev, RF_PATH_A, 0x18, RFREG_MASK) & 0xff); in rtw8822c_dpk_reload()
3030 rtw_dbg(rtwdev, RTW_DBG_RFK, in rtw8822c_dpk_reload()
3032 rtw8822c_dpk_reload_data(rtwdev); in rtw8822c_dpk_reload()
3039 static void rtw8822c_do_dpk(struct rtw_dev *rtwdev) in rtw8822c_do_dpk() argument
3041 struct rtw_dpk_info *dpk_info = &rtwdev->dm_info.dpk_info; in rtw8822c_do_dpk()
3053 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DPK] Skip DPK due to DPD PWR off\n"); in rtw8822c_do_dpk()
3055 } else if (rtw8822c_dpk_reload(rtwdev)) { in rtw8822c_do_dpk()
3062 rtw8822c_dpk_information(rtwdev); in rtw8822c_do_dpk()
3064 rtw8822c_dpk_backup_registers(rtwdev, bb_reg, DPK_BB_REG_NUM, bckp); in rtw8822c_do_dpk()
3065 rtw8822c_dpk_backup_rf_registers(rtwdev, rf_reg, rf_reg_backup); in rtw8822c_do_dpk()
3067 rtw8822c_dpk_mac_bb_setting(rtwdev); in rtw8822c_do_dpk()
3068 rtw8822c_dpk_afe_setting(rtwdev, true); in rtw8822c_do_dpk()
3069 rtw8822c_dpk_pre_setting(rtwdev); in rtw8822c_do_dpk()
3070 rtw8822c_dpk_result_reset(rtwdev); in rtw8822c_do_dpk()
3071 rtw8822c_dpk_path_select(rtwdev); in rtw8822c_do_dpk()
3072 rtw8822c_dpk_afe_setting(rtwdev, false); in rtw8822c_do_dpk()
3073 rtw8822c_dpk_enable_disable(rtwdev); in rtw8822c_do_dpk()
3075 rtw8822c_dpk_reload_rf_registers(rtwdev, rf_reg, rf_reg_backup); in rtw8822c_do_dpk()
3076 for (path = 0; path < rtwdev->hal.rf_path_num; path++) in rtw8822c_do_dpk()
3077 rtw8822c_dpk_rxbb_dc_cal(rtwdev, path); in rtw8822c_do_dpk()
3078 rtw8822c_dpk_restore_registers(rtwdev, DPK_BB_REG_NUM, bckp); in rtw8822c_do_dpk()
3081 static void rtw8822c_phy_calibration(struct rtw_dev *rtwdev) in rtw8822c_phy_calibration() argument
3083 rtw8822c_do_iqk(rtwdev); in rtw8822c_phy_calibration()
3084 rtw8822c_do_dpk(rtwdev); in rtw8822c_phy_calibration()
3087 void rtw8822c_dpk_track(struct rtw_dev *rtwdev) in rtw8822c_dpk_track() argument
3089 struct rtw_dpk_info *dpk_info = &rtwdev->dm_info.dpk_info; in rtw8822c_dpk_track()
3098 thermal_value[path] = rtw8822c_dpk_thermal_read(rtwdev, path); in rtw8822c_dpk_track()
3110 rtw_write32_mask(rtwdev, REG_NCTL0, BIT_SUBPAGE, in rtw8822c_dpk_track()
3112 rtw_write32_mask(rtwdev, 0x1b58, GENMASK(6, 0), in rtw8822c_dpk_track()
3136 rtw8822c_phy_cck_pd_set_reg(struct rtw_dev *rtwdev, in rtw8822c_phy_cck_pd_set_reg() argument
3144 pd = rtw_read32_mask(rtwdev, in rtw8822c_phy_cck_pd_set_reg()
3147 cs = rtw_read32_mask(rtwdev, in rtw8822c_phy_cck_pd_set_reg()
3158 rtw_write32_mask(rtwdev, in rtw8822c_phy_cck_pd_set_reg()
3162 rtw_write32_mask(rtwdev, in rtw8822c_phy_cck_pd_set_reg()
3168 static void rtw8822c_phy_cck_pd_set(struct rtw_dev *rtwdev, u8 new_lvl) in rtw8822c_phy_cck_pd_set() argument
3170 struct rtw_dm_info *dm_info = &rtwdev->dm_info; in rtw8822c_phy_cck_pd_set()
3176 nrx = (u8)rtw_read32_mask(rtwdev, 0x1a2c, 0x60000); in rtw8822c_phy_cck_pd_set()
3177 bw = (u8)rtw_read32_mask(rtwdev, 0x9b0, 0xc); in rtw8822c_phy_cck_pd_set()
3187 rtw8822c_phy_cck_pd_set_reg(rtwdev, in rtw8822c_phy_cck_pd_set()