On Sat, Sep 17, 2022 at 12:06:21AM +0100, Daniel Golle wrote: > From: Tomislav Požega <pozega.tomislav@xxxxxxxxx> > > Add RXIQ calibration found in mtk driver. With old openwrt builds this > gets us ~8Mbps more of RX bandwidth (test with iPA/eLNA layout). > > Signed-off-by: Tomislav Požega <pozega.tomislav@xxxxxxxxx> > --- > .../net/wireless/ralink/rt2x00/rt2800lib.c | 384 ++++++++++++++++++ > 1 file changed, 384 insertions(+) > > diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c > index d5b4dba3b27203..6e5a72cf2a81a0 100644 > --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c > +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c > @@ -8695,6 +8695,389 @@ static void rt2800_rxdcoc_calibration(struct rt2x00_dev *rt2x00dev) > rt2800_rfcsr_write_bank(rt2x00dev, 0, 2, saverfb0r2); > } > > +static u32 rt2800_do_sqrt_accumulation(u32 si) > +{ > + u32 root, root_pre, bit; > + char i; > + > + bit = 1 << 15; > + root = 0; > + for (i = 15; i >= 0; i = i - 1) { > + root_pre = root + bit; > + if ((root_pre * root_pre) <= si) > + root = root_pre; > + bit = bit >> 1; > + } > + > + return root; > +} > + > +static void rt2800_rxiq_calibration(struct rt2x00_dev *rt2x00dev) > +{ > + u8 rfb0r1, rfb0r2, rfb0r42; > + u8 rfb4r0, rfb4r19; > + u8 rfb5r3, rfb5r4, rfb5r17, rfb5r18, rfb5r19, rfb5r20; > + u8 rfb6r0, rfb6r19; > + u8 rfb7r3, rfb7r4, rfb7r17, rfb7r18, rfb7r19, rfb7r20; > + > + u8 bbp1, bbp4; > + u8 bbpr241, bbpr242; > + u32 i; > + u8 ch_idx; > + u8 bbpval; > + u8 rfval, vga_idx = 0; > + int mi = 0, mq = 0, si = 0, sq = 0, riq = 0; > + int sigma_i, sigma_q, r_iq, g_rx; > + int g_imb; > + int ph_rx; > + u32 savemacsysctrl = 0; > + u32 orig_RF_CONTROL0 = 0; > + u32 orig_RF_BYPASS0 = 0; > + u32 orig_RF_CONTROL1 = 0; > + u32 orig_RF_BYPASS1 = 0; > + u32 orig_RF_CONTROL3 = 0; > + u32 orig_RF_BYPASS3 = 0; > + u32 macstatus, bbpval1 = 0; > + u8 rf_vga_table[] = {0x20, 0x21, 0x22, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f}; static const maybe ? > + savemacsysctrl = rt2800_register_read(rt2x00dev, MAC_SYS_CTRL); > + orig_RF_CONTROL0 = rt2800_register_read(rt2x00dev, RF_CONTROL0); > + orig_RF_BYPASS0 = rt2800_register_read(rt2x00dev, RF_BYPASS0); > + orig_RF_CONTROL1 = rt2800_register_read(rt2x00dev, RF_CONTROL1); > + orig_RF_BYPASS1 = rt2800_register_read(rt2x00dev, RF_BYPASS1); > + orig_RF_CONTROL3 = rt2800_register_read(rt2x00dev, RF_CONTROL3); > + orig_RF_BYPASS3 = rt2800_register_read(rt2x00dev, RF_BYPASS3); > + > + bbp1 = rt2800_bbp_read(rt2x00dev, 1); > + bbp4 = rt2800_bbp_read(rt2x00dev, 4); > + > + rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0x0); > + > + for (i = 0; i < 10000; i++) { > + macstatus = rt2800_register_read(rt2x00dev, MAC_STATUS_CFG); > + if (macstatus & 0x3) > + usleep_range(50, 100); > + else > + break; > + } This one is used frequently , I think we can add helper for that. mt76 has mt76x02_wait_for_txrx_idle , so we can create something similar. > + vga_idx = 0; > + while (vga_idx < 11) { Looks like ideation issue. In general this function is too big. Could be split into small sub-functions ?