89a4ccb961a5aa74a5282d24fd36d8462a94f108
[openwrt/openwrt.git] / package / kernel / mac80211 / patches / rt2x00 / 984-rt2x00-add-rxdcoc-calibration.patch
1 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
2 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
3 @@ -8621,6 +8621,70 @@ static void rt2800_r_calibration(struct
4 rt2800_register_write(rt2x00dev, PWR_PIN_CFG, MAC_PWR_PIN_CFG);
5 }
6
7 +static void rt2800_rxdcoc_calibration(struct rt2x00_dev *rt2x00dev)
8 +{
9 + u8 bbpreg = 0;
10 + u32 macvalue = 0, macvalue1 = 0;
11 + u8 saverfb0r2, saverfb5r4, saverfb7r4, rfvalue;
12 + int i;
13 +
14 + saverfb0r2 = rt2800_rfcsr_read_bank(rt2x00dev, 0, 2);
15 + rfvalue = saverfb0r2;
16 + rfvalue |= 0x03;
17 + rt2800_rfcsr_write_bank(rt2x00dev, 0, 2, rfvalue);
18 +
19 + rt2800_bbp_write(rt2x00dev, 158, 141);
20 + bbpreg = rt2800_bbp_read(rt2x00dev, 159);
21 + bbpreg |= 0x10;
22 + rt2800_bbp_write(rt2x00dev, 159, bbpreg);
23 +
24 + macvalue = rt2800_register_read(rt2x00dev, MAC_SYS_CTRL);
25 + rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0x8);
26 +
27 + for (i = 0; i < 10000; i++) {
28 + macvalue1 = rt2800_register_read(rt2x00dev, MAC_STATUS_CFG);
29 + if (macvalue1 & 0x1)
30 + udelay(50);
31 + else
32 + break;
33 + }
34 +
35 + saverfb5r4 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 0);
36 + saverfb7r4 = rt2800_rfcsr_read_bank(rt2x00dev, 7, 4);
37 + saverfb5r4 = saverfb5r4 & (~0x40);
38 + saverfb7r4 = saverfb7r4 & (~0x40);
39 + rt2800_rfcsr_write_dccal(rt2x00dev, 4, 0x64);
40 + rt2800_rfcsr_write_bank(rt2x00dev, 5, 4, saverfb5r4);
41 + rt2800_rfcsr_write_bank(rt2x00dev, 7, 4, saverfb7r4);
42 +
43 + rt2800_bbp_write(rt2x00dev, 158, 141);
44 + bbpreg = rt2800_bbp_read(rt2x00dev, 159);
45 + bbpreg = bbpreg & (~0x40);
46 + rt2800_bbp_write(rt2x00dev, 159, bbpreg);
47 + bbpreg |= 0x48;
48 + rt2800_bbp_write(rt2x00dev, 159, bbpreg);
49 +
50 + for (i = 0; i < 10000; i++) {
51 + bbpreg = rt2800_bbp_read(rt2x00dev, 159);
52 + if ((bbpreg & 0x40)==0)
53 + break;
54 + udelay(50);
55 + }
56 +
57 + bbpreg = rt2800_bbp_read(rt2x00dev, 159);
58 + bbpreg = bbpreg & (~0x40);
59 + rt2800_bbp_write(rt2x00dev, 159, bbpreg);
60 +
61 + rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, macvalue);
62 +
63 + rt2800_bbp_write(rt2x00dev, 158, 141);
64 + bbpreg = rt2800_bbp_read(rt2x00dev, 159);
65 + bbpreg &= (~0x10);
66 + rt2800_bbp_write(rt2x00dev, 159, bbpreg);
67 +
68 + rt2800_rfcsr_write_bank(rt2x00dev, 0, 2, saverfb0r2);
69 +}
70 +
71 static void rt2800_bbp_core_soft_reset(struct rt2x00_dev *rt2x00dev,
72 bool set_bw, bool is_ht40)
73 {
74 @@ -9230,6 +9294,7 @@ static void rt2800_init_rfcsr_6352(struc
75
76 rt2800_r_calibration(rt2x00dev);
77 rt2800_rf_self_txdc_cal(rt2x00dev);
78 + rt2800_rxdcoc_calibration(rt2x00dev);
79 rt2800_bw_filter_calibration(rt2x00dev, true);
80 rt2800_bw_filter_calibration(rt2x00dev, false);
81 }