int N PHY Cal RX IQ Rev 2 (struct nphy_txgains target, bool debug)
- Establish a 3-element u16 array called lna and preset to {3, 3, 1}
- Establish a 3-element u16 array called hpf1 and preset to {7, 2, 0}
- Establish a 3-element u16 array called hpf2 and preset to {2, 0, 0}
- Establish a 3-element u32 array called power
- Establish a 2-element u16 array called gain_save
- Establish a 2-element u16 array called cal_gain
- Establish a 2-element struct nphy_iqcal_params array named cal_params
- Establish a struct nphy_iq_est variable named est
- Initialize int ret to 0
- Initialize bool playtone to 1
- Initialized desired to 13
Call N PHY Stay in Carrier Search with argument 1
If PHY Revision < 2
- Read an N PHY Table with ID 7, length 2, offset 0x110, width 16, and data gain_save
- Loop 2 times with index i
Call N PHY IQ Cal Gain Params with i, target, cal_params[i] as arguments
- Set cal_gain[i] to cal_params[i].cal_gain
- Write an N PHY Table with ID 7, length 2, offset 0x110, width 16, and data from cal_gain
- loop 2 times with index i
- Save PHY Register 0xA2 as tmp1
- Save PHY Register ((i == 0) ? 0xA6 : 0xA7) as tmp2
- Save PHY register 0xA5 as tmp3
- Save PHY Register ((i == 0) ? 0x91 : 0x92) as tmp4
- Save PHY Register ((i == 0) ? 0x92 : 0x91) as tmp5
Maskset PHY Register 0xA2 with mask 0x0FFF and set with (1 - i) << 12
- Maskset PHY Register 0xA2 with mask 0xFFF0 and set with (1 - i)
- Set bits 0x0006 in PHY Register ((i == 0) ? 0xA6 : 0xA7)
- Set bits 0x0006 in PHY Register 0xA5
If nphy_rxcalparams & 0xff000000 is not zero
- If the band if 5G
- Write 0x140 to PHY Register ((i == 0) ? 0x91 : 0x92)
- Otherwise
- Write 0x110 to PHY Register ((i == 0) ? 0x91 : 0x92)
- If the band if 5G
- Otherwise
- If the band if 5G
- Write 0x180 to PHY Register ((i == 0) ? 0x91 : 0x92)
- Otherwise
- Write 0x120 to PHY Register ((i == 0) ? 0x91 : 0x92)
- If the band if 5G
- If the band if 5G
- Write 0x148 to PHY Register ((i == 1) ? 0x91 : 0x92)
- Otherwise
- Write 0x114 to PHY Register ((i == 1) ? 0x91 : 0x92)
If nphy_rxcalparams & 0x10000 is not 0
- Maskset Radio Register 0xD6 with mask 0xFC and set with (i + 1)
- Maskset Radio Register 0xE2 with mask 0xFC and set with (2 - i)
- Loop 4 times with index j
If j < 3
- Set cur_lna to lna[j], cur_hpf1 to hpf1[j], and cur_hpf2 to hpf2[j]
- Otherwise
If power[1] > 10000
- Set cur_lna to lna[2], cur_hpf1 to hpf1[2], and cur_hpf2 to hpf2[2]
- Set use to 1
- Set cur_hpf to cur_hpf1
Set actual to number of bits in power[2]
- Otherwise
If power[0] > 10000
- Set cur_lna to lna[1], cur_hpf1 to hpf1[1], and cur_hpf2 to hpf2[1]
- Set use to 1
- Set cur_hpf to cur_hpf1
Set actual to number of bits in power[1]
- Otherwise
- Set cur_lna to lna[0], cur_hpf1 to hpf1[0], and cur_hpf2 to hpf2[0]
- Set use to 2
- Set cur_hpf to cur_hpf2
Set actual to number of bits in power[0]
- Set change to desired - actual
- Add change to cur_hpf
- Clamp cur_hpf between 0 and 10
- If use is 1
- Set cur_hpf1 to cur_hpf
- Otherwise
- Set cur_hpf2 to cur_hpf
Calculate tmp as ((cur_hpf2 << 8) | (cur_hpf1 << 4) | (cur_lna << 2))
Call N PHY RF Ctrl Override with 0x400, tmp, 3, 0 as arguments
Call N PHY Force RF Seq with 2 as argument
Call N PHT Stop Playback
- If playtone is not zero
Call N PHY TX Tone with 4000, (nphy_rxcalparams & 0xffff), 0, 0 as arguments and save result as ret
- Set playtone to 0
- Otherwise
Call N PHY Run Samples with 160, 0xFFFF, 0, 0, 0 as arguments
- If ret is zero
If j < 3
Call N PHY RX IQ Est with &est, 1024, 32, 0 as arguments
- If i is 0
- Set real to (est.i0_pwr + 512) / 1024
- Set imag to (est.q0_pwr + 512) / 1024
- Otherwise
- Set real to (est.i1_pwr + 512) / 1024
- Set imag to (est.q1_pwr + 512) / 1024
- Set power[i] to real + imag
- Otherwise
Call N PHY Calc RX IQ Comp with (1 << i) as argument
Call N PHY Stop Playback
- If ret is not zero
- Break from loop
- Mask Radio Register 0xD6 with mask 0xFC
- Mask Radio Register 0xE2 with mask 0xFC
- Write tmp5 to PHY Register (i == 1) ? 0x91 : 0x92
- Write tmp4 to PHY Register (i == 0) ? 0x91 : 0x92
- Write tmp3 to PHY Register 0xA5
- Write tmp2 to PHY Register (i == 0) ? 0xA6 : 0xA7
- Write tmp1 to PHY Register 0xA2
- If ret is not zero
- Break from loop
Call N PHY RF Ctrl Override with 0x400, 0, 3, 1 as arguments
Call N PHY Force RF Seq with 2 as argument
- Write an N PHY Table with ID 7, length 2, offset 0x110, width 16, and data from gain_save
Call N PHY Stay in Carrier Search with argument 0
- Return ret