17 #include <linux/kernel.h>
30 #define PLL_2064_NDIV 90
31 #define PLL_2064_LOW_END_VCO 3000
32 #define PLL_2064_LOW_END_KVCO 27
33 #define PLL_2064_HIGH_END_VCO 4200
34 #define PLL_2064_HIGH_END_KVCO 68
35 #define PLL_2064_LOOP_BW_DOUBLER 200
36 #define PLL_2064_D30_DOUBLER 10500
37 #define PLL_2064_LOOP_BW 260
38 #define PLL_2064_D30 8000
39 #define PLL_2064_CAL_REF_TO 8
40 #define PLL_2064_MHZ 1000000
41 #define PLL_2064_OPEN_LOOP_DELAY 5
46 #define NOISE_IF_UPD_CHK_INTERVAL 1
47 #define NOISE_IF_UPD_RST_INTERVAL 60
48 #define NOISE_IF_UPD_THRESHOLD_CNT 1
49 #define NOISE_IF_UPD_TRHRESHOLD 50
50 #define NOISE_IF_UPD_TIMEOUT 1000
51 #define NOISE_IF_OFF 0
52 #define NOISE_IF_CHK 1
55 #define PAPD_BLANKING_PROFILE 3
57 #define PAPD_CORR_NORM 0
58 #define PAPD_BLANKING_THRESHOLD 0
59 #define PAPD_STOP_AFTER_LAST_UPDATE 0
61 #define LCN_TARGET_PWR 60
63 #define LCN_VBAT_OFFSET_433X 34649679
64 #define LCN_VBAT_SLOPE_433X 8258032
66 #define LCN_VBAT_SCALE_NOM 53
67 #define LCN_VBAT_SCALE_DEN 432
69 #define LCN_TEMPSENSE_OFFSET 80812
70 #define LCN_TEMPSENSE_DEN 2647
72 #define LCN_BW_LMT 200
73 #define LCN_CUR_LMT 1250
75 #define LCN_VCO_DIV 30
76 #define LCN_OFFSET 680
78 #define LCN_CUR_DIV 2640
80 #define LCNPHY_txgainctrlovrval1_pagain_ovr_val1_SHIFT \
82 #define LCNPHY_txgainctrlovrval1_pagain_ovr_val1_MASK \
83 (0x7f << LCNPHY_txgainctrlovrval1_pagain_ovr_val1_SHIFT)
85 #define LCNPHY_stxtxgainctrlovrval1_pagain_ovr_val1_SHIFT \
87 #define LCNPHY_stxtxgainctrlovrval1_pagain_ovr_val1_MASK \
88 (0x7f << LCNPHY_stxtxgainctrlovrval1_pagain_ovr_val1_SHIFT)
90 #define wlc_lcnphy_enable_tx_gain_override(pi) \
91 wlc_lcnphy_set_tx_gain_override(pi, true)
92 #define wlc_lcnphy_disable_tx_gain_override(pi) \
93 wlc_lcnphy_set_tx_gain_override(pi, false)
95 #define wlc_lcnphy_iqcal_active(pi) \
96 (read_phy_reg((pi), 0x451) & \
97 ((0x1 << 15) | (0x1 << 14)))
99 #define txpwrctrl_off(pi) (0x7 != ((read_phy_reg(pi, 0x4a4) & 0xE000) >> 13))
100 #define wlc_lcnphy_tempsense_based_pwr_ctrl_enabled(pi) \
101 (pi->temppwrctrl_capable)
102 #define wlc_lcnphy_tssi_based_pwr_ctrl_enabled(pi) \
103 (pi->hwpwrctrl_capable)
105 #define SWCTRL_BT_TX 0x18
106 #define SWCTRL_OVR_DISABLE 0x40
108 #define AFE_CLK_INIT_MODE_TXRX2X 1
109 #define AFE_CLK_INIT_MODE_PAPD 0
111 #define LCNPHY_TBL_ID_IQLOCAL 0x00
113 #define LCNPHY_TBL_ID_RFSEQ 0x08
114 #define LCNPHY_TBL_ID_GAIN_IDX 0x0d
115 #define LCNPHY_TBL_ID_SW_CTRL 0x0f
116 #define LCNPHY_TBL_ID_GAIN_TBL 0x12
117 #define LCNPHY_TBL_ID_SPUR 0x14
118 #define LCNPHY_TBL_ID_SAMPLEPLAY 0x15
119 #define LCNPHY_TBL_ID_SAMPLEPLAY1 0x16
121 #define LCNPHY_TX_PWR_CTRL_RATE_OFFSET 832
122 #define LCNPHY_TX_PWR_CTRL_MAC_OFFSET 128
123 #define LCNPHY_TX_PWR_CTRL_GAIN_OFFSET 192
124 #define LCNPHY_TX_PWR_CTRL_IQ_OFFSET 320
125 #define LCNPHY_TX_PWR_CTRL_LO_OFFSET 448
126 #define LCNPHY_TX_PWR_CTRL_PWR_OFFSET 576
128 #define LCNPHY_TX_PWR_CTRL_START_INDEX_2G_4313 140
130 #define LCNPHY_TX_PWR_CTRL_START_NPT 1
131 #define LCNPHY_TX_PWR_CTRL_MAX_NPT 7
133 #define LCNPHY_NOISE_SAMPLES_DEFAULT 5000
135 #define LCNPHY_ACI_DETECT_START 1
136 #define LCNPHY_ACI_DETECT_PROGRESS 2
137 #define LCNPHY_ACI_DETECT_STOP 3
139 #define LCNPHY_ACI_CRSHIFRMLO_TRSH 100
140 #define LCNPHY_ACI_GLITCH_TRSH 2000
141 #define LCNPHY_ACI_TMOUT 250
142 #define LCNPHY_ACI_DETECT_TIMEOUT 2
143 #define LCNPHY_ACI_START_DELAY 0
145 #define wlc_lcnphy_tx_gain_override_enabled(pi) \
146 (0 != (read_phy_reg((pi), 0x43b) & (0x1 << 6)))
148 #define wlc_lcnphy_total_tx_frames(pi) \
149 wlapi_bmac_read_shm((pi)->sh->physhim, M_UCODE_MACSTAT + \
150 offsetof(struct macstat, txallfrm))
202 {0, 0, 0, 0, 0, 0, 0, 0, 0},
206 tbl_iqcal_gainparams_lcnphy_2G,
209 static const u16 iqcal_gainparams_numgains_lcnphy[1] = {
231 u16 lcnphy_iqcal_loft_gainladder[] = {
255 u16 lcnphy_iqcal_ir_gainladder[] = {
315 u16 iqlo_loopback_rf_regs[20] = {
339 u16 tempsense_phy_regs[14] = {
357 u16 rxiq_cal_rf_reg[11] = {
426 static const u32 lcnphy_23bitgaincode_table[] = {
466 static const s8 lcnphy_gain_table[] = {
506 static const s8 lcnphy_gain_index_offset_for_rssi[] = {
561 {1, 2412, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
562 {2, 2417, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
563 {3, 2422, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
564 {4, 2427, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
565 {5, 2432, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
566 {6, 2437, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
567 {7, 2442, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
568 {8, 2447, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
569 {9, 2452, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
570 {10, 2457, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
571 {11, 2462, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
572 {12, 2467, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
573 {13, 2472, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
574 {14, 2484, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
579 {0x01, 0x64, 0x64, 0, 0},
580 {0x02, 0x20, 0x20, 0, 0},
581 {0x03, 0x66, 0x66, 0, 0},
582 {0x04, 0xf8, 0xf8, 0, 0},
584 {0x06, 0x10, 0x10, 0, 0},
588 {0x0A, 0x37, 0x37, 0, 0},
589 {0x0B, 0x6, 0x6, 0, 0},
590 {0x0C, 0x55, 0x55, 0, 0},
591 {0x0D, 0x8b, 0x8b, 0, 0},
593 {0x0F, 0x5, 0x5, 0, 0},
595 {0x11, 0xe, 0xe, 0, 0},
597 {0x13, 0xb, 0xb, 0, 0},
598 {0x14, 0x2, 0x2, 0, 0},
599 {0x15, 0x12, 0x12, 0, 0},
600 {0x16, 0x12, 0x12, 0, 0},
601 {0x17, 0xc, 0xc, 0, 0},
602 {0x18, 0xc, 0xc, 0, 0},
603 {0x19, 0xc, 0xc, 0, 0},
604 {0x1A, 0x8, 0x8, 0, 0},
605 {0x1B, 0x2, 0x2, 0, 0},
607 {0x1D, 0x1, 0x1, 0, 0},
608 {0x1E, 0x12, 0x12, 0, 0},
609 {0x1F, 0x6e, 0x6e, 0, 0},
610 {0x20, 0x2, 0x2, 0, 0},
611 {0x21, 0x23, 0x23, 0, 0},
612 {0x22, 0x8, 0x8, 0, 0},
615 {0x25, 0xc, 0xc, 0, 0},
616 {0x26, 0x33, 0x33, 0, 0},
617 {0x27, 0x55, 0x55, 0, 0},
619 {0x29, 0x30, 0x30, 0, 0},
620 {0x2A, 0xb, 0xb, 0, 0},
621 {0x2B, 0x1b, 0x1b, 0, 0},
622 {0x2C, 0x3, 0x3, 0, 0},
623 {0x2D, 0x1b, 0x1b, 0, 0},
625 {0x2F, 0x20, 0x20, 0, 0},
626 {0x30, 0xa, 0xa, 0, 0},
628 {0x32, 0x62, 0x62, 0, 0},
629 {0x33, 0x19, 0x19, 0, 0},
630 {0x34, 0x33, 0x33, 0, 0},
631 {0x35, 0x77, 0x77, 0, 0},
633 {0x37, 0x70, 0x70, 0, 0},
634 {0x38, 0x3, 0x3, 0, 0},
635 {0x39, 0xf, 0xf, 0, 0},
636 {0x3A, 0x6, 0x6, 0, 0},
637 {0x3B, 0xcf, 0xcf, 0, 0},
638 {0x3C, 0x1a, 0x1a, 0, 0},
639 {0x3D, 0x6, 0x6, 0, 0},
640 {0x3E, 0x42, 0x42, 0, 0},
642 {0x40, 0xfb, 0xfb, 0, 0},
643 {0x41, 0x9a, 0x9a, 0, 0},
644 {0x42, 0x7a, 0x7a, 0, 0},
645 {0x43, 0x29, 0x29, 0, 0},
647 {0x45, 0x8, 0x8, 0, 0},
648 {0x46, 0xce, 0xce, 0, 0},
649 {0x47, 0x27, 0x27, 0, 0},
650 {0x48, 0x62, 0x62, 0, 0},
651 {0x49, 0x6, 0x6, 0, 0},
652 {0x4A, 0x58, 0x58, 0, 0},
653 {0x4B, 0xf7, 0xf7, 0, 0},
655 {0x4D, 0xb3, 0xb3, 0, 0},
657 {0x4F, 0x2, 0x2, 0, 0},
659 {0x51, 0x9, 0x9, 0, 0},
660 {0x52, 0x5, 0x5, 0, 0},
661 {0x53, 0x17, 0x17, 0, 0},
662 {0x54, 0x38, 0x38, 0, 0},
665 {0x57, 0xb, 0xb, 0, 0},
672 {0x5E, 0x88, 0x88, 0, 0},
673 {0x5F, 0xcc, 0xcc, 0, 0},
674 {0x60, 0x74, 0x74, 0, 0},
675 {0x61, 0x74, 0x74, 0, 0},
676 {0x62, 0x74, 0x74, 0, 0},
677 {0x63, 0x44, 0x44, 0, 0},
678 {0x64, 0x77, 0x77, 0, 0},
679 {0x65, 0x44, 0x44, 0, 0},
680 {0x66, 0x77, 0x77, 0, 0},
681 {0x67, 0x55, 0x55, 0, 0},
682 {0x68, 0x77, 0x77, 0, 0},
683 {0x69, 0x77, 0x77, 0, 0},
685 {0x6B, 0x7f, 0x7f, 0, 0},
686 {0x6C, 0x8, 0x8, 0, 0},
688 {0x6E, 0x88, 0x88, 0, 0},
689 {0x6F, 0x66, 0x66, 0, 0},
690 {0x70, 0x66, 0x66, 0, 0},
691 {0x71, 0x28, 0x28, 0, 0},
692 {0x72, 0x55, 0x55, 0, 0},
693 {0x73, 0x4, 0x4, 0, 0},
697 {0x77, 0x1, 0x1, 0, 0},
698 {0x78, 0xd6, 0xd6, 0, 0},
709 {0x83, 0xb4, 0xb4, 0, 0},
710 {0x84, 0x1, 0x1, 0, 0},
711 {0x85, 0x20, 0x20, 0, 0},
712 {0x86, 0x5, 0x5, 0, 0},
713 {0x87, 0xff, 0xff, 0, 0},
714 {0x88, 0x7, 0x7, 0, 0},
715 {0x89, 0x77, 0x77, 0, 0},
716 {0x8A, 0x77, 0x77, 0, 0},
717 {0x8B, 0x77, 0x77, 0, 0},
718 {0x8C, 0x77, 0x77, 0, 0},
719 {0x8D, 0x8, 0x8, 0, 0},
720 {0x8E, 0xa, 0xa, 0, 0},
721 {0x8F, 0x8, 0x8, 0, 0},
722 {0x90, 0x18, 0x18, 0, 0},
723 {0x91, 0x5, 0x5, 0, 0},
724 {0x92, 0x1f, 0x1f, 0, 0},
725 {0x93, 0x10, 0x10, 0, 0},
726 {0x94, 0x3, 0x3, 0, 0},
729 {0x97, 0xaa, 0xaa, 0, 0},
731 {0x99, 0x23, 0x23, 0, 0},
732 {0x9A, 0x7, 0x7, 0, 0},
733 {0x9B, 0xf, 0xf, 0, 0},
734 {0x9C, 0x10, 0x10, 0, 0},
735 {0x9D, 0x3, 0x3, 0, 0},
736 {0x9E, 0x4, 0x4, 0, 0},
737 {0x9F, 0x20, 0x20, 0, 0},
742 {0xA4, 0x1, 0x1, 0, 0},
743 {0xA5, 0x77, 0x77, 0, 0},
744 {0xA6, 0x77, 0x77, 0, 0},
745 {0xA7, 0x77, 0x77, 0, 0},
746 {0xA8, 0x77, 0x77, 0, 0},
747 {0xA9, 0x8c, 0x8c, 0, 0},
748 {0xAA, 0x88, 0x88, 0, 0},
749 {0xAB, 0x78, 0x78, 0, 0},
750 {0xAC, 0x57, 0x57, 0, 0},
751 {0xAD, 0x88, 0x88, 0, 0},
753 {0xAF, 0x8, 0x8, 0, 0},
754 {0xB0, 0x88, 0x88, 0, 0},
756 {0xB2, 0x1b, 0x1b, 0, 0},
757 {0xB3, 0x3, 0x3, 0, 0},
758 {0xB4, 0x24, 0x24, 0, 0},
759 {0xB5, 0x3, 0x3, 0, 0},
760 {0xB6, 0x1b, 0x1b, 0, 0},
761 {0xB7, 0x24, 0x24, 0, 0},
762 {0xB8, 0x3, 0x3, 0, 0},
764 {0xBA, 0xaa, 0xaa, 0, 0},
766 {0xBC, 0x4, 0x4, 0, 0},
768 {0xBE, 0x8, 0x8, 0, 0},
769 {0xBF, 0x11, 0x11, 0, 0},
772 {0xC2, 0x62, 0x62, 0, 0},
773 {0xC3, 0x1e, 0x1e, 0, 0},
774 {0xC4, 0x33, 0x33, 0, 0},
775 {0xC5, 0x37, 0x37, 0, 0},
777 {0xC7, 0x70, 0x70, 0, 0},
778 {0xC8, 0x1e, 0x1e, 0, 0},
779 {0xC9, 0x6, 0x6, 0, 0},
780 {0xCA, 0x4, 0x4, 0, 0},
781 {0xCB, 0x2f, 0x2f, 0, 0},
782 {0xCC, 0xf, 0xf, 0, 0},
784 {0xCE, 0xff, 0xff, 0, 0},
785 {0xCF, 0x8, 0x8, 0, 0},
786 {0xD0, 0x3f, 0x3f, 0, 0},
787 {0xD1, 0x3f, 0x3f, 0, 0},
788 {0xD2, 0x3f, 0x3f, 0, 0},
792 {0xD6, 0xcc, 0xcc, 0, 0},
794 {0xD8, 0x8, 0x8, 0, 0},
795 {0xD9, 0x8, 0x8, 0, 0},
796 {0xDA, 0x8, 0x8, 0, 0},
797 {0xDB, 0x11, 0x11, 0, 0},
799 {0xDD, 0x87, 0x87, 0, 0},
800 {0xDE, 0x88, 0x88, 0, 0},
801 {0xDF, 0x8, 0x8, 0, 0},
802 {0xE0, 0x8, 0x8, 0, 0},
803 {0xE1, 0x8, 0x8, 0, 0},
807 {0xE5, 0xf5, 0xf5, 0, 0},
808 {0xE6, 0x30, 0x30, 0, 0},
809 {0xE7, 0x1, 0x1, 0, 0},
811 {0xE9, 0xff, 0xff, 0, 0},
814 {0xEC, 0x22, 0x22, 0, 0},
818 {0xF0, 0x3, 0x3, 0, 0},
819 {0xF1, 0x1, 0x1, 0, 0},
825 {0xF7, 0x6, 0x6, 0, 0},
828 {0xFA, 0x40, 0x40, 0, 0},
830 {0xFC, 0x1, 0x1, 0, 0},
831 {0xFD, 0x80, 0x80, 0, 0},
832 {0xFE, 0x2, 0x2, 0, 0},
833 {0xFF, 0x10, 0x10, 0, 0},
834 {0x100, 0x2, 0x2, 0, 0},
835 {0x101, 0x1e, 0x1e, 0, 0},
836 {0x102, 0x1e, 0x1e, 0, 0},
838 {0x104, 0x1f, 0x1f, 0, 0},
839 {0x105, 0, 0x8, 0, 1},
840 {0x106, 0x2a, 0x2a, 0, 0},
841 {0x107, 0xf, 0xf, 0, 0},
862 {0x11C, 0x1, 0x1, 0, 0},
868 {0x122, 0x80, 0x80, 0, 0},
870 {0x124, 0xf8, 0xf8, 0, 0},
886 #define LCNPHY_NUM_DIG_FILT_COEFFS 16
887 #define LCNPHY_NUM_TX_DIG_FILTERS_CCK 13
891 {0, 1, 415, 1874, 64, 128, 64, 792, 1656, 64, 128, 64, 778, 1582, 64,
893 {1, 1, 402, 1847, 259, 59, 259, 671, 1794, 68, 54, 68, 608, 1863, 93,
895 {2, 1, 415, 1874, 64, 128, 64, 792, 1656, 192, 384, 192, 778, 1582, 64,
897 {3, 1, 302, 1841, 129, 258, 129, 658, 1720, 205, 410, 205, 754, 1760,
899 {20, 1, 360, 1884, 242, 1734, 242, 752, 1720, 205, 1845, 205, 767, 1760,
901 {21, 1, 360, 1884, 149, 1874, 149, 752, 1720, 205, 1883, 205, 767, 1760,
903 {22, 1, 360, 1884, 98, 1948, 98, 752, 1720, 205, 1924, 205, 767, 1760,
905 {23, 1, 350, 1884, 116, 1966, 116, 752, 1720, 205, 2008, 205, 767, 1760,
907 {24, 1, 325, 1884, 32, 40, 32, 756, 1720, 256, 471, 256, 766, 1760, 256,
909 {25, 1, 299, 1884, 51, 64, 51, 736, 1720, 256, 471, 256, 765, 1760, 256,
911 {26, 1, 277, 1943, 39, 117, 88, 637, 1838, 64, 192, 144, 614, 1864, 128,
913 {27, 1, 245, 1943, 49, 147, 110, 626, 1838, 256, 768, 576, 613, 1864,
915 {30, 1, 302, 1841, 61, 122, 61, 658, 1720, 205, 410, 205, 754, 1760,
919 #define LCNPHY_NUM_TX_DIG_FILTERS_OFDM 3
922 {0, 0, 0xa2, 0x0, 0x100, 0x100, 0x0, 0x0, 0x0, 0x100, 0x0, 0x0,
923 0x278, 0xfea0, 0x80, 0x100, 0x80,},
924 {1, 0, 374, 0xFF79, 16, 32, 16, 799, 0xFE74, 50, 32, 50,
925 750, 0xFE2B, 212, 0xFFCE, 212,},
926 {2, 0, 375, 0xFF16, 37, 76, 37, 799, 0xFE74, 32, 20, 32, 748,
927 0xFEF2, 128, 0xFFE2, 128}
930 #define wlc_lcnphy_set_start_tx_pwr_idx(pi, idx) \
931 mod_phy_reg(pi, 0x4a4, \
935 #define wlc_lcnphy_set_tx_pwr_npt(pi, npt) \
936 mod_phy_reg(pi, 0x4a5, \
940 #define wlc_lcnphy_get_tx_pwr_ctrl(pi) \
941 (read_phy_reg((pi), 0x4a4) & \
946 #define wlc_lcnphy_get_tx_pwr_npt(pi) \
947 ((read_phy_reg(pi, 0x4a5) & \
951 #define wlc_lcnphy_get_current_tx_pwr_idx_if_pwrctrl_on(pi) \
952 (read_phy_reg(pi, 0x473) & 0x1ff)
954 #define wlc_lcnphy_get_target_tx_pwr(pi) \
955 ((read_phy_reg(pi, 0x4a7) & \
959 #define wlc_lcnphy_set_target_tx_pwr(pi, target) \
960 mod_phy_reg(pi, 0x4a7, \
964 #define wlc_radio_2064_rcal_done(pi) \
965 (0 != (read_radio_reg(pi, RADIO_2064_REG05C) & 0x20))
967 #define tempsense_done(pi) \
968 (0x8000 == (read_phy_reg(pi, 0x476) & 0x8000))
970 #define LCNPHY_IQLOCC_READ(val) \
971 ((u8)(-(s8)(((val) & 0xf0) >> 4) + (s8)((val) & 0x0f)))
973 #define FIXED_TXPWR 78
974 #define LCNPHY_TEMPSENSE(val) ((s16)((val > 255) ? (val - 512) : val))
987 wlc_lcnphy_common_read_table(
struct brcms_phy *pi,
u32 tbl_id,
988 const u16 *tbl_ptr,
u32 tbl_len,
989 u32 tbl_width,
u32 tbl_offset)
1020 quotient = dividend /
divisor;
1021 remainder = dividend %
divisor;
1023 roundup = (divisor >> 1) + rbit;
1025 while (precision--) {
1027 if (remainder >= roundup) {
1029 remainder = ((remainder -
roundup) << 1) + rbit;
1035 if (remainder >= roundup)
1041 static int wlc_lcnphy_calc_floor(
s16 coeff_x,
int type)
1047 k = (coeff_x - 1) / 2;
1053 if ((coeff_x + 1) < 0)
1056 k = (coeff_x + 1) / 2;
1064 u16 dac_gain, rfgain0, rfgain1;
1067 gains->
dac_gain = (dac_gain & 0x380) >> 7;
1069 rfgain0 = (
read_phy_reg(pi, 0x4b5) & (0xffff << 0)) >> 0;
1070 rfgain1 = (
read_phy_reg(pi, 0x4fb) & (0x7fff << 0)) >> 0;
1072 gains->
gm_gain = rfgain0 & 0xff;
1073 gains->
pga_gain = (rfgain0 >> 8) & 0xff;
1078 static void wlc_lcnphy_set_dac_gain(
struct brcms_phy *pi,
u16 dac_gain)
1083 dac_ctrl = dac_ctrl & 0xc7f;
1084 dac_ctrl = dac_ctrl | (dac_gain << 7);
1085 mod_phy_reg(pi, 0x439, (0xfff << 0), (dac_ctrl) << 0);
1089 static void wlc_lcnphy_set_tx_gain_override(
struct brcms_phy *pi,
bool bEnable)
1091 u16 bit = bEnable ? 1 : 0;
1103 u16 ebit = enable ? 1 : 0;
1127 wlc_lcnphy_set_rx_gain_by_distribution(
struct brcms_phy *pi,
1134 u16 gain0_15, gain16_19;
1136 gain16_19 = biq2 & 0xf;
1137 gain0_15 = ((biq1 & 0xf) << 12) |
1138 ((tia & 0xf) << 8) |
1139 ((lna2 & 0x3) << 6) |
1141 0x3) << 4) | ((lna1 & 0x3) << 2) | ((lna1 & 0x3) << 0);
1143 mod_phy_reg(pi, 0x4b6, (0xffff << 0), gain0_15 << 0);
1144 mod_phy_reg(pi, 0x4b7, (0xf << 0), gain16_19 << 0);
1149 mod_phy_reg(pi, 0x4b1, (0x1 << 10), ext_lna << 10);
1162 static void wlc_lcnphy_set_trsw_override(
struct brcms_phy *pi,
bool tx,
bool rx)
1167 (0x1 << 0), (tx ? (0x1 << 1) : 0) | (rx ? (0x1 << 0) : 0));
1169 or_phy_reg(pi, 0x44c, (0x1 << 1) | (0x1 << 0));
1172 static void wlc_lcnphy_clear_trsw_override(
struct brcms_phy *pi)
1195 wlc_lcnphy_rx_iq_est(
struct brcms_phy *pi,
1208 mod_phy_reg(pi, 0x482, (0xffff << 0), (num_samps) << 0);
1218 if (wait_count > (10 * 500)) {
1241 static bool wlc_lcnphy_calc_rx_iq_comp(
struct brcms_phy *pi,
u16 num_samps)
1243 #define LCNPHY_MIN_RXIQ_PWR 2
1248 s16 iq_nbits, qq_nbits, arsh, brsh;
1253 a0_new = ((
read_phy_reg(pi, 0x645) & (0x3ff << 0)) >> 0);
1254 b0_new = ((
read_phy_reg(pi, 0x646) & (0x3ff << 0)) >> 0);
1259 wlc_lcnphy_set_rx_iq_comp(pi, 0, 0);
1261 result = wlc_lcnphy_rx_iq_est(pi, num_samps, 32, &iq_est);
1277 arsh = 10 - (30 - iq_nbits);
1279 a = (-(iq << (30 - iq_nbits)) + (ii >> (1 + arsh)));
1280 temp = (
s32) (ii >> arsh);
1284 a = (-(iq << (30 - iq_nbits)) + (ii << (-1 - arsh)));
1285 temp = (
s32) (ii << -arsh);
1290 brsh = qq_nbits - 31 + 20;
1292 b = (qq << (31 - qq_nbits));
1293 temp = (
s32) (ii >> brsh);
1297 b = (qq << (31 - qq_nbits));
1298 temp = (
s32) (ii << -brsh);
1306 a0_new = (
u16) (a & 0x3ff);
1307 b0_new = (
u16) (b & 0x3ff);
1310 wlc_lcnphy_set_rx_iq_comp(pi, a0_new, b0_new);
1322 static u32 wlc_lcnphy_measure_digital_power(
struct brcms_phy *pi,
u16 nsamples)
1326 if (!wlc_lcnphy_rx_iq_est(pi, nsamples, 32, &iq_est))
1328 return (iq_est.
i_pwr + iq_est.
q_pwr) / nsamples;
1332 wlc_lcnphy_rx_iq_cal(
struct brcms_phy *pi,
1334 int iqcomp_sz,
bool tx_switch,
bool rx_switch,
int module,
1339 u8 tx_gain_index_old = 0;
1340 bool result =
false, tx_gain_override_old =
false;
1341 u16 i, Core1TxControl_old, RFOverride0_old,
1342 RFOverrideVal0_old, rfoverride2_old, rfoverride2val_old,
1343 rfoverride3_old, rfoverride3val_old, rfoverride4_old,
1344 rfoverride4val_old, afectrlovr_old, afectrlovrval_old;
1346 u32 received_power, rx_pwr_threshold;
1347 u16 old_sslpnCalibClkEnCtrl, old_sslpnRxFeClkEnCtrl;
1348 u16 values_to_save[11];
1356 while (iqcomp_sz--) {
1357 if (iqcomp[iqcomp_sz].
chan ==
1359 wlc_lcnphy_set_rx_iq_comp(pi,
1361 iqcomp[iqcomp_sz].a,
1363 iqcomp[iqcomp_sz].b);
1376 for (i = 0; i < 11; i++)
1397 if (tx_gain_override_old) {
1398 wlc_lcnphy_get_tx_gain(pi, &old_gains);
1438 wlc_lcnphy_set_trsw_override(pi, tx_switch, rx_switch);
1439 wlc_lcnphy_rx_gain_override_enable(pi,
true);
1442 rx_pwr_threshold = 950;
1443 while (tia_gain > 0) {
1445 wlc_lcnphy_set_rx_gain_by_distribution(pi,
1452 wlc_lcnphy_measure_digital_power(pi, 2000);
1453 if (received_power < rx_pwr_threshold)
1456 result = wlc_lcnphy_calc_rx_iq_comp(pi, 0xffff);
1475 wlc_lcnphy_clear_trsw_override(pi);
1479 for (i = 0; i < 11; i++)
1483 if (tx_gain_override_old)
1489 wlc_lcnphy_rx_gain_override_enable(pi,
false);
1514 u16 afectrlovr, afectrlovrval;
1543 static void wlc_lcnphy_toggle_afe_pwdn(
struct brcms_phy *pi)
1545 u16 save_AfeCtrlOvrVal, save_AfeCtrlOvr;
1561 wlc_lcnphy_txrx_spur_avoidance_mode(
struct brcms_phy *pi,
bool enable)
1581 wlc_lcnphy_set_chanspec_tweaks(
struct brcms_phy *pi,
u16 chanspec)
1595 if (channel == 1 || channel == 2 || channel == 3 ||
1596 channel == 4 || channel == 9 ||
1597 channel == 10 || channel == 11 || channel == 12) {
1604 wlc_lcnphy_txrx_spur_avoidance_mode(pi,
false);
1616 wlc_lcnphy_txrx_spur_avoidance_mode(pi,
true);
1629 wlc_lcnphy_radio_2064_channel_tune_4313(
struct brcms_phy *pi,
u8 channel)
1632 const struct chan_info_2064_lcnphy *ci;
1633 u8 rfpll_doubler = 0;
1634 u8 pll_pwrup, pll_pwrup_ovr;
1635 s32 qFxtal, qFref, qFvco, qFcal;
1636 u8 d15, d16, f16, e44, e45;
1637 u32 div_int, div_frac, fvco3, fpfd, fref3, fcal_div;
1638 u16 loop_bw, d30, setCount;
1640 u8 h29, h28_ten, e30, h30_ten, cp_current;
1643 ci = &chan_info_2064_lcnphy[0];
1649 if (!rfpll_doubler) {
1658 for (i = 0; i <
ARRAY_SIZE(chan_info_2064_lcnphy); i++)
1659 if (chan_info_2064_lcnphy[i].
chan == channel)
1665 ci = &chan_info_2064_lcnphy[
i];
1706 fvco3 = (ci->
freq * 3);
1710 qFref = wlc_lcnphy_qdiv_roundup(fpfd,
PLL_2064_MHZ, 16);
1712 qFvco = wlc_lcnphy_qdiv_roundup(fvco3, 2, 16);
1720 d16 = (qFcal * 8 / (d15 + 1)) - 1;
1723 f16 = ((d16 + 1) * (d15 + 1)) / qFcal;
1724 setCount = f16 * 3 * (ci->
freq) / 32 - 1;
1726 (
u8) (setCount >> 8));
1731 div_int = ((fvco3 * (
PLL_2064_MHZ >> 4)) / fref3) << 4;
1733 div_frac = ((fvco3 * (
PLL_2064_MHZ >> 4)) % fref3) << 4;
1734 while (div_frac >= fref3) {
1738 div_frac = wlc_lcnphy_qdiv_roundup(div_frac, fref3, 20);
1741 (
u8) (div_int >> 4));
1743 (
u8) (div_int << 4));
1745 (
u8) (div_frac >> 16));
1767 if (channel >= 1 && channel <= 5)
1787 wlc_lcnphy_load_tx_iir_filter(
struct brcms_phy *pi,
bool is_ofdm,
s16 filt_type)
1789 s16 filt_index = -1;
1832 if (filt_type == LCNPHY_txdigfiltcoeffs_cck[j][0]) {
1833 filt_index = (
s16) j;
1838 if (filt_index != -1) {
1841 LCNPHY_txdigfiltcoeffs_cck
1842 [filt_index][j + 1]);
1846 if (filt_type == LCNPHY_txdigfiltcoeffs_ofdm[j][0]) {
1847 filt_index = (
s16) j;
1852 if (filt_index != -1) {
1855 LCNPHY_txdigfiltcoeffs_ofdm
1856 [filt_index][j + 1]);
1860 return (filt_index != -1) ? 0 : -1;
1874 wlc_lcnphy_radio_2064_channel_tune_4313(pi, channel);
1877 wlc_lcnphy_toggle_afe_pwdn(pi);
1879 write_phy_reg(pi, 0x657, lcnphy_sfo_cfg[channel - 1].ptcentreTs20);
1880 write_phy_reg(pi, 0x658, lcnphy_sfo_cfg[channel - 1].ptcentreFactor);
1885 wlc_lcnphy_load_tx_iir_filter(pi,
false, 3);
1889 wlc_lcnphy_load_tx_iir_filter(pi,
false, 2);
1892 wlc_lcnphy_load_tx_iir_filter(pi,
true, 0);
1898 static u16 wlc_lcnphy_get_pa_gain(
struct brcms_phy *pi)
1909 static void wlc_lcnphy_set_tx_gain(
struct brcms_phy *pi,
1912 u16 pa_gain = wlc_lcnphy_get_pa_gain(pi);
1922 ((target_gains->
pad_gain) | (pa_gain << 8)) << 0);
1932 ((target_gains->
pad_gain) | (pa_gain << 8)) << 0);
1934 wlc_lcnphy_set_dac_gain(pi, target_gains->
dac_gain);
1939 static void wlc_lcnphy_set_bbmult(
struct brcms_phy *pi,
u8 m0)
1941 u16 m0m1 = (
u16) m0 << 8;
1947 tab.tbl_offset = 87;
1952 static void wlc_lcnphy_clear_tx_power_offsets(
struct brcms_phy *pi)
1957 memset(data_buf, 0,
sizeof(data_buf));
1961 tab.tbl_ptr = data_buf;
2021 static u16 wlc_lcnphy_rfseq_tbl_adc_pwrup(
struct brcms_phy *pi)
2023 u16 N1,
N2, N3, N4, N5, N6,
N;
2036 N = 2 * (N1 + N2 + N3 + N4 + 2 * (N5 + N6)) + 80;
2042 static void wlc_lcnphy_pwrctrl_rssiparams(
struct brcms_phy *pi)
2044 u16 auxpga_vmid, auxpga_vmid_temp, auxpga_gain_temp;
2047 auxpga_vmid = (2 << 8) |
2049 auxpga_vmid_temp = (2 << 8) | (8 << 4) | 4;
2050 auxpga_gain_temp = 2;
2076 (auxpga_vmid_temp << 0) | (auxpga_gain_temp << 12));
2081 (auxpga_vmid_temp << 0) | (auxpga_gain_temp << 12));
2086 static void wlc_lcnphy_tssi_setup(
struct brcms_phy *pi)
2096 for (ind = 0; ind < 128; ind++) {
2100 tab.tbl_offset = 704;
2101 for (ind = 0; ind < 128; ind++) {
2138 wlc_lcnphy_clear_tx_power_offsets(pi);
2142 mod_phy_reg(pi, 0x4a6, (0x1ff << 0), (0xff) << 0);
2144 mod_phy_reg(pi, 0x49a, (0x1ff << 0), (0xff) << 0);
2176 (0x1 << 3) | (0x7 << 12), 0 << 3 | 2 << 12);
2178 rfseq = wlc_lcnphy_rfseq_tbl_adc_pwrup(pi);
2181 tab.tbl_ptr = &rfseq;
2196 wlc_lcnphy_pwrctrl_rssiparams(pi);
2201 u16 tx_cnt, tx_total, npt;
2208 if (tx_cnt > (1 << npt)) {
2222 a = 32768 + (a1 * tssi);
2223 b = (1024 * b0) + (64 * b1 * tssi);
2224 p = ((2 *
b) + a) / (2 *
a);
2229 static void wlc_lcnphy_txpower_reset_npt(
struct brcms_phy *pi)
2248 for (i = 0, j = 0; i <
ARRAY_SIZE(rate_table); i++, j++) {
2266 wlc_lcnphy_txpower_reset_npt(pi);
2270 static void wlc_lcnphy_set_tx_pwr_soft_ctrl(
struct brcms_phy *pi,
s8 index)
2272 u32 cck_offset[4] = { 22, 22, 22, 22 };
2273 u32 ofdm_offset, reg_offset_cck;
2288 for (i = 0; i < 4; i++)
2289 cck_offset[i] -= reg_offset_cck;
2293 tab.tbl_ptr = cck_offset;
2298 tab.tbl_ptr = &ofdm_offset;
2299 for (i = 836; i < 862; i++) {
2316 index2 = (
u16) (index * 2);
2317 mod_phy_reg(pi, 0x4a9, (0x1ff << 0), (index2) << 0);
2323 static s8 wlc_lcnphy_tempcompensated_txpwrctrl(
struct brcms_phy *pi)
2325 s8 index, delta_brd, delta_temp, new_index, tempcorrx;
2326 s16 manp, meas_temp, temp_diff;
2348 temp_diff = manp - meas_temp;
2349 if (temp_diff < 0) {
2351 temp_diff = -temp_diff;
2354 delta_temp = (
s8) wlc_lcnphy_qdiv_roundup((
u32) (temp_diff * 192),
2359 delta_temp = -delta_temp;
2372 new_index += tempcorrx;
2377 if (new_index < 0 || new_index > 126)
2393 return current_mode;
2402 mode = wlc_lcnphy_set_tx_pwr_ctrl_mode(pi, mode);
2403 old_mode = wlc_lcnphy_set_tx_pwr_ctrl_mode(pi, old_mode);
2411 if (old_mode != mode) {
2416 wlc_lcnphy_clear_tx_power_offsets(pi);
2437 ((0x1 << 15) | (0x1 << 14) | (0x1 << 13)), mode);
2439 index = wlc_lcnphy_tempcompensated_txpwrctrl(pi);
2440 wlc_lcnphy_set_tx_pwr_soft_ctrl(pi, index);
2450 wlc_lcnphy_tx_iqlo_loopback(
struct brcms_phy *pi,
u16 *values_to_save)
2454 for (i = 0; i < 20; i++)
2541 static bool wlc_lcnphy_iqcal_wait(
struct brcms_phy *pi)
2543 uint delay_count = 0;
2549 if (delay_count > (10 * 500))
2557 wlc_lcnphy_tx_iqlo_loopback_cleanup(
struct brcms_phy *pi,
u16 *values_to_save)
2565 for (i = 0; i < 20; i++)
2571 wlc_lcnphy_tx_iqlo_cal(
struct brcms_phy *pi,
2580 u16 ncorr_override[5];
2581 u16 syst_coeffs[] = { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
2582 0x0000, 0x0000, 0x0000, 0x0000, 0x0000};
2584 u16 commands_fullcal[] = {
2585 0x8434, 0x8334, 0x8084, 0x8267, 0x8056, 0x8234
2588 u16 commands_recal[] = {
2589 0x8434, 0x8334, 0x8084, 0x8267, 0x8056, 0x8234
2592 u16 command_nums_fullcal[] = {
2593 0x7a97, 0x7a97, 0x7a97, 0x7a87, 0x7a87, 0x7b97
2596 u16 command_nums_recal[] = {
2597 0x7a97, 0x7a97, 0x7a97, 0x7a87, 0x7a87, 0x7b97
2599 u16 *command_nums = command_nums_fullcal;
2601 u16 *start_coeffs =
NULL, *cal_cmds =
NULL, cal_type, diq_start;
2602 u16 tx_pwr_ctrl_old, save_txpwrctrlrfctrl2;
2603 u16 save_sslpnCalibClkEnCtrl, save_sslpnRxFeClkEnCtrl;
2604 bool tx_gain_override_old;
2606 uint i, n_cal_cmds = 0, n_cal_start = 0;
2607 u16 *values_to_save;
2611 if (
NULL == values_to_save)
2622 start_coeffs = syst_coeffs;
2623 cal_cmds = commands_fullcal;
2628 start_coeffs = syst_coeffs;
2629 cal_cmds = commands_recal;
2631 command_nums = command_nums_recal;
2639 start_coeffs, 11, 16, 64);
2652 mod_phy_reg(pi, 0x4db, (0x3ff << 0), (0x2a6) << 0);
2656 wlc_lcnphy_tx_iqlo_loopback(pi, values_to_save);
2659 if (tx_gain_override_old)
2660 wlc_lcnphy_get_tx_gain(pi, &old_gains);
2662 if (!target_gains) {
2663 if (!tx_gain_override_old)
2666 wlc_lcnphy_get_tx_gain(pi, &temp_gains);
2667 target_gains = &temp_gains;
2670 hash = (target_gains->
gm_gain << 8) |
2675 cal_gains = *target_gains;
2676 memset(ncorr_override, 0,
sizeof(ncorr_override));
2677 for (j = 0; j < iqcal_gainparams_numgains_lcnphy[band_idx]; j++) {
2678 if (hash == tbl_iqcal_gainparams_lcnphy[band_idx][j][0]) {
2680 tbl_iqcal_gainparams_lcnphy[band_idx][
j][1];
2681 cal_gains.pga_gain =
2682 tbl_iqcal_gainparams_lcnphy[band_idx][
j][2];
2683 cal_gains.pad_gain =
2684 tbl_iqcal_gainparams_lcnphy[band_idx][
j][3];
2686 &tbl_iqcal_gainparams_lcnphy[band_idx][j][3],
2687 sizeof(ncorr_override));
2692 wlc_lcnphy_set_tx_gain(pi, &cal_gains);
2698 lcnphy_iqcal_loft_gainladder,
2703 lcnphy_iqcal_ir_gainladder,
2705 lcnphy_iqcal_ir_gainladder), 16,
2719 for (i = n_cal_start; i < n_cal_cmds; i++) {
2721 u16 best_coeffs[11];
2724 cal_type = (cal_cmds[
i] & 0x0f00) >> 8;
2726 command_num = command_nums[
i];
2727 if (ncorr_override[cal_type])
2729 ncorr_override[cal_type] << 8 | (command_num &
2734 if ((cal_type == 3) || (cal_type == 4)) {
2736 &diq_start, 1, 16, 69);
2739 &zero_diq, 1, 16, 69);
2744 if (!wlc_lcnphy_iqcal_wait(pi))
2754 if ((cal_type == 3) || (cal_type == 4))
2756 &diq_start, 1, 16, 69);
2759 txiqlocal_bestcoeffs,
2762 txiqlocal_bestcoeffs),
2768 txiqlocal_bestcoeffs,
2770 txiqlocal_bestcoeffs), 16, 96);
2775 txiqlocal_bestcoeffs[0], 4, 16, 80);
2779 txiqlocal_bestcoeffs[5], 2, 16, 85);
2782 wlc_lcnphy_tx_iqlo_loopback_cleanup(pi, values_to_save);
2783 kfree(values_to_save);
2792 if (tx_gain_override_old)
2793 wlc_lcnphy_set_tx_gain(pi, &old_gains);
2801 static void wlc_lcnphy_idle_tssi_est(
struct brcms_phy_pub *ppi)
2803 bool suspend, tx_gain_override_old;
2806 u16 idleTssi, idleTssi0_2C, idleTssi0_OB, idleTssi0_regvalue_OB,
2807 idleTssi0_regvalue_2C;
2810 u16 SAVE_jtag_bb_afe_switch =
2822 wlc_lcnphy_get_tx_gain(pi, &old_gains);
2830 wlc_lcnphy_tssi_setup(pi);
2835 idleTssi0_2C = ((
read_phy_reg(pi, 0x63e) & (0x1ff << 0))
2838 if (idleTssi0_2C >= 256)
2839 idleTssi0_OB = idleTssi0_2C - 256;
2841 idleTssi0_OB = idleTssi0_2C + 256;
2843 idleTssi0_regvalue_OB = idleTssi0_OB;
2844 if (idleTssi0_regvalue_OB >= 256)
2845 idleTssi0_regvalue_2C = idleTssi0_regvalue_OB - 256;
2847 idleTssi0_regvalue_2C = idleTssi0_regvalue_OB + 256;
2848 mod_phy_reg(pi, 0x4a6, (0x1ff << 0), (idleTssi0_regvalue_2C) << 0);
2852 wlc_lcnphy_set_tx_gain_override(pi, tx_gain_override_old);
2853 wlc_lcnphy_set_tx_gain(pi, &old_gains);
2865 static void wlc_lcnphy_vbat_temp_sense_setup(
struct brcms_phy *pi,
u8 mode)
2868 u16 save_txpwrCtrlEn;
2869 u8 auxpga_vmidcourse, auxpga_vmidfine, auxpga_gain;
2873 u8 save_reg007, save_reg0FF, save_reg11F, save_reg005, save_reg025,
2875 u16 values_to_save[14];
2888 for (i = 0; i < 14; i++)
2889 values_to_save[i] =
read_phy_reg(pi, tempsense_phy_regs[i]);
2948 val = wlc_lcnphy_rfseq_tbl_adc_pwrup(pi);
2960 auxpga_vmidcourse = 8;
2961 auxpga_vmidfine = 0x4;
2969 auxpga_vmidcourse = 7;
2970 auxpga_vmidfine = 0xa;
2974 (
u16) ((2 << 8) | (auxpga_vmidcourse << 4) | auxpga_vmidfine);
2977 mod_phy_reg(pi, 0x4d8, (0x3ff << 2), (auxpga_vmid) << 2);
2981 mod_phy_reg(pi, 0x4d8, (0x7 << 12), (auxpga_gain) << 12);
2997 for (i = 0; i < 14; i++)
2998 write_phy_reg(pi, tempsense_phy_regs[i], values_to_save[i]);
3007 static void wlc_lcnphy_tx_pwr_ctrl_init(
struct brcms_phy_pub *ppi)
3013 s32 tssi, pwr, maxtargetpwr, mintargetpwr;
3024 tx_gains.gm_gain = 4;
3025 tx_gains.pga_gain = 12;
3026 tx_gains.pad_gain = 12;
3027 tx_gains.dac_gain = 0;
3031 tx_gains.gm_gain = 7;
3032 tx_gains.pga_gain = 15;
3033 tx_gains.pad_gain = 14;
3034 tx_gains.dac_gain = 0;
3038 wlc_lcnphy_set_tx_gain(pi, &tx_gains);
3039 wlc_lcnphy_set_bbmult(pi, bbmult);
3040 wlc_lcnphy_vbat_temp_sense_setup(pi,
TEMPSENSE);
3043 wlc_lcnphy_idle_tssi_est(ppi);
3045 wlc_lcnphy_clear_tx_power_offsets(pi);
3058 for (tssi = 0; tssi < 128; tssi++) {
3061 pwr = (pwr < mintargetpwr) ? mintargetpwr : pwr;
3078 static u8 wlc_lcnphy_get_bbmult(
struct brcms_phy *pi)
3086 tab.tbl_offset = 87;
3090 return (
u8) ((m0m1 & 0xff00) >> 8);
3105 u8 *ei0,
u8 *eq0,
u8 *fi0,
u8 *fq0)
3146 u32 bbmultiqcomp, txgain, locoeffs, rfpower;
3171 gains.
dac_gain = (
u16) (bbmultiqcomp >> 28) & 0x07;
3172 wlc_lcnphy_set_tx_gain(pi, &gains);
3173 wlc_lcnphy_set_pa_gain(pi, (
u16) (txgain >> 24) & 0x7f);
3175 bb_mult = (
u8) ((bbmultiqcomp >> 20) & 0xff);
3176 wlc_lcnphy_set_bbmult(pi, bb_mult);
3182 a = (
u16) ((bbmultiqcomp >> 10) & 0x3ff);
3183 b = (
u16) (bbmultiqcomp & 0x3ff);
3195 mod_phy_reg(pi, 0x6a6, (0x1fff << 0), (rfpower * 8) << 0);
3200 static void wlc_lcnphy_clear_papd_comptable(
struct brcms_phy *pi)
3204 u32 temp_offset[128];
3211 memset(temp_offset, 0,
sizeof(temp_offset));
3212 for (j = 1; j < 128; j += 2)
3213 temp_offset[j] = 0x80000;
3228 ~(
u16) ((0x1 << 3) |
3231 (0x1 << 0) | (0x1 << 1) | (0x1 << 2)));
3234 ~(
u16) ((0x1 << 3) | (0x1 << 5) | (0x1 << 14)));
3237 mod_phy_reg(pi, 0x44d, (0x1 << 1) | (0x1 << 0), (0x1 << 0));
3240 ~(
u16) ((0x1 << 0) | (0x1 << 1) | (0x1 << 2)));
3243 ~(
u16) ((0x1 << 0) | (0x1 << 1) | (0x1 << 2)));
3255 wlc_lcnphy_set_trsw_override(pi,
true,
false);
3297 wlc_lcnphy_run_samples(
struct brcms_phy *pi,
3304 mod_phy_reg(pi, 0x642, (0x7f << 0), (num_samps - 1) << 0);
3305 if (num_loops != 0xffff)
3307 mod_phy_reg(pi, 0x640, (0xffff << 0), num_loops << 0);
3353 u16 num_samps,
t,
k;
3371 wlc_lcnphy_txrx_spur_avoidance_mode(pi,
false);
3377 bw = phy_bw * 1000 *
k;
3378 num_samps = bw /
abs(f_kHz);
3380 }
while ((num_samps * (
u32) (
abs(f_kHz))) != bw);
3384 rot = ((f_kHz * 36) / phy_bw) / 100;
3387 for (t = 0; t < num_samps; t++) {
3393 i_samp = (
u16) (
FLOAT(tone_samp.
i * max_val) & 0x3ff);
3394 q_samp = (
u16) (
FLOAT(tone_samp.
q * max_val) & 0x3ff);
3395 data_buf[
t] = (i_samp << 10) | q_samp;
3409 wlc_lcnphy_run_samples(pi, num_samps, 0xffff, 0, iqcalmode);
3414 s16 playback_status;
3422 wlc_lcnphy_txrx_spur_avoidance_mode(pi,
true);
3426 if (playback_status & (0x1 << 0)) {
3429 }
else if (playback_status & (0x1 << 1))
3444 wlc_lcnphy_set_cc(
struct brcms_phy *pi,
int cal_type,
s16 coeff_x,
s16 coeff_y)
3454 di0dq0 = (coeff_x & 0xff) << 8 | (coeff_y & 0xff);
3458 k = wlc_lcnphy_calc_floor(coeff_x, 0);
3460 k = wlc_lcnphy_calc_floor(coeff_x, 1);
3462 data_rf = (x * 16 +
y);
3464 k = wlc_lcnphy_calc_floor(coeff_y, 0);
3466 k = wlc_lcnphy_calc_floor(coeff_y, 1);
3468 data_rf = (x * 16 +
y);
3472 k = wlc_lcnphy_calc_floor(coeff_x, 0);
3474 k = wlc_lcnphy_calc_floor(coeff_x, 1);
3476 data_rf = (x * 16 +
y);
3478 k = wlc_lcnphy_calc_floor(coeff_y, 0);
3480 k = wlc_lcnphy_calc_floor(coeff_y, 1);
3482 data_rf = (x * 16 +
y);
3492 u8 di0, dq0, ei, eq, fi, fq;
3504 di0 = (((didq & 0xff00) << 16) >> 24);
3505 dq0 = (((didq & 0x00ff) << 24) >> 24);
3524 wlc_lcnphy_samp_cap(
struct brcms_phy *pi,
int clip_detect_algo,
u16 thresh,
3527 u32 curval1, curval2, stpptr, curptr, strptr,
val;
3529 u16 old_sslpnCalibClkEnCtrl;
3539 ((1 << 6) | curval1));
3569 }
while ((curptr != stpptr) && (timer < 500));
3574 while (strptr < 0x8000) {
3576 imag = ((val >> 16) & 0x3ff);
3577 real = ((
val) & 0x3ff);
3585 ptr[(strptr - 0x7E00) / 4] = real;
3587 ptr[(strptr - 0x7E00) / 4] = imag;
3589 if (clip_detect_algo) {
3590 if (imag > thresh || imag < -thresh) {
3605 wlc_lcnphy_a1(
struct brcms_phy *pi,
int cal_type,
int num_levels,
3611 int phy_c4, phy_c5,
k,
l,
j, phy_c6;
3612 u16 phy_c7, phy_c8, phy_c9;
3613 s16 phy_c10, phy_c11, phy_c12, phy_c13, phy_c14, phy_c15, phy_c16;
3615 s32 phy_c18, phy_c19;
3616 u32 phy_c20, phy_c21;
3617 bool phy_c22, phy_c23, phy_c24, phy_c25;
3618 u16 phy_c26, phy_c27;
3619 u16 phy_c28, phy_c29, phy_c30;
3623 phy_c10 = phy_c13 = phy_c14 = phy_c8 = 0;
3629 if (
NULL == phy_c32) {
3642 wlc_lcnphy_tx_iqlo_loopback(pi, phy_c32);
3655 phy_c1 = &lcnphy_spb_tone_3750[0];
3658 if (num_levels == 0) {
3664 if (step_size_lg2 == 0) {
3671 phy_c7 = (1 << step_size_lg2);
3672 phy_c3 = wlc_lcnphy_get_cc(pi, cal_type);
3673 phy_c15 = (
s16) phy_c3.re;
3674 phy_c16 = (
s16) phy_c3.im;
3675 if (cal_type == 2) {
3676 if (phy_c3.re > 127)
3677 phy_c15 = phy_c3.re - 256;
3678 if (phy_c3.im > 127)
3679 phy_c16 = phy_c3.im - 256;
3681 wlc_lcnphy_set_cc(pi, cal_type, phy_c15, phy_c16);
3683 for (phy_c8 = 0; phy_c7 != 0 && phy_c8 < num_levels; phy_c8++) {
3702 phy_c9 = 2 * phy_c9;
3708 (phy_c5 & 0x7) | ((phy_c5 & 0x7) << 4));
3712 wlc_lcnphy_samp_cap(pi, 1, phy_c9, &ptr[0], 2);
3717 if ((phy_c22 != phy_c24) && (!phy_c25))
3721 if (phy_c5 <= 0 || phy_c5 >= 7)
3729 else if (phy_c5 > 7)
3732 for (k = -phy_c7; k <= phy_c7; k += phy_c7) {
3733 for (l = -phy_c7; l <= phy_c7; l += phy_c7) {
3734 phy_c11 = phy_c15 +
k;
3735 phy_c12 = phy_c16 +
l;
3737 if (phy_c11 < -phy_c10)
3739 else if (phy_c11 > phy_c10)
3741 if (phy_c12 < -phy_c10)
3743 else if (phy_c12 > phy_c10)
3745 wlc_lcnphy_set_cc(pi, cal_type, phy_c11,
3748 wlc_lcnphy_samp_cap(pi, 0, 0, ptr, 2);
3752 for (j = 0; j < 128; j++) {
3754 phy_c6 = j % phy_c4;
3756 phy_c6 = (2 *
j) % phy_c4;
3758 phy_c2.re = phy_c1[phy_c6].
re;
3759 phy_c2.im = phy_c1[phy_c6].
im;
3761 phy_c18 = phy_c18 + phy_c17 * phy_c2.re;
3762 phy_c19 = phy_c19 + phy_c17 * phy_c2.im;
3765 phy_c18 = phy_c18 >> 10;
3766 phy_c19 = phy_c19 >> 10;
3767 phy_c20 = ((phy_c18 * phy_c18) +
3768 (phy_c19 * phy_c19));
3770 if (phy_c23 || phy_c20 < phy_c21) {
3781 phy_c7 = phy_c7 >> 1;
3782 wlc_lcnphy_set_cc(pi, cal_type, phy_c15, phy_c16);
3787 wlc_lcnphy_tx_iqlo_loopback_cleanup(pi, phy_c32);
3816 static void wlc_lcnphy_tx_iqlo_soft_cal_full(
struct brcms_phy *pi)
3820 wlc_lcnphy_set_cc(pi, 0, 0, 0);
3821 wlc_lcnphy_set_cc(pi, 2, 0, 0);
3822 wlc_lcnphy_set_cc(pi, 3, 0, 0);
3823 wlc_lcnphy_set_cc(pi, 4, 0, 0);
3825 wlc_lcnphy_a1(pi, 4, 0, 0);
3826 wlc_lcnphy_a1(pi, 3, 0, 0);
3827 wlc_lcnphy_a1(pi, 2, 3, 2);
3828 wlc_lcnphy_a1(pi, 0, 5, 8);
3829 wlc_lcnphy_a1(pi, 2, 2, 1);
3830 wlc_lcnphy_a1(pi, 0, 4, 3);
3832 iqcc0 = wlc_lcnphy_get_cc(pi, 0);
3833 locc2 = wlc_lcnphy_get_cc(pi, 2);
3834 locc3 = wlc_lcnphy_get_cc(pi, 3);
3835 locc4 = wlc_lcnphy_get_cc(pi, 4);
3853 static void wlc_lcnphy_txpwrtbl_iqlo_cal(
struct brcms_phy *pi)
3858 u16 a,
b, didq, save_pa_gain = 0;
3859 uint idx, SAVE_txpwrindex = 0xFF;
3863 u8 ei0, eq0, fi0, fq0;
3866 wlc_lcnphy_get_tx_gain(pi, &old_gains);
3867 save_pa_gain = wlc_lcnphy_get_pa_gain(pi);
3869 save_bb_mult = wlc_lcnphy_get_bbmult(pi);
3880 wlc_lcnphy_set_tx_gain(pi, &target_gains);
3887 wlc_lcnphy_tx_iqlo_cal(pi, &target_gains,
3892 wlc_lcnphy_tx_iqlo_soft_cal_full(pi);
3896 if ((
abs((
s8) fi0) == 15) && (
abs((
s8) fq0) == 15)) {
3915 wlc_lcnphy_tx_iqlo_cal(pi, &target_gains,
3918 wlc_lcnphy_tx_iqlo_soft_cal_full(pi);
3933 for (idx = 0; idx < 128; idx++) {
3937 val = (val & 0xfff00000) |
3938 ((
u32) (a & 0x3FF) << 10) | (b & 0x3ff);
3954 wlc_lcnphy_set_bbmult(pi, save_bb_mult);
3955 wlc_lcnphy_set_pa_gain(pi, save_pa_gain);
3956 wlc_lcnphy_set_tx_gain(pi, &old_gains);
3966 u16 tempsenseval1, tempsenseval2;
3968 bool suspend =
false;
3971 suspend = (0 == (bcma_read32(pi->
d11core,
3976 wlc_lcnphy_vbat_temp_sense_setup(pi,
TEMPSENSE);
3981 if (tempsenseval1 > 255)
3982 avg = (
s16) (tempsenseval1 - 512);
3984 avg = (
s16) tempsenseval1;
3986 if (tempsenseval2 > 255)
3987 avg += (
s16) (tempsenseval2 - 512);
3989 avg += (
s16) tempsenseval2;
4008 u16 tempsenseval1, tempsenseval2;
4010 bool suspend =
false;
4015 suspend = (0 == (bcma_read32(pi->
d11core,
4020 wlc_lcnphy_vbat_temp_sense_setup(pi,
TEMPSENSE);
4025 if (tempsenseval1 > 255)
4026 avg = (
int)(tempsenseval1 - 512);
4028 avg = (
int)tempsenseval1;
4031 if (tempsenseval2 > 255)
4032 avg = (
int)(avg - tempsenseval2 + 512);
4034 avg = (
int)(avg - tempsenseval2);
4036 if (tempsenseval2 > 255)
4037 avg = (
int)(avg + tempsenseval2 - 512);
4039 avg = (
int)(avg + tempsenseval2);
4046 avg = tempsenseval1;
4078 bool suspend =
false;
4081 suspend = (0 == (bcma_read32(pi->
d11core,
4086 wlc_lcnphy_vbat_temp_sense_setup(pi,
VBATSENSE);
4091 if (vbatsenseval > 255)
4092 avg = (
s32) (vbatsenseval - 512);
4094 avg = (
s32) vbatsenseval;
4106 static void wlc_lcnphy_afe_clk_init(
struct brcms_phy *pi,
u8 mode)
4117 wlc_lcnphy_toggle_afe_pwdn(pi);
4120 static void wlc_lcnphy_temp_adj(
struct brcms_phy *pi)
4124 static void wlc_lcnphy_glacial_timer_based_cal(
struct brcms_phy *pi)
4139 wlc_lcnphy_txpwrtbl_iqlo_cal(pi);
4149 static void wlc_lcnphy_periodic_cal(
struct brcms_phy *pi)
4158 s32 tssi, pwr, maxtargetpwr, mintargetpwr;
4178 wlc_lcnphy_txpwrtbl_iqlo_cal(pi);
4180 rx_iqcomp = lcnphy_rx_iqcomp_table_rev0;
4181 rx_iqcomp_sz =
ARRAY_SIZE(lcnphy_rx_iqcomp_table_rev0);
4184 wlc_lcnphy_rx_iq_cal(pi,
NULL, 0,
true,
false, 1, 40);
4186 wlc_lcnphy_rx_iq_cal(pi,
NULL, 0,
true,
false, 1, 127);
4203 for (tssi = 0; tssi < 128; tssi++) {
4205 pwr = (pwr < mintargetpwr) ? mintargetpwr : pwr;
4228 wlc_lcnphy_periodic_cal(pi);
4231 wlc_lcnphy_periodic_cal(pi);
4238 temp_diff = temp1 -
temp2;
4240 (temp_diff > 60) || (temp_diff < -60)) {
4241 wlc_lcnphy_glacial_timer_based_cal(pi);
4263 (status & (0x1 << 15))) {
4272 *cck_pwr = *ofdm_pwr + cck_offset;
4294 index = wlc_lcnphy_tempcompensated_txpwrctrl(pi);
4295 index2 = (
u16) (index * 2);
4296 mod_phy_reg(pi, 0x4a9, (0x1ff << 0), (index2) << 0);
4304 wlc_lcnphy_load_tx_gain_table(
struct brcms_phy *pi,
4325 for (j = 0; j < 128; j++) {
4326 gm_gain = gain_table[
j].
gm;
4327 val = (((
u32) pa_gain << 24) |
4328 (gain_table[
j].
pad << 16) |
4329 (gain_table[j].pga << 8) | gm_gain);
4334 val = (gain_table[
j].
dac << 28) | (gain_table[j].bb_mult << 20);
4340 static void wlc_lcnphy_load_rfpower(
struct brcms_phy *pi)
4345 u8 scale_factor = 1;
4352 for (index = 0; index < 128; index++) {
4353 tab.tbl_ptr = &bbmult;
4356 bbmult = bbmult >> 20;
4358 tab.tbl_ptr = &rfgain;
4366 temp2 =
qm_shr16(temp2, qQ2 - qQ1);
4369 temp1 =
qm_shr16(temp1, qQ1 - qQ2);
4379 val = (((index << shift) + (5 * temp) +
4380 (1 << (scale_factor + shift - 3))) >> (scale_factor +
4389 static void wlc_lcnphy_bu_tweaks(
struct brcms_phy *pi)
4408 if (!(pi->
sh->boardrev < 0x1204))
4435 wlc_lcnphy_clear_tx_power_offsets(pi);
4441 static void wlc_lcnphy_rcal(
struct brcms_phy *pi)
4461 rcal_value = rcal_value & 0x1f;
4469 static void wlc_lcnphy_rc_cal(
struct brcms_phy *pi)
4474 dflt_rc_cal_val = 7;
4476 dflt_rc_cal_val = 11;
4478 (dflt_rc_cal_val << 10) | (dflt_rc_cal_val << 5) |
4489 static void wlc_radio_2064_init(
struct brcms_phy *pi)
4494 lcnphyregs = lcnphy_radio_regs_2064;
4496 for (i = 0; lcnphyregs[
i].
address != 0xffff; i++)
4499 ((lcnphyregs[i].
address & 0x3fff) |
4504 ((lcnphyregs[i].
address & 0x3fff) |
4545 wlc_lcnphy_rcal(pi);
4547 wlc_lcnphy_rc_cal(pi);
4550 static void wlc_lcnphy_radio_init(
struct brcms_phy *pi)
4552 wlc_radio_2064_init(pi);
4555 static void wlc_lcnphy_tbl_init(
struct brcms_phy *pi)
4596 wlc_lcnphy_load_tx_gain_table(
4600 wlc_lcnphy_load_tx_gain_table(
4623 for (idx = 0; idx <
l; idx++)
4631 if (pi->
sh->boardrev < 0x1250)
4642 wlc_lcnphy_load_rfpower(pi);
4644 wlc_lcnphy_clear_papd_comptable(pi);
4647 static void wlc_lcnphy_rev0_baseband_init(
struct brcms_phy *pi)
4693 static void wlc_lcnphy_rev2_baseband_init(
struct brcms_phy *pi)
4701 static void wlc_lcnphy_agc_temp_init(
struct brcms_phy *pi)
4719 tab.tbl_ptr = tableBuffer;
4722 tab.tbl_offset = 59;
4726 if (tableBuffer[0] > 63)
4727 tableBuffer[0] -= 128;
4730 if (tableBuffer[1] > 63)
4731 tableBuffer[1] -= 128;
4744 tab.tbl_ptr = tableBuffer;
4747 tab.tbl_offset = 28;
4756 static void wlc_lcnphy_baseband_init(
struct brcms_phy *pi)
4759 wlc_lcnphy_tbl_init(pi);
4760 wlc_lcnphy_rev0_baseband_init(pi);
4762 wlc_lcnphy_rev2_baseband_init(pi);
4763 wlc_lcnphy_bu_tweaks(pi);
4784 wlc_lcnphy_baseband_init(pi);
4786 wlc_lcnphy_radio_init(pi);
4801 wlc_lcnphy_agc_temp_init(pi);
4803 wlc_lcnphy_temp_adj(pi);
4815 static bool wlc_phy_txpwr_srom_read_lcnphy(
struct brcms_phy *pi)
4824 u32 offset_ofdm, offset_mcs;
4857 uint max_pwr_chan = txpwr;
4861 max_pwr_chan - ((cckpo & 0xf) * 2);
4868 ((offset_ofdm & 0xf) * 2);
4881 ((offset_ofdm & 0xf) * 2);
4884 offset_mcs = sprom->
mcs2gpo[1] << 16;
4885 offset_mcs |= sprom->
mcs2gpo[0];
4890 txpwr - ((offset_mcs & 0xf) * 2);
4982 if (!wlc_phy_txpwr_srom_read_lcnphy(pi))
5003 u16 trsw, ext_lna, lna1, lna2, tia, biq0, biq1, gain0_15, gain16_19;
5005 trsw = (gain & ((
u32) 1 << 28)) ? 0 : 1;
5006 ext_lna = (
u16) (
gain >> 29) & 0x01;
5007 lna1 = (
u16) (
gain >> 0) & 0x0f;
5008 lna2 = (
u16) (
gain >> 4) & 0x0f;
5009 tia = (
u16) (
gain >> 8) & 0xf;
5010 biq0 = (
u16) (
gain >> 12) & 0xf;
5011 biq1 = (
u16) (
gain >> 16) & 0xf;
5013 gain0_15 = (
u16) ((lna1 & 0x3) | ((lna1 & 0x3) << 2) |
5014 ((lna2 & 0x3) << 4) | ((lna2 & 0x3) << 6) |
5015 ((tia & 0xf) << 8) | ((biq0 & 0xf) << 12));
5020 mod_phy_reg(pi, 0x4b1, (0x1 << 10), ext_lna << 10);
5021 mod_phy_reg(pi, 0x4b6, (0xffff << 0), gain0_15 << 0);
5022 mod_phy_reg(pi, 0x4b7, (0xf << 0), gain16_19 << 0);
5028 wlc_lcnphy_rx_gain_override_enable(pi,
true);
5031 static u32 wlc_lcnphy_get_receive_power(
struct brcms_phy *pi,
s32 *gain_index)
5033 u32 received_power = 0;
5039 if (*gain_index >= 0)
5040 gain_code = lcnphy_23bitgaincode_table[*gain_index];
5042 if (-1 == *gain_index) {
5044 while ((*gain_index <= (
s32) max_index)
5045 && (received_power < 700)) {
5046 wlc_lcnphy_set_rx_gain(pi,
5047 lcnphy_23bitgaincode_table
5050 wlc_lcnphy_measure_digital_power(
5058 wlc_lcnphy_set_rx_gain(pi, gain_code);
5060 wlc_lcnphy_measure_digital_power(pi,
5065 return received_power;
5071 s32 nominal_power_db;
5072 s32 log_val, gain_mismatch, desired_gain, input_power_offset_db,
5076 u32 msb1, msb2, val1, val2, diff1, diff2;
5080 received_power = wlc_lcnphy_get_receive_power(pi, &gain_index);
5082 gain = lcnphy_gain_table[gain_index];
5086 power = (received_power * 16);
5087 msb1 =
ffs(power) - 1;
5091 diff1 = (power - val1);
5092 diff2 = (val2 - power);
5098 log_val = log_val * 3;
5100 gain_mismatch = (nominal_power_db / 2) - (log_val);
5102 desired_gain = gain + gain_mismatch;
5104 input_power_offset_db =
read_phy_reg(pi, 0x434) & 0xFF;
5106 if (input_power_offset_db > 127)
5107 input_power_offset_db -= 256;
5109 input_power_db = input_power_offset_db - desired_gain;
5112 input_power_db + lcnphy_gain_index_offset_for_rssi[gain_index];
5115 if ((freq > 2427) && (freq <= 2467))
5116 input_power_db = input_power_db - 1;
5120 if ((temperature - 15) < -30)
5123 (((temperature - 10 - 25) * 286) >> 12) -
5125 else if ((temperature - 15) < 4)
5128 (((temperature - 10 - 25) * 286) >> 12) -
5131 input_power_db = input_power_db +
5132 (((temperature - 10 - 25) * 286) >> 12);
5134 wlc_lcnphy_rx_gain_override_enable(pi, 0);
5136 return input_power_db;