b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | //============================================================ |
| 2 | // |
| 3 | // File Name: Hal8192CDMOutSrc.c |
| 4 | // |
| 5 | // Description: |
| 6 | // |
| 7 | // This file is for 92CE/92CU outsource dynamic mechanism for partner. |
| 8 | // |
| 9 | // |
| 10 | //============================================================ |
| 11 | |
| 12 | #ifndef _HAL8192CDM_C_ |
| 13 | #define _HAL8192CDM_C_ |
| 14 | |
| 15 | #ifdef __KERNEL__ |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <asm/uaccess.h> |
| 20 | #include <linux/fcntl.h> |
| 21 | #include <linux/fs.h> |
| 22 | #include <linux/file.h> |
| 23 | #include <asm/unistd.h> |
| 24 | #elif defined(__ECOS) |
| 25 | #include <cyg/io/eth/rltk/819x/wrapper/sys_support.h> |
| 26 | #include <cyg/io/eth/rltk/819x/wrapper/skbuff.h> |
| 27 | #include <cyg/io/eth/rltk/819x/wrapper/timer.h> |
| 28 | #include <cyg/io/eth/rltk/819x/wrapper/wrapper.h> |
| 29 | #endif |
| 30 | |
| 31 | #include "./8192cd_cfg.h" |
| 32 | #include "./8192cd.h" |
| 33 | #include "./8192cd_hw.h" |
| 34 | #include "./8192cd_headers.h" |
| 35 | #include "./8192cd_debug.h" |
| 36 | |
| 37 | |
| 38 | |
| 39 | #ifdef __KERNEL__ |
| 40 | #ifdef __LINUX_2_6__ |
| 41 | #ifndef CONFIG_AX1500 |
| 42 | #include <linux/syscalls.h> |
| 43 | #endif |
| 44 | #else |
| 45 | #include <linux/fs.h> |
| 46 | #endif |
| 47 | #endif |
| 48 | |
| 49 | #if defined(CONFIG_RTL_819X) && defined(USE_RLX_BSP) |
| 50 | #if defined(CONFIG_OPENWRT_SDK) && !defined(CONFIG_ARCH_CPU_RLX) |
| 51 | #include <bspchip.h> |
| 52 | #else |
| 53 | #include <bsp/bspchip.h> |
| 54 | #endif //CONFIG_OPENWRT_SDK |
| 55 | #endif |
| 56 | |
| 57 | |
| 58 | //Analog Pre-distortion calibration |
| 59 | #define APK_BB_REG_NUM 5 |
| 60 | #define APK_AFE_REG_NUM 16 |
| 61 | #define APK_CURVE_REG_NUM 4 |
| 62 | #define PATH_NUM 2 |
| 63 | |
| 64 | //============================================================ |
| 65 | // Global var |
| 66 | //============================================================ |
| 67 | |
| 68 | #if !defined(USE_OUT_SRC) || defined(_OUTSRC_COEXIST) |
| 69 | unsigned int ofdm_swing_table[] = { |
| 70 | 0x7f8001fe, // 0, +6.0dB |
| 71 | 0x788001e2, // 1, +5.5dB |
| 72 | 0x71c001c7, // 2, +5.0dB |
| 73 | 0x6b8001ae, // 3, +4.5dB |
| 74 | 0x65400195, // 4, +4.0dB |
| 75 | 0x5fc0017f, // 5, +3.5dB |
| 76 | 0x5a400169, // 6, +3.0dB |
| 77 | 0x55400155, // 7, +2.5dB |
| 78 | 0x50800142, // 8, +2.0dB |
| 79 | 0x4c000130, // 9, +1.5dB |
| 80 | 0x47c0011f, // 10, +1.0dB |
| 81 | 0x43c0010f, // 11, +0.5dB |
| 82 | 0x40000100, // 12, +0dB |
| 83 | 0x3c8000f2, // 13, -0.5dB |
| 84 | 0x390000e4, // 14, -1.0dB |
| 85 | 0x35c000d7, // 15, -1.5dB |
| 86 | 0x32c000cb, // 16, -2.0dB |
| 87 | 0x300000c0, // 17, -2.5dB |
| 88 | 0x2d4000b5, // 18, -3.0dB |
| 89 | 0x2ac000ab, // 19, -3.5dB |
| 90 | 0x288000a2, // 20, -4.0dB |
| 91 | 0x26000098, // 21, -4.5dB |
| 92 | 0x24000090, // 22, -5.0dB |
| 93 | 0x22000088, // 23, -5.5dB |
| 94 | 0x20000080, // 24, -6.0dB |
| 95 | 0x1e400079, // 25, -6.5dB |
| 96 | 0x1c800072, // 26, -7.0dB |
| 97 | 0x1b00006c, // 27. -7.5dB |
| 98 | 0x19800066, // 28, -8.0dB |
| 99 | 0x18000060, // 29, -8.5dB |
| 100 | 0x16c0005b, // 30, -9.0dB |
| 101 | 0x15800056, // 31, -9.5dB |
| 102 | 0x14400051, // 32, -10.0dB |
| 103 | 0x1300004c, // 33, -10.5dB |
| 104 | 0x12000048, // 34, -11.0dB |
| 105 | 0x11000044, // 35, -11.5dB |
| 106 | 0x10000040, // 36, -12.0dB |
| 107 | }; |
| 108 | |
| 109 | |
| 110 | unsigned int TxPwrTrk_OFDM_SwingTbl[TxPwrTrk_OFDM_SwingTbl_Len] = { |
| 111 | /* +6.0dB */ 0x7f8001fe, |
| 112 | /* +5.5dB */ 0x788001e2, |
| 113 | /* +5.0dB */ 0x71c001c7, |
| 114 | /* +4.5dB */ 0x6b8001ae, |
| 115 | /* +4.0dB */ 0x65400195, |
| 116 | /* +3.5dB */ 0x5fc0017f, |
| 117 | /* +3.0dB */ 0x5a400169, |
| 118 | /* +2.5dB */ 0x55400155, |
| 119 | /* +2.0dB */ 0x50800142, |
| 120 | /* +1.5dB */ 0x4c000130, |
| 121 | /* +1.0dB */ 0x47c0011f, |
| 122 | /* +0.5dB */ 0x43c0010f, |
| 123 | /* 0.0dB */ 0x40000100, |
| 124 | /* -0.5dB */ 0x3c8000f2, |
| 125 | /* -1.0dB */ 0x390000e4, |
| 126 | /* -1.5dB */ 0x35c000d7, |
| 127 | /* -2.0dB */ 0x32c000cb, |
| 128 | /* -2.5dB */ 0x300000c0, |
| 129 | /* -3.0dB */ 0x2d4000b5, |
| 130 | /* -3.5dB */ 0x2ac000ab, |
| 131 | /* -4.0dB */ 0x288000a2, |
| 132 | /* -4.5dB */ 0x26000098, |
| 133 | /* -5.0dB */ 0x24000090, |
| 134 | /* -5.5dB */ 0x22000088, |
| 135 | /* -6.0dB */ 0x20000080, |
| 136 | /* -6.5dB */ 0x1a00006c, |
| 137 | /* -7.0dB */ 0x1c800072, |
| 138 | /* -7.5dB */ 0x18000060, |
| 139 | /* -8.0dB */ 0x19800066, |
| 140 | /* -8.5dB */ 0x15800056, |
| 141 | /* -9.0dB */ 0x26c0005b, |
| 142 | /* -9.5dB */ 0x14400051, |
| 143 | /* -10.0dB */ 0x24400051, |
| 144 | /* -10.5dB */ 0x1300004c, |
| 145 | /* -11.0dB */ 0x12000048, |
| 146 | /* -11.5dB */ 0x11000044, |
| 147 | /* -12.0dB */ 0x10000040 |
| 148 | }; |
| 149 | |
| 150 | unsigned char TxPwrTrk_CCK_SwingTbl[TxPwrTrk_CCK_SwingTbl_Len][8] = { |
| 151 | /* 0.0dB */ {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04}, |
| 152 | /* 0.5dB */ {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, |
| 153 | /* 1.0dB */ {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, |
| 154 | /* 1.5dB */ {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, |
| 155 | /* 2.0dB */ {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, |
| 156 | /* 2.5dB */ {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, |
| 157 | /* 3.0dB */ {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, |
| 158 | /* 3.5dB */ {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, |
| 159 | /* 4.0dB */ {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, |
| 160 | /* 4.5dB */ {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, |
| 161 | /* 5.0dB */ {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, |
| 162 | /* 5.5dB */ {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, |
| 163 | /* 6.0dB */ {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, |
| 164 | /* 6.5dB */ {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, |
| 165 | /* 7.0dB */ {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, |
| 166 | /* 7.5dB */ {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, |
| 167 | /* 8.0dB */ {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, |
| 168 | /* 8.5dB */ {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, |
| 169 | /* 9.0dB */ {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, |
| 170 | /* 9.5dB */ {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, |
| 171 | /* 10.0dB */ {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, |
| 172 | /* 10.5dB */ {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, |
| 173 | /* 11.0dB */ {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01} |
| 174 | }; |
| 175 | |
| 176 | unsigned char TxPwrTrk_CCK_SwingTbl_CH14[TxPwrTrk_CCK_SwingTbl_Len][8] = { |
| 177 | /* 0.0dB */ {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00}, |
| 178 | /* 0.5dB */ {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, |
| 179 | /* 1.0dB */ {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, |
| 180 | /* 1.5dB */ {0x2d, 0x2d, 0x27, 0x17, 0x00, 0x00, 0x00, 0x00}, |
| 181 | /* 2.0dB */ {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, |
| 182 | /* 2.5dB */ {0x28, 0x28, 0x22, 0x14, 0x00, 0x00, 0x00, 0x00}, |
| 183 | /* 3.0dB */ {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, |
| 184 | /* 3.5dB */ {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, |
| 185 | /* 4.0dB */ {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, |
| 186 | /* 4.5dB */ {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, |
| 187 | /* 5.0dB */ {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, |
| 188 | /* 5.5dB */ {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, |
| 189 | /* 6.0dB */ {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, |
| 190 | /* 6.5dB */ {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, |
| 191 | /* 7.0dB */ {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, |
| 192 | /* 7.5dB */ {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, |
| 193 | /* 8.0dB */ {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, |
| 194 | /* 8.5dB */ {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, |
| 195 | /* 9.0dB */ {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, |
| 196 | /* 9.5dB */ {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, |
| 197 | /* 10.0dB */ {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, |
| 198 | /* 10.5dB */ {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, |
| 199 | /* 11.0dB */ {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00} |
| 200 | }; |
| 201 | |
| 202 | //#ifndef USE_OUT_SRC |
| 203 | |
| 204 | unsigned char cck_swing_table_ch1_ch13[][8] = { |
| 205 | {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04}, // 0, +0dB |
| 206 | {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, // 1, -0.5dB |
| 207 | {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, // 2, -1.0dB |
| 208 | {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, // 3, -1.5dB |
| 209 | {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, // 4, -2.0dB |
| 210 | {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, // 5, -2.5dB |
| 211 | {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, // 6, -3.0dB |
| 212 | {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, // 7, -3.5dB |
| 213 | {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, // 8, -4.0dB |
| 214 | {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, // 9, -4.5dB |
| 215 | {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, // 10, -5.0dB |
| 216 | {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, // 11, -5.5dB |
| 217 | {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, // 12, -6.0dB |
| 218 | {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, // 13, -6.5dB |
| 219 | {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, // 14, -7.0dB |
| 220 | {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, // 15, -7.5dB |
| 221 | {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, // 16, -8.0dB |
| 222 | {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, // 17, -8.5dB |
| 223 | {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, // 18, -9.0dB |
| 224 | {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, // 19, -9.5dB |
| 225 | {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, // 20, -10.0dB |
| 226 | {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, // 21, -10.5dB |
| 227 | {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, // 22, -11.0dB |
| 228 | {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, // 23, -11.5dB |
| 229 | {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, // 24, -12.0dB |
| 230 | {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, // 25, -12.5dB |
| 231 | {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, // 26, -13.0dB |
| 232 | {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, // 27, -13.5dB |
| 233 | {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, // 28, -14.0dB |
| 234 | {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, // 29, -14.5dB |
| 235 | {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, // 30, -15.0dB |
| 236 | {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, // 31, -15.5dB |
| 237 | {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01} // 32, -16.0dB |
| 238 | }; |
| 239 | |
| 240 | unsigned char cck_swing_table_ch14 [][8]= { |
| 241 | {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00}, // 0, +0dB |
| 242 | {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, // 1, -0.5dB |
| 243 | {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, // 2, -1.0dB |
| 244 | {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, // 3, -1.5dB |
| 245 | {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, // 4, -2.0dB |
| 246 | {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, // 5, -2.5dB |
| 247 | {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, // 6, -3.0dB |
| 248 | {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, // 7, -3.5dB |
| 249 | {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, // 8, -4.0dB |
| 250 | {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, // 9, -4.5dB |
| 251 | {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, // 10, -5.0dB |
| 252 | {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, // 11, -5.5dB |
| 253 | {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, // 12, -6.0dB |
| 254 | {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, // 13, -6.5dB |
| 255 | {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, // 14, -7.0dB |
| 256 | {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, // 15, -7.5dB |
| 257 | {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, // 16, -8.0dB |
| 258 | {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, // 17, -8.5dB |
| 259 | {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, // 18, -9.0dB |
| 260 | {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, // 19, -9.5dB |
| 261 | {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, // 20, -10.0dB |
| 262 | {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, // 21, -10.5dB |
| 263 | {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, // 22, -11.0dB |
| 264 | {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, // 23, -11.5dB |
| 265 | {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, // 24, -12.0dB |
| 266 | {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, // 25, -12.5dB |
| 267 | {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, // 26, -13.0dB |
| 268 | {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, // 27, -13.5dB |
| 269 | {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, // 28, -14.0dB |
| 270 | {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, // 29, -14.5dB |
| 271 | {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, // 30, -15.0dB |
| 272 | {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, // 31, -15.5dB |
| 273 | {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00} // 32, -16.0dB |
| 274 | }; |
| 275 | |
| 276 | #endif |
| 277 | |
| 278 | //#if defined(_OUTSRC_COEXIST) |
| 279 | #if !defined(USE_OUT_SRC) || defined(_OUTSRC_COEXIST) |
| 280 | const int OFDM_TABLE_SIZE= sizeof(ofdm_swing_table)/sizeof(int); |
| 281 | const int CCK_TABLE_SIZE= sizeof(cck_swing_table_ch1_ch13) >>3; |
| 282 | #endif |
| 283 | |
| 284 | |
| 285 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 286 | |
| 287 | static unsigned int OFDMSwingTable_92D[] = { |
| 288 | 0x7f8001fe, // 0, +6.0dB |
| 289 | 0x788001e2, // 1, +5.5dB |
| 290 | 0x71c001c7, // 2, +5.0dB |
| 291 | 0x6b8001ae, // 3, +4.5dB |
| 292 | 0x65400195, // 4, +4.0dB |
| 293 | 0x5fc0017f, // 5, +3.5dB |
| 294 | 0x5a400169, // 6, +3.0dB |
| 295 | 0x55400155, // 7, +2.5dB |
| 296 | 0x50800142, // 8, +2.0dB |
| 297 | 0x4c000130, // 9, +1.5dB |
| 298 | 0x47c0011f, // 10, +1.0dB |
| 299 | 0x43c0010f, // 11, +0.5dB |
| 300 | 0x40000100, // 12, +0dB |
| 301 | 0x3c8000f2, // 13, -0.5dB |
| 302 | 0x390000e4, // 14, -1.0dB |
| 303 | 0x35c000d7, // 15, -1.5dB |
| 304 | 0x32c000cb, // 16, -2.0dB |
| 305 | 0x300000c0, // 17, -2.5dB |
| 306 | 0x2d4000b5, // 18, -3.0dB |
| 307 | 0x2ac000ab, // 19, -3.5dB |
| 308 | 0x288000a2, // 20, -4.0dB |
| 309 | 0x26000098, // 21, -4.5dB |
| 310 | 0x24000090, // 22, -5.0dB |
| 311 | 0x22000088, // 23, -5.5dB |
| 312 | 0x20000080, // 24, -6.0dB |
| 313 | 0x1e400079, // 25, -6.5dB |
| 314 | 0x1c800072, // 26, -7.0dB |
| 315 | 0x1b00006c, // 27. -7.5dB |
| 316 | 0x19800066, // 28, -8.0dB |
| 317 | 0x18000060, // 29, -8.5dB |
| 318 | 0x16c0005b, // 30, -9.0dB |
| 319 | 0x15800056, // 31, -9.5dB |
| 320 | 0x14400051, // 32, -10.0dB |
| 321 | 0x1300004c, // 33, -10.5dB |
| 322 | 0x12000048, // 34, -11.0dB |
| 323 | 0x11000044, // 35, -11.5dB |
| 324 | 0x10000040, // 36, -12.0dB |
| 325 | 0x0f00003c,// 37, -12.5dB |
| 326 | 0x0e400039,// 38, -13.0dB |
| 327 | 0x0d800036,// 39, -13.5dB |
| 328 | 0x0cc00033,// 40, -14.0dB |
| 329 | 0x0c000030,// 41, -14.5dB |
| 330 | 0x0b40002d,// 42, -15.0dB |
| 331 | }; |
| 332 | #endif |
| 333 | |
| 334 | |
| 335 | #ifdef HW_ANT_SWITCH |
| 336 | #define RXDVY_A_EN ((HW_DIV_ENABLE && !priv->pshare->rf_ft_var.antSw_select) ? 0x80 : 0) |
| 337 | #define RXDVY_B_EN ((HW_DIV_ENABLE && priv->pshare->rf_ft_var.antSw_select) ? 0x80 : 0) |
| 338 | #endif |
| 339 | |
| 340 | |
| 341 | //3 ============================================================ |
| 342 | //3 DIG related functions |
| 343 | //3 ============================================================ |
| 344 | #if 0 |
| 345 | int getIGIFor1RCCA(int value_IGI) |
| 346 | { |
| 347 | #define ONERCCA_LOW_TH 0x30 |
| 348 | #define ONERCCA_LOW_DIFF 8 |
| 349 | |
| 350 | if (value_IGI < ONERCCA_LOW_TH) { |
| 351 | if ((ONERCCA_LOW_TH - value_IGI) < ONERCCA_LOW_DIFF) |
| 352 | return ONERCCA_LOW_TH; |
| 353 | else |
| 354 | return value_IGI + ONERCCA_LOW_DIFF; |
| 355 | } else { |
| 356 | return value_IGI; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | |
| 361 | void set_DIG_state(struct rtl8192cd_priv *priv, int state) |
| 362 | { |
| 363 | int value_IGI; |
| 364 | |
| 365 | if (state) { |
| 366 | priv->pshare->DIG_on = 1; |
| 367 | priv->pshare->restore = 0; |
| 368 | } |
| 369 | else { |
| 370 | priv->pshare->DIG_on = 0; |
| 371 | if (priv->pshare->restore == 0) { |
| 372 | if (priv->pshare->rf_ft_var.use_ext_lna == 1) |
| 373 | value_IGI = 0x30; |
| 374 | else |
| 375 | value_IGI = 0x20; |
| 376 | |
| 377 | #if defined(HW_ANT_SWITCH) |
| 378 | // wirte new initial gain index into regC50/C58 |
| 379 | if (priv->pshare->rf_ft_var.one_path_cca == 0) { |
| 380 | RTL_W8(0xc50, value_IGI | RXDVY_A_EN); |
| 381 | #if defined(CONFIG_RTL_92C_SUPPORT) || defined(CONFIG_RTL_92D_SUPPORT) |
| 382 | if ( |
| 383 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 384 | (GET_CHIP_VER(priv)==VERSION_8192C) || (GET_CHIP_VER(priv)==VERSION_8188C) |
| 385 | #endif |
| 386 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 387 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 388 | || |
| 389 | #endif |
| 390 | (GET_CHIP_VER(priv)==VERSION_8192D) |
| 391 | #endif |
| 392 | ) |
| 393 | RTL_W8(0xc58, value_IGI | RXDVY_B_EN); |
| 394 | #endif |
| 395 | } else if (priv->pshare->rf_ft_var.one_path_cca == 1) { |
| 396 | RTL_W8(0xc50, value_IGI | RXDVY_A_EN); |
| 397 | #if defined(CONFIG_RTL_92C_SUPPORT) || defined(CONFIG_RTL_92D_SUPPORT) |
| 398 | if ( |
| 399 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 400 | (GET_CHIP_VER(priv)==VERSION_8192C) || (GET_CHIP_VER(priv)==VERSION_8188C) |
| 401 | #endif |
| 402 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 403 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 404 | || |
| 405 | #endif |
| 406 | (GET_CHIP_VER(priv)==VERSION_8192D) |
| 407 | #endif |
| 408 | ) |
| 409 | RTL_W8(0xc58, getIGIFor1RCCA(value_IGI) | RXDVY_B_EN); |
| 410 | #endif |
| 411 | } else if (priv->pshare->rf_ft_var.one_path_cca == 2) { |
| 412 | RTL_W8(0xc50, getIGIFor1RCCA(value_IGI) | RXDVY_A_EN); |
| 413 | #if defined(CONFIG_RTL_92C_SUPPORT) || defined(CONFIG_RTL_92D_SUPPORT) |
| 414 | if ( |
| 415 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 416 | (GET_CHIP_VER(priv)==VERSION_8192C) || (GET_CHIP_VER(priv)==VERSION_8188C) |
| 417 | #endif |
| 418 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 419 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 420 | || |
| 421 | #endif |
| 422 | (GET_CHIP_VER(priv)==VERSION_8192D) |
| 423 | #endif |
| 424 | ) |
| 425 | RTL_W8(0xc58, value_IGI | RXDVY_B_EN); |
| 426 | #endif |
| 427 | } |
| 428 | #else |
| 429 | // Write IGI into HW |
| 430 | if (priv->pshare->rf_ft_var.one_path_cca == 0) { |
| 431 | RTL_W8(0xc50, value_IGI); |
| 432 | #if defined(CONFIG_RTL_92C_SUPPORT) || defined(CONFIG_RTL_92D_SUPPORT) |
| 433 | if ( |
| 434 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 435 | (GET_CHIP_VER(priv)==VERSION_8192C) || (GET_CHIP_VER(priv)==VERSION_8188C) |
| 436 | #endif |
| 437 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 438 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 439 | || |
| 440 | #endif |
| 441 | (GET_CHIP_VER(priv)==VERSION_8192D) |
| 442 | #endif |
| 443 | ) |
| 444 | RTL_W8(0xc58, value_IGI); |
| 445 | #endif |
| 446 | } else if (priv->pshare->rf_ft_var.one_path_cca == 1) { |
| 447 | RTL_W8(0xc50, value_IGI); |
| 448 | #if defined(CONFIG_RTL_92C_SUPPORT) || defined(CONFIG_RTL_92D_SUPPORT) |
| 449 | if ( |
| 450 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 451 | (GET_CHIP_VER(priv)==VERSION_8192C) || (GET_CHIP_VER(priv)==VERSION_8188C) |
| 452 | #endif |
| 453 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 454 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 455 | || |
| 456 | #endif |
| 457 | (GET_CHIP_VER(priv)==VERSION_8192D) |
| 458 | #endif |
| 459 | ) |
| 460 | RTL_W8(0xc58, getIGIFor1RCCA(value_IGI)); |
| 461 | #endif |
| 462 | } else if (priv->pshare->rf_ft_var.one_path_cca == 2) { |
| 463 | RTL_W8(0xc50, getIGIFor1RCCA(value_IGI)); |
| 464 | #if defined(CONFIG_RTL_92C_SUPPORT) || defined(CONFIG_RTL_92D_SUPPORT) |
| 465 | if ( |
| 466 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 467 | (GET_CHIP_VER(priv)==VERSION_8192C) || (GET_CHIP_VER(priv)==VERSION_8188C) |
| 468 | #endif |
| 469 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 470 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 471 | || |
| 472 | #endif |
| 473 | (GET_CHIP_VER(priv)==VERSION_8192D) |
| 474 | #endif |
| 475 | ) |
| 476 | RTL_W8(0xc58, value_IGI); |
| 477 | #endif |
| 478 | } |
| 479 | #endif |
| 480 | priv->pshare->restore = 1; |
| 481 | } |
| 482 | #ifdef INTERFERENCE_CONTROL |
| 483 | priv->pshare->phw->signal_strength = 0; |
| 484 | #endif |
| 485 | } |
| 486 | } |
| 487 | #endif |
| 488 | |
| 489 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 490 | void MP_DIG_process(unsigned long task_priv) |
| 491 | { |
| 492 | struct rtl8192cd_priv *priv = (struct rtl8192cd_priv *)task_priv; |
| 493 | u4Byte RXOK_cal, RxPWDBAve; |
| 494 | //unsigned int FA_cnt_ofdm = priv->pshare->ofdm_FA_cnt1 + priv->pshare->ofdm_FA_cnt2 + |
| 495 | // priv->pshare->ofdm_FA_cnt3 + priv->pshare->ofdm_FA_cnt4; |
| 496 | //unsigned int FA_cnt_cck = priv->pshare->cck_FA_cnt; |
| 497 | |
| 498 | if (!(priv->drv_state & DRV_STATE_OPEN)) |
| 499 | return; |
| 500 | |
| 501 | if (!(priv->pshare->rf_ft_var.mp_specific && priv->pshare->mp_dig_on)) |
| 502 | return; |
| 503 | |
| 504 | //printk("===> %s, pBandType = %d\n", __FUNCTION__, priv->pmib->dot11RFEntry.phyBandSelect); |
| 505 | |
| 506 | if (priv->pmib->dot11RFEntry.phyBandSelect == PHY_BAND_5G) { |
| 507 | |
| 508 | FA_statistic(priv); |
| 509 | |
| 510 | priv->pshare->LastNumQryPhyStatusAll = priv->pshare->NumQryPhyStatus; |
| 511 | priv->pshare->NumQryPhyStatus = priv->pshare->NumQryPhyStatusCCK + priv->pshare->NumQryPhyStatusOFDM; |
| 512 | RXOK_cal = priv->pshare->NumQryPhyStatus - priv->pshare->LastNumQryPhyStatusAll; |
| 513 | |
| 514 | if (RXOK_cal == 0) |
| 515 | RxPWDBAve = 0; |
| 516 | else |
| 517 | RxPWDBAve = priv->pshare->RxPWDBAve/RXOK_cal; |
| 518 | |
| 519 | priv->pshare->RxPWDBAve= 0; |
| 520 | |
| 521 | //printk("RX OK = %d\n", RXOK_cal); |
| 522 | //printk("RSSI = %d\n", RxPWDBAve); |
| 523 | //printk("DIG = (%x, %x), Cnt_all = %d, Cnt_Ofdm_fail = %d, Cnt_Cck_fail = %d\n", RTL_R8(0xc50), RTL_R8(0xc58), priv->pshare->FA_total_cnt, FA_cnt_ofdm, FA_cnt_cck); |
| 524 | |
| 525 | if (RXOK_cal >= 70) { |
| 526 | if (RxPWDBAve <= 40) { |
| 527 | RTL_W8(0xc50, 0x1C); |
| 528 | RTL_W8(0xc58, 0x1C); |
| 529 | } else if (RxPWDBAve > 45) { |
| 530 | RTL_W8(0xc50, 0x20); |
| 531 | RTL_W8(0xc58, 0x20); |
| 532 | } |
| 533 | } |
| 534 | else { |
| 535 | RTL_W8(0xc50, 0x20); |
| 536 | RTL_W8(0xc58, 0x20); |
| 537 | } |
| 538 | } |
| 539 | rtk_mod_timer(&priv->pshare->MP_DIGTimer, jiffies + RTL_MILISECONDS_TO_JIFFIES(700)); |
| 540 | } |
| 541 | |
| 542 | static __always_inline void MP_DIG_timer_cb(unsigned long task_priv) |
| 543 | { |
| 544 | MP_DIG_process(task_priv); |
| 545 | } |
| 546 | DEFINE_TIMER_CALLBACK(MP_DIG_timer_cb); |
| 547 | |
| 548 | void init_MP_DIGTimer(struct rtl8192cd_priv *priv) |
| 549 | { |
| 550 | rtk_timer_setup(&(priv->pshare->MP_DIGTimer), MP_DIG_timer_cb, (unsigned long)priv, 0); |
| 551 | } |
| 552 | #endif // CONFIG_RTL_92D_SUPPORT |
| 553 | |
| 554 | void DIG_process(struct rtl8192cd_priv *priv) |
| 555 | { |
| 556 | #define DEAD_POINT_TH 10000 |
| 557 | #define DOWN_IG_HIT_TH 5 |
| 558 | #define DEAD_POINT_HIT_TH 3 |
| 559 | |
| 560 | unsigned char value_IGI; |
| 561 | signed char value8; |
| 562 | unsigned int IGI_target; |
| 563 | unsigned char Adap_IGI_Upper; |
| 564 | #ifdef INTERFERENCE_CONTROL |
| 565 | unsigned short thd0 = priv->pshare->threshold0; |
| 566 | unsigned short thd1 = priv->pshare->threshold1; |
| 567 | unsigned short thd2 = priv->pshare->threshold2; |
| 568 | #endif |
| 569 | |
| 570 | if (priv->pshare->DIG_on == 1) |
| 571 | { |
| 572 | #ifdef HIGH_POWER_EXT_LNA |
| 573 | if (priv->pshare->rf_ft_var.use_ext_lna == 1) { |
| 574 | // priv->pshare->FA_upper = 0x42; |
| 575 | priv->pshare->FA_upper = MIN_NUM(0x42, priv->pshare->rssi_min+36); |
| 576 | priv->pshare->FA_lower = 0x30; |
| 577 | } else |
| 578 | #endif |
| 579 | { |
| 580 | // Reset initial gain upper & lower bounds |
| 581 | #ifdef DFS |
| 582 | unsigned int dfs_channel = 144; |
| 583 | |
| 584 | if(priv->pmib->dot11DFSEntry.band4_DFS_en) |
| 585 | dfs_channel = 165; |
| 586 | |
| 587 | if (!priv->pmib->dot11DFSEntry.disable_DFS && |
| 588 | (OPMODE & WIFI_AP_STATE) && |
| 589 | (((priv->pmib->dot11RFEntry.dot11channel >= 52) && |
| 590 | (priv->pmib->dot11RFEntry.dot11channel <= 64)) || |
| 591 | ((priv->pmib->dot11RFEntry.dot11channel >= 100) && |
| 592 | (priv->pmib->dot11RFEntry.dot11channel <= dfs_channel)))){ |
| 593 | priv->pshare->FA_upper = 0x24; |
| 594 | priv->pshare->FA_lower = 0x20; |
| 595 | } |
| 596 | else |
| 597 | #endif |
| 598 | { |
| 599 | #ifdef INTERFERENCE_CONTROL |
| 600 | priv->pshare->FA_lower = 0x20; |
| 601 | |
| 602 | if (priv->pshare->rssi_min != 0xFF) |
| 603 | { |
| 604 | // priv->pshare->FA_upper = 0x3E; |
| 605 | |
| 606 | if (priv->pshare->rssi_min > 30) |
| 607 | priv->pshare->FA_lower = 0x24; |
| 608 | else if (priv->pshare->rssi_min > 25) |
| 609 | priv->pshare->FA_lower = 0x22; |
| 610 | |
| 611 | // limit upper bound to prevent the minimal signal sta from disconnect |
| 612 | // if ((priv->pshare->rssi_min + 10) < priv->pshare->FA_upper) |
| 613 | // priv->pshare->FA_upper = priv->pshare->rssi_min + 10; |
| 614 | priv->pshare->FA_upper = MIN_NUM(0x3E, priv->pshare->rssi_min+20); |
| 615 | } |
| 616 | else // before link |
| 617 | { |
| 618 | priv->pshare->FA_upper = 0x32; |
| 619 | |
| 620 | thd0 = 500; |
| 621 | thd1 = 8000; |
| 622 | thd2 = 10000; |
| 623 | } |
| 624 | #else |
| 625 | if (priv->pmib->dot11RFEntry.tx2path) { |
| 626 | if (priv->pmib->dot11BssType.net_work_type == WIRELESS_11B) |
| 627 | priv->pshare->FA_upper = MIN_NUM(0x2A, priv->pshare->rssi_min+10); |
| 628 | else |
| 629 | priv->pshare->FA_upper = MIN_NUM(0x3E, priv->pshare->rssi_min+10); |
| 630 | } |
| 631 | else |
| 632 | priv->pshare->FA_upper = MIN_NUM(0x3E, priv->pshare->rssi_min+10); |
| 633 | priv->pshare->FA_lower = 0x20; |
| 634 | |
| 635 | if (priv->pshare->rssi_min > 30) |
| 636 | priv->pshare->FA_lower = 0x24; |
| 637 | else if (priv->pshare->rssi_min > 25) |
| 638 | priv->pshare->FA_lower = 0x22; |
| 639 | #endif |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | // determine a new initial gain index according to the sumation of all FA counters as well as upper & lower bounds |
| 644 | value8 = RTL_R8(0xc50); |
| 645 | #if defined(CONFIG_RTL_92C_SUPPORT) || defined(CONFIG_RTL_92D_SUPPORT) |
| 646 | if ( |
| 647 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 648 | (GET_CHIP_VER(priv)==VERSION_8192C) || (GET_CHIP_VER(priv)==VERSION_8188C) |
| 649 | #endif |
| 650 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 651 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 652 | || |
| 653 | #endif |
| 654 | (GET_CHIP_VER(priv)==VERSION_8192D) |
| 655 | #endif |
| 656 | ) { |
| 657 | if(priv->pshare->rf_ft_var.one_path_cca==2) |
| 658 | value8 = RTL_R8(0xc58); |
| 659 | } |
| 660 | #endif |
| 661 | |
| 662 | value_IGI = (value8 & 0x7F); |
| 663 | |
| 664 | #if defined(CONFIG_RTL_NOISE_CONTROL_92C) |
| 665 | if(priv->pshare->rf_ft_var.dnc_enable) |
| 666 | if ((GET_CHIP_VER(priv) == VERSION_8192C)||(GET_CHIP_VER(priv) == VERSION_8188C)){ |
| 667 | unsigned long tp_now = (priv->ext_stats.tx_avarage+priv->ext_stats.rx_avarage)>>17; |
| 668 | #ifdef HIGH_POWER_EXT_LNA |
| 669 | if(priv->pshare->rf_ft_var.use_ext_lna) { |
| 670 | if( (priv->pshare->rssi_min > 50) ) { |
| 671 | if((!priv->pshare->DNC_on) && (value_IGI >= priv->pshare->FA_upper) && (priv->pshare->FA_total_cnt > priv->pshare->threshold2)) { |
| 672 | priv->pshare->DNC_on = 1; |
| 673 | priv->ext_stats.tp_average_pre = tp_now; |
| 674 | priv->pshare->FA_lower = 0x20; |
| 675 | phy_set_bb_reg(priv, 0x870, bMaskDWord, RTL_R32(0x870)|BIT(5)|BIT(6)|BIT(21)|BIT(22)); |
| 676 | |
| 677 | #ifdef HW_ANT_SWITCH |
| 678 | phy_set_bb_reg(priv, 0xc50, bMaskByte0, priv->pshare->FA_lower | RXDVY_A_EN); |
| 679 | phy_set_bb_reg(priv, 0xc58, bMaskByte0, priv->pshare->FA_lower | RXDVY_B_EN); |
| 680 | #else |
| 681 | phy_set_bb_reg(priv, 0xc50, bMaskByte0, priv->pshare->FA_lower); |
| 682 | phy_set_bb_reg(priv, 0xc58, bMaskByte0, priv->pshare->FA_lower); |
| 683 | #endif |
| 684 | |
| 685 | } else if(priv->pshare->DNC_on ==1) { |
| 686 | if(tp_now < priv->ext_stats.tp_average_pre + 2) { |
| 687 | priv->pshare->DNC_on = 0; |
| 688 | } |
| 689 | else { |
| 690 | priv->pshare->DNC_on =2; |
| 691 | priv->ext_stats.tp_average_pre = tp_now; |
| 692 | } |
| 693 | } else if(priv->pshare->DNC_on >= 2 ) { |
| 694 | if(( tp_now+10 < priv->ext_stats.tp_average_pre ) || (tp_now < 1) ) { |
| 695 | priv->pshare->DNC_on = 0; |
| 696 | } else if(priv->pshare->DNC_on<5) { |
| 697 | priv->ext_stats.tp_average_pre = tp_now; |
| 698 | ++priv->pshare->DNC_on; |
| 699 | } |
| 700 | } |
| 701 | }else { |
| 702 | priv->pshare->DNC_on = 0; |
| 703 | } |
| 704 | |
| 705 | if( priv->pshare->DNC_on ) |
| 706 | return; |
| 707 | else |
| 708 | phy_set_bb_reg(priv, 0x870, bMaskDWord, RTL_R32(0x870)& ~(BIT(5)|BIT(6)|BIT(21)|BIT(22))); |
| 709 | |
| 710 | } else |
| 711 | #endif |
| 712 | { |
| 713 | if( (priv->pshare->rssi_min > 40) && (value_IGI >= priv->pshare->FA_upper) ) { |
| 714 | // unsigned long tp_now = (priv->ext_stats.tx_avarage+priv->ext_stats.rx_avarage)>>17; |
| 715 | if((!priv->pshare->DNC_on) && (priv->pshare->FA_total_cnt > priv->pshare->threshold2)) { |
| 716 | priv->pshare->DNC_on = 1; |
| 717 | priv->ext_stats.tp_average_pre = tp_now; |
| 718 | } else if(priv->pshare->DNC_on ==1) { |
| 719 | if(tp_now < priv->ext_stats.tp_average_pre + 2) { |
| 720 | priv->pshare->DNC_on = 0; |
| 721 | } |
| 722 | else { |
| 723 | priv->pshare->DNC_on = 2; |
| 724 | priv->ext_stats.tp_average_pre = tp_now; |
| 725 | } |
| 726 | } else if(priv->pshare->DNC_on >= 2 ) { |
| 727 | if((tp_now +10 < priv->ext_stats.tp_average_pre ) |
| 728 | || ((priv->ext_stats.tp_average_pre < 10) && (priv->pshare->FA_total_cnt < priv->pshare->threshold1))) { |
| 729 | priv->pshare->DNC_on = 0; |
| 730 | } else if(priv->pshare->DNC_on<6) { |
| 731 | priv->ext_stats.tp_average_pre = tp_now; |
| 732 | ++priv->pshare->DNC_on; |
| 733 | } |
| 734 | } |
| 735 | if(priv->pshare->DNC_on) { |
| 736 | priv->pshare->FA_upper = 0x3e; |
| 737 | } |
| 738 | }else { |
| 739 | priv->pshare->DNC_on = 0; |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | #endif |
| 744 | |
| 745 | if ((priv->pshare->digDeadPoint == 0) && (priv->pshare->FA_total_cnt > DEAD_POINT_TH)) { |
| 746 | if ((priv->pshare->digDeadPointHitCount > 0) && (priv->pshare->digDeadPointCandidate == value_IGI)) { |
| 747 | priv->pshare->digDeadPointHitCount++; |
| 748 | if (priv->pshare->digDeadPointHitCount == DEAD_POINT_HIT_TH) { |
| 749 | priv->pshare->digDeadPoint = priv->pshare->digDeadPointCandidate; |
| 750 | } |
| 751 | } else { |
| 752 | priv->pshare->digDeadPointCandidate = value_IGI; |
| 753 | priv->pshare->digDeadPointHitCount = 1; |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | #ifdef INTERFERENCE_CONTROL |
| 758 | if (priv->pshare->FA_total_cnt < thd0) { |
| 759 | #else |
| 760 | if (priv->pshare->FA_total_cnt < priv->pshare->threshold0) { |
| 761 | #endif |
| 762 | priv->pshare->digDownCount++; |
| 763 | if (priv->pshare->digDownCount > DOWN_IG_HIT_TH) { |
| 764 | // Reset deadpoint hit count |
| 765 | if ((priv->pshare->digDeadPoint == 0) && (priv->pshare->digDeadPointHitCount > 0) && (value_IGI == priv->pshare->digDeadPointCandidate)) |
| 766 | priv->pshare->digDeadPointHitCount = 0; |
| 767 | |
| 768 | value_IGI--; |
| 769 | |
| 770 | // Check if the new value is dead point |
| 771 | if ((priv->pshare->digDeadPoint > 0) && (value_IGI == priv->pshare->digDeadPoint)) |
| 772 | value_IGI++; |
| 773 | } |
| 774 | #ifdef INTERFERENCE_CONTROL |
| 775 | } else if (priv->pshare->FA_total_cnt < thd1) { |
| 776 | #else |
| 777 | } else if (priv->pshare->FA_total_cnt < priv->pshare->threshold1) { |
| 778 | #endif |
| 779 | value_IGI += 0; |
| 780 | priv->pshare->digDownCount = 0; |
| 781 | #ifdef INTERFERENCE_CONTROL |
| 782 | } else if (priv->pshare->FA_total_cnt < thd2) { |
| 783 | #else |
| 784 | } else if (priv->pshare->FA_total_cnt < priv->pshare->threshold2) { |
| 785 | #endif |
| 786 | value_IGI++; |
| 787 | priv->pshare->digDownCount = 0; |
| 788 | #ifdef INTERFERENCE_CONTROL |
| 789 | } else if (priv->pshare->FA_total_cnt >= thd2) { |
| 790 | #else |
| 791 | } else if (priv->pshare->FA_total_cnt >= priv->pshare->threshold2) { |
| 792 | #endif |
| 793 | value_IGI += 2; |
| 794 | priv->pshare->digDownCount = 0; |
| 795 | } else { |
| 796 | priv->pshare->digDownCount = 0; |
| 797 | } |
| 798 | |
| 799 | if (value_IGI > priv->pshare->FA_upper) |
| 800 | value_IGI = priv->pshare->FA_upper; |
| 801 | else if (value_IGI < priv->pshare->FA_lower) |
| 802 | value_IGI = priv->pshare->FA_lower; |
| 803 | if (priv->pshare->rf_ft_var.adaptivity_enable && priv->pshare->rf_ft_var.adaptivity_flag == TRUE) |
| 804 | { |
| 805 | Adap_IGI_Upper = priv->pshare->rf_ft_var.adaptivity_igi_upper; |
| 806 | if(value_IGI > Adap_IGI_Upper) |
| 807 | value_IGI = Adap_IGI_Upper; |
| 808 | } |
| 809 | |
| 810 | #if defined(HW_ANT_SWITCH) |
| 811 | // wirte new initial gain index into regC50/C58 |
| 812 | if (priv->pshare->rf_ft_var.one_path_cca == 0) { |
| 813 | if (!(ODMPTR->support_ability & ODM_BB_ANT_DIV)) |
| 814 | RTL_W8(0xc50, value_IGI); |
| 815 | else |
| 816 | RTL_W8(0xc50, value_IGI | RXDVY_A_EN); |
| 817 | #if defined(CONFIG_RTL_92C_SUPPORT) || defined(CONFIG_RTL_92D_SUPPORT) |
| 818 | if ( |
| 819 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 820 | (GET_CHIP_VER(priv)==VERSION_8192C) || (GET_CHIP_VER(priv)==VERSION_8188C) |
| 821 | #endif |
| 822 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 823 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 824 | || |
| 825 | #endif |
| 826 | (GET_CHIP_VER(priv)==VERSION_8192D) |
| 827 | #endif |
| 828 | ) |
| 829 | RTL_W8(0xc58, value_IGI | RXDVY_B_EN); |
| 830 | #endif |
| 831 | } else if (priv->pshare->rf_ft_var.one_path_cca == 1) { |
| 832 | if (!(ODMPTR->support_ability & ODM_BB_ANT_DIV)) |
| 833 | RTL_W8(0xc50, value_IGI); |
| 834 | else |
| 835 | RTL_W8(0xc50, value_IGI | RXDVY_A_EN); |
| 836 | #if defined(CONFIG_RTL_92C_SUPPORT) || defined(CONFIG_RTL_92D_SUPPORT) |
| 837 | if ( |
| 838 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 839 | (GET_CHIP_VER(priv)==VERSION_8192C) || (GET_CHIP_VER(priv)==VERSION_8188C) |
| 840 | #endif |
| 841 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 842 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 843 | || |
| 844 | #endif |
| 845 | (GET_CHIP_VER(priv)==VERSION_8192D) |
| 846 | #endif |
| 847 | ) |
| 848 | RTL_W8(0xc58, getIGIFor1RCCA(value_IGI) | RXDVY_B_EN); |
| 849 | #endif |
| 850 | } else if (priv->pshare->rf_ft_var.one_path_cca == 2) { |
| 851 | if (!(ODMPTR->support_ability & ODM_BB_ANT_DIV)) |
| 852 | RTL_W8(0xc50, value_IGI); |
| 853 | else |
| 854 | RTL_W8(0xc50, getIGIFor1RCCA(value_IGI) | RXDVY_A_EN); |
| 855 | #if defined(CONFIG_RTL_92C_SUPPORT) || defined(CONFIG_RTL_92D_SUPPORT) |
| 856 | if ( |
| 857 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 858 | (GET_CHIP_VER(priv)==VERSION_8192C) || (GET_CHIP_VER(priv)==VERSION_8188C) |
| 859 | #endif |
| 860 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 861 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 862 | || |
| 863 | #endif |
| 864 | (GET_CHIP_VER(priv)==VERSION_8192D) |
| 865 | #endif |
| 866 | ) |
| 867 | RTL_W8(0xc58, value_IGI| RXDVY_B_EN); |
| 868 | #endif |
| 869 | } |
| 870 | #else |
| 871 | // Write IGI into HW |
| 872 | if (priv->pshare->rf_ft_var.one_path_cca == 0) { |
| 873 | RTL_W8(0xc50, value_IGI); |
| 874 | #if defined(CONFIG_RTL_92C_SUPPORT) || defined(CONFIG_RTL_92D_SUPPORT) |
| 875 | if ( |
| 876 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 877 | (GET_CHIP_VER(priv)==VERSION_8192C) || (GET_CHIP_VER(priv)==VERSION_8188C) |
| 878 | #endif |
| 879 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 880 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 881 | || |
| 882 | #endif |
| 883 | (GET_CHIP_VER(priv)==VERSION_8192D) |
| 884 | #endif |
| 885 | ) |
| 886 | RTL_W8(0xc58, value_IGI); |
| 887 | #endif |
| 888 | } else if (priv->pshare->rf_ft_var.one_path_cca == 1) { |
| 889 | RTL_W8(0xc50, value_IGI); |
| 890 | #if defined(CONFIG_RTL_92C_SUPPORT) || defined(CONFIG_RTL_92D_SUPPORT) |
| 891 | if ( |
| 892 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 893 | (GET_CHIP_VER(priv)==VERSION_8192C) || (GET_CHIP_VER(priv)==VERSION_8188C) |
| 894 | #endif |
| 895 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 896 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 897 | || |
| 898 | #endif |
| 899 | (GET_CHIP_VER(priv)==VERSION_8192D) |
| 900 | #endif |
| 901 | ) |
| 902 | RTL_W8(0xc58, getIGIFor1RCCA(value_IGI)); |
| 903 | #endif |
| 904 | } else if (priv->pshare->rf_ft_var.one_path_cca == 2) { |
| 905 | RTL_W8(0xc50, getIGIFor1RCCA(value_IGI)); |
| 906 | #if defined(CONFIG_RTL_92C_SUPPORT) || defined(CONFIG_RTL_92D_SUPPORT) |
| 907 | if ( |
| 908 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 909 | (GET_CHIP_VER(priv)==VERSION_8192C) || (GET_CHIP_VER(priv)==VERSION_8188C) |
| 910 | #endif |
| 911 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 912 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 913 | || |
| 914 | #endif |
| 915 | (GET_CHIP_VER(priv)==VERSION_8192D) |
| 916 | #endif |
| 917 | ) |
| 918 | RTL_W8(0xc58, value_IGI); |
| 919 | #endif |
| 920 | } |
| 921 | #endif |
| 922 | |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | #if 0 |
| 927 | void check_DIG_by_rssi(struct rtl8192cd_priv *priv, unsigned char rssi_strength) |
| 928 | { |
| 929 | unsigned int dig_on = 0; |
| 930 | |
| 931 | if (OPMODE & WIFI_SITE_MONITOR) |
| 932 | return; |
| 933 | |
| 934 | if ((rssi_strength > priv->pshare->rf_ft_var.digGoUpperLevel) |
| 935 | && (rssi_strength < HP_LOWER+1) && (priv->pshare->phw->signal_strength != 2)) { |
| 936 | #ifndef CONFIG_RTL_92D_SUPPORT |
| 937 | if (priv->pshare->is_40m_bw) |
| 938 | // RTL_W8(0xc87, (RTL_R8(0xc87) & 0xf) | 0x30); 92D |
| 939 | RTL_W8(0xc87, 0x30); |
| 940 | else |
| 941 | RTL_W8(0xc30, 0x44); |
| 942 | #endif |
| 943 | |
| 944 | if (priv->pshare->phw->signal_strength != 3) |
| 945 | dig_on++; |
| 946 | |
| 947 | priv->pshare->phw->signal_strength = 2; |
| 948 | } |
| 949 | else if ((rssi_strength > HP_LOWER+5) && (priv->pshare->phw->signal_strength != 3)) { |
| 950 | #ifndef CONFIG_RTL_92D_SUPPORT |
| 951 | if (priv->pshare->is_40m_bw) |
| 952 | // RTL_W8(0xc87, (RTL_R8(0xc87) & 0xf) | 0x30); 92D |
| 953 | RTL_W8(0xc87, 0x30); |
| 954 | else |
| 955 | RTL_W8(0xc30, 0x44); |
| 956 | #endif |
| 957 | |
| 958 | if (priv->pshare->phw->signal_strength != 2) |
| 959 | dig_on++; |
| 960 | |
| 961 | priv->pshare->phw->signal_strength = 3; |
| 962 | } |
| 963 | else if (((rssi_strength < priv->pshare->rf_ft_var.digGoLowerLevel) |
| 964 | && (priv->pshare->phw->signal_strength != 1)) || !priv->pshare->phw->signal_strength) { |
| 965 | // DIG off |
| 966 | // set_DIG_state(priv, 0); |
| 967 | |
| 968 | #ifndef CONFIG_RTL_92D_SUPPORT |
| 969 | if (priv->pshare->is_40m_bw) |
| 970 | //RTL_W8(0xc87, (RTL_R8(0xc87) & 0xf) | 0x30); 92D |
| 971 | RTL_W8(0xc87, 0x30); |
| 972 | else |
| 973 | RTL_W8(0xc30, 0x44); |
| 974 | #endif |
| 975 | |
| 976 | priv->pshare->phw->signal_strength = 1; |
| 977 | } |
| 978 | |
| 979 | if (dig_on) { |
| 980 | // DIG on |
| 981 | set_DIG_state(priv, 1); |
| 982 | } |
| 983 | |
| 984 | //check_DC_TH_by_rssi(priv, rssi_strength); |
| 985 | } |
| 986 | |
| 987 | |
| 988 | void DIG_for_site_survey(struct rtl8192cd_priv *priv, int do_ss) |
| 989 | { |
| 990 | if (do_ss) { |
| 991 | // DIG off |
| 992 | set_DIG_state(priv, 0); |
| 993 | } |
| 994 | else { |
| 995 | // DIG on |
| 996 | #ifndef INTERFERENCE_CONTROL |
| 997 | if (priv->pshare->phw->signal_strength > 1) |
| 998 | #endif |
| 999 | { |
| 1000 | set_DIG_state(priv, 1); |
| 1001 | } |
| 1002 | } |
| 1003 | } |
| 1004 | #endif |
| 1005 | |
| 1006 | #if 0 |
| 1007 | //#ifdef INTERFERENCE_CONTROL |
| 1008 | void check_NBI_by_rssi(struct rtl8192cd_priv *priv, unsigned char rssi_strength) |
| 1009 | { |
| 1010 | if (OPMODE & WIFI_SITE_MONITOR) |
| 1011 | return; |
| 1012 | |
| 1013 | if (priv->pshare->phw->nbi_filter_on) { |
| 1014 | if (rssi_strength < 20) { |
| 1015 | priv->pshare->phw->nbi_filter_on = 0; |
| 1016 | RTL_W16(rOFDM0_RxDSP, RTL_R16(rOFDM0_RxDSP) & ~ BIT(9)); // NBI off |
| 1017 | } |
| 1018 | } else { // NBI OFF previous |
| 1019 | if (rssi_strength > 25) { |
| 1020 | priv->pshare->phw->nbi_filter_on = 1; |
| 1021 | RTL_W16(rOFDM0_RxDSP, RTL_R16(rOFDM0_RxDSP) | BIT(9)); // NBI on |
| 1022 | } |
| 1023 | } |
| 1024 | } |
| 1025 | #endif |
| 1026 | |
| 1027 | /* |
| 1028 | * dynamic CCK CCA enhance by rssi |
| 1029 | */ |
| 1030 | void CCK_CCA_dynamic_enhance(struct rtl8192cd_priv *priv, unsigned char rssi_strength) |
| 1031 | { |
| 1032 | #if 1 |
| 1033 | unsigned int cck_fa = priv->pshare->FA_total_cnt; |
| 1034 | int rssi_thd = 30; |
| 1035 | |
| 1036 | if (rssi_strength == 0xff) { |
| 1037 | if (cck_fa < 1000) { |
| 1038 | if (priv->pshare->phw->CCK_CCA_enhanced != 2) { |
| 1039 | RTL_W8(0xa0a, 0x40); |
| 1040 | priv->pshare->phw->CCK_CCA_enhanced = 2; |
| 1041 | } |
| 1042 | } else { |
| 1043 | if (priv->pshare->phw->CCK_CCA_enhanced != 1) { |
| 1044 | RTL_W8(0xa0a, 0x83); |
| 1045 | priv->pshare->phw->CCK_CCA_enhanced = 1; |
| 1046 | } |
| 1047 | } |
| 1048 | return; |
| 1049 | } |
| 1050 | |
| 1051 | if (rssi_strength > rssi_thd+5) { |
| 1052 | if (priv->pshare->phw->CCK_CCA_enhanced != 0) { |
| 1053 | RTL_W8(0xa0a, 0xcd); |
| 1054 | priv->pshare->phw->CCK_CCA_enhanced = 0; |
| 1055 | } |
| 1056 | } else if (rssi_strength< rssi_thd) { |
| 1057 | if ((rssi_strength > 9) || (priv->assoc_num >1)) { |
| 1058 | if (priv->pshare->phw->CCK_CCA_enhanced != 1) { |
| 1059 | RTL_W8(0xa0a, 0x83); |
| 1060 | priv->pshare->phw->CCK_CCA_enhanced = 1; |
| 1061 | } |
| 1062 | } else { |
| 1063 | if(cck_fa<1000) { |
| 1064 | if (priv->pshare->phw->CCK_CCA_enhanced != 2) { |
| 1065 | RTL_W8(0xa0a, 0x40); |
| 1066 | priv->pshare->phw->CCK_CCA_enhanced = 2; |
| 1067 | } |
| 1068 | } else { |
| 1069 | if (priv->pshare->phw->CCK_CCA_enhanced != 1) { |
| 1070 | RTL_W8(0xa0a, 0x83); |
| 1071 | priv->pshare->phw->CCK_CCA_enhanced = 1; |
| 1072 | } |
| 1073 | } |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | #else |
| 1078 | |
| 1079 | if (rssi_strength == 0xff) |
| 1080 | return; |
| 1081 | |
| 1082 | if (!priv->pshare->phw->CCK_CCA_enhanced && (rssi_strength < 30)) { |
| 1083 | priv->pshare->phw->CCK_CCA_enhanced = TRUE; |
| 1084 | RTL_W8(0xa0a, 0x83); |
| 1085 | } |
| 1086 | else if (priv->pshare->phw->CCK_CCA_enhanced && (rssi_strength > 35)) { |
| 1087 | priv->pshare->phw->CCK_CCA_enhanced = FALSE; |
| 1088 | RTL_W8(0xa0a, 0xcd); |
| 1089 | } |
| 1090 | #endif |
| 1091 | } |
| 1092 | |
| 1093 | |
| 1094 | //3 ============================================================ |
| 1095 | //3 Dynamic Tx Power / Power Tracking |
| 1096 | //3 ============================================================ |
| 1097 | |
| 1098 | #ifdef HIGH_POWER_EXT_PA |
| 1099 | void tx_power_control(struct rtl8192cd_priv *priv) |
| 1100 | { |
| 1101 | #ifndef SMP_SYNC |
| 1102 | unsigned long x; |
| 1103 | #endif |
| 1104 | |
| 1105 | int pwr_value = 0x10101010; |
| 1106 | if( priv->pshare->phw->signal_strength == 3 && priv->pshare->phw->lower_tx_power== 0) { |
| 1107 | SAVE_INT_AND_CLI(x); |
| 1108 | priv->pshare->phw->power_backup[0x00] = RTL_R32(REG_TX_AGC_A_RATE18_06); |
| 1109 | priv->pshare->phw->power_backup[0x01] = RTL_R32(REG_TX_AGC_A_RATE54_24); |
| 1110 | priv->pshare->phw->power_backup[0x02] = RTL_R32(REG_TX_AGC_B_RATE18_06); |
| 1111 | priv->pshare->phw->power_backup[0x03] = RTL_R32(REG_TX_AGC_B_RATE54_24); |
| 1112 | priv->pshare->phw->power_backup[0x04] = RTL_R32(REG_TX_AGC_A_MCS03_MCS00); |
| 1113 | priv->pshare->phw->power_backup[0x05] = RTL_R32(REG_TX_AGC_A_MCS07_MCS04); |
| 1114 | priv->pshare->phw->power_backup[0x06] = RTL_R32(REG_TX_AGC_A_MCS11_MCS08); |
| 1115 | priv->pshare->phw->power_backup[0x07] = RTL_R32(REG_TX_AGC_A_MCS15_MCS12); |
| 1116 | priv->pshare->phw->power_backup[0x08] = RTL_R32(REG_TX_AGC_B_MCS03_MCS00); |
| 1117 | priv->pshare->phw->power_backup[0x09] = RTL_R32(REG_TX_AGC_B_MCS07_MCS04); |
| 1118 | priv->pshare->phw->power_backup[0x0a] = RTL_R32(REG_TX_AGC_B_MCS11_MCS08); |
| 1119 | priv->pshare->phw->power_backup[0x0b] = RTL_R32(REG_TX_AGC_B_MCS15_MCS12); |
| 1120 | priv->pshare->phw->power_backup[0x0c] = RTL_R32(rTxAGC_A_CCK11_2_B_CCK11); |
| 1121 | priv->pshare->phw->power_backup[0x0d] = RTL_R32(REG_TX_AGC_A_CCK_1_MCS32); |
| 1122 | priv->pshare->phw->power_backup[0x0e] = RTL_R32(rTxAGC_B_CCK5_1_Mcs32); |
| 1123 | RTL_W32(REG_TX_AGC_A_RATE18_06, pwr_value); |
| 1124 | RTL_W32(REG_TX_AGC_A_RATE54_24, pwr_value); |
| 1125 | RTL_W32(REG_TX_AGC_B_RATE18_06, pwr_value); |
| 1126 | RTL_W32(REG_TX_AGC_B_RATE54_24, pwr_value); |
| 1127 | RTL_W32(REG_TX_AGC_A_MCS03_MCS00, pwr_value); |
| 1128 | RTL_W32(REG_TX_AGC_A_MCS07_MCS04, pwr_value); |
| 1129 | RTL_W32(REG_TX_AGC_A_MCS11_MCS08, pwr_value); |
| 1130 | RTL_W32(REG_TX_AGC_A_MCS15_MCS12, pwr_value); |
| 1131 | RTL_W32(REG_TX_AGC_B_MCS03_MCS00, pwr_value); |
| 1132 | RTL_W32(REG_TX_AGC_B_MCS07_MCS04, pwr_value); |
| 1133 | RTL_W32(REG_TX_AGC_B_MCS11_MCS08, pwr_value); |
| 1134 | RTL_W32(REG_TX_AGC_B_MCS15_MCS12, pwr_value); |
| 1135 | RTL_W32(rTxAGC_A_CCK11_2_B_CCK11, pwr_value); |
| 1136 | RTL_W32(REG_TX_AGC_A_CCK_1_MCS32, (pwr_value & 0x0000ff00) | (priv->pshare->phw->power_backup[0x0d] &0xffff00ff)); |
| 1137 | RTL_W32(rTxAGC_B_CCK5_1_Mcs32, (pwr_value & 0xffffff00) | (priv->pshare->phw->power_backup[0x0e] &0x000000ff)); |
| 1138 | priv->pshare->phw->lower_tx_power = 1; |
| 1139 | RESTORE_INT(x); |
| 1140 | } |
| 1141 | else if( priv->pshare->phw->signal_strength != 3 && priv->pshare->phw->lower_tx_power) { |
| 1142 | SAVE_INT_AND_CLI(x); |
| 1143 | RTL_W32(REG_TX_AGC_A_RATE18_06, priv->pshare->phw->power_backup[0x00]); |
| 1144 | RTL_W32(REG_TX_AGC_A_RATE54_24, priv->pshare->phw->power_backup[0x01]); |
| 1145 | RTL_W32(REG_TX_AGC_B_RATE18_06, priv->pshare->phw->power_backup[0x02]); |
| 1146 | RTL_W32(REG_TX_AGC_B_RATE54_24, priv->pshare->phw->power_backup[0x03]); |
| 1147 | RTL_W32(REG_TX_AGC_A_MCS03_MCS00, priv->pshare->phw->power_backup[0x04]); |
| 1148 | RTL_W32(REG_TX_AGC_A_MCS07_MCS04, priv->pshare->phw->power_backup[0x05]); |
| 1149 | RTL_W32(REG_TX_AGC_A_MCS11_MCS08, priv->pshare->phw->power_backup[0x06]); |
| 1150 | RTL_W32(REG_TX_AGC_A_MCS15_MCS12, priv->pshare->phw->power_backup[0x07]); |
| 1151 | RTL_W32(REG_TX_AGC_B_MCS03_MCS00, priv->pshare->phw->power_backup[0x08]); |
| 1152 | RTL_W32(REG_TX_AGC_B_MCS07_MCS04, priv->pshare->phw->power_backup[0x09]); |
| 1153 | RTL_W32(REG_TX_AGC_B_MCS11_MCS08, priv->pshare->phw->power_backup[0x0a]); |
| 1154 | RTL_W32(REG_TX_AGC_B_MCS15_MCS12, priv->pshare->phw->power_backup[0x0b]); |
| 1155 | RTL_W32(rTxAGC_A_CCK11_2_B_CCK11, priv->pshare->phw->power_backup[0x0c]); |
| 1156 | RTL_W32(REG_TX_AGC_A_CCK_1_MCS32, priv->pshare->phw->power_backup[0x0d]); |
| 1157 | RTL_W32(rTxAGC_B_CCK5_1_Mcs32, priv->pshare->phw->power_backup[0x0e]); |
| 1158 | priv->pshare->phw->lower_tx_power = 0; |
| 1159 | RESTORE_INT(x); |
| 1160 | } |
| 1161 | } |
| 1162 | #endif |
| 1163 | |
| 1164 | #if 0 |
| 1165 | int get_CCK_swing_index(struct rtl8192cd_priv *priv) |
| 1166 | { |
| 1167 | int TempCCk, index=12, i; |
| 1168 | short channel; |
| 1169 | #ifdef MP_TEST |
| 1170 | if ((OPMODE & WIFI_MP_STATE) || priv->pshare->rf_ft_var.mp_specific) |
| 1171 | channel=priv->pshare->working_channel; |
| 1172 | else |
| 1173 | #endif |
| 1174 | channel = (priv->pmib->dot11RFEntry.dot11channel); |
| 1175 | |
| 1176 | //Query CCK default setting From 0xa24 |
| 1177 | TempCCk = phy_query_bb_reg(priv, rCCK0_TxFilter2, bMaskDWord)&bMaskCCK; |
| 1178 | TempCCk = cpu_to_le32(TempCCk); |
| 1179 | for(i=0 ; i<CCK_TABLE_SIZE ; i++) { |
| 1180 | if(channel==14) { |
| 1181 | if(memcmp((void*)&TempCCk, (void*)&cck_swing_table_ch14[i][2], 4)==0) { |
| 1182 | index = i; |
| 1183 | break; |
| 1184 | } |
| 1185 | } else { |
| 1186 | if(memcmp((void*)&TempCCk, (void*)&cck_swing_table_ch1_ch13[i][2], 4)==0) { |
| 1187 | index = i; |
| 1188 | break; |
| 1189 | } |
| 1190 | } |
| 1191 | } |
| 1192 | DEBUG_INFO("Initial reg0x%x = 0x%lx, CCK_index=0x%x, ch %d\n", |
| 1193 | rCCK0_TxFilter2, TempCCk, index, channel); |
| 1194 | return index; |
| 1195 | } |
| 1196 | |
| 1197 | |
| 1198 | void set_CCK_swing_index(struct rtl8192cd_priv *priv, short CCK_index) |
| 1199 | { |
| 1200 | short channel; |
| 1201 | #ifdef MP_TEST |
| 1202 | if ((OPMODE & WIFI_MP_STATE) || priv->pshare->rf_ft_var.mp_specific) |
| 1203 | channel=priv->pshare->working_channel; |
| 1204 | else |
| 1205 | #endif |
| 1206 | channel = (priv->pmib->dot11RFEntry.dot11channel); |
| 1207 | |
| 1208 | |
| 1209 | #ifdef CONFIG_RTL_88E_SUPPORT /*for 88e tx power tracking*/ |
| 1210 | if(GET_CHIP_VER(priv) == VERSION_8188E){ |
| 1211 | if(channel !=14) { |
| 1212 | RTL_W8( 0xa22, 0x1c); |
| 1213 | RTL_W8( 0xa23, 0x1a); |
| 1214 | RTL_W8( 0xa24, 0x18); |
| 1215 | RTL_W8( 0xa25, 0x12); |
| 1216 | RTL_W8( 0xa26, 0xe); |
| 1217 | RTL_W8( 0xa27, 0x8); |
| 1218 | RTL_W8( 0xa28, 0x4); |
| 1219 | RTL_W8( 0xa29, 0x2); |
| 1220 | } |
| 1221 | else{ |
| 1222 | RTL_W8( 0xa22, 0x1c); |
| 1223 | RTL_W8( 0xa23, 0x1a); |
| 1224 | RTL_W8( 0xa24, 0x18); |
| 1225 | RTL_W8( 0xa25, 0x12); |
| 1226 | RTL_W8( 0xa26, 0x0); |
| 1227 | RTL_W8( 0xa27, 0x0); |
| 1228 | RTL_W8( 0xa28, 0x0); |
| 1229 | RTL_W8( 0xa29, 0x0); |
| 1230 | } |
| 1231 | } |
| 1232 | else |
| 1233 | #endif |
| 1234 | if(channel !=14) { |
| 1235 | RTL_W8( 0xa22, cck_swing_table_ch1_ch13[CCK_index][0]); |
| 1236 | RTL_W8( 0xa23, cck_swing_table_ch1_ch13[CCK_index][1]); |
| 1237 | RTL_W8( 0xa24, cck_swing_table_ch1_ch13[CCK_index][2]); |
| 1238 | RTL_W8( 0xa25, cck_swing_table_ch1_ch13[CCK_index][3]); |
| 1239 | RTL_W8( 0xa26, cck_swing_table_ch1_ch13[CCK_index][4]); |
| 1240 | RTL_W8( 0xa27, cck_swing_table_ch1_ch13[CCK_index][5]); |
| 1241 | RTL_W8( 0xa28, cck_swing_table_ch1_ch13[CCK_index][6]); |
| 1242 | RTL_W8( 0xa29, cck_swing_table_ch1_ch13[CCK_index][7]); |
| 1243 | } |
| 1244 | else{ |
| 1245 | RTL_W8( 0xa22, cck_swing_table_ch14[CCK_index][0]); |
| 1246 | RTL_W8( 0xa23, cck_swing_table_ch14[CCK_index][1]); |
| 1247 | RTL_W8( 0xa24, cck_swing_table_ch14[CCK_index][2]); |
| 1248 | RTL_W8( 0xa25, cck_swing_table_ch14[CCK_index][3]); |
| 1249 | RTL_W8( 0xa26, cck_swing_table_ch14[CCK_index][4]); |
| 1250 | RTL_W8( 0xa27, cck_swing_table_ch14[CCK_index][5]); |
| 1251 | RTL_W8( 0xa28, cck_swing_table_ch14[CCK_index][6]); |
| 1252 | RTL_W8( 0xa29, cck_swing_table_ch14[CCK_index][7]); |
| 1253 | } |
| 1254 | } |
| 1255 | #endif |
| 1256 | |
| 1257 | unsigned char getThermalValue(struct rtl8192cd_priv *priv) |
| 1258 | { |
| 1259 | unsigned char ThermalValue; |
| 1260 | int sum=0, i=0; |
| 1261 | phy_set_rf_reg(priv, RF_PATH_A, RF_T_METER, bMask20Bits, 0x60); |
| 1262 | while ((phy_query_rf_reg(priv, RF_PATH_A, RF_T_METER, bMask20Bits, 1) > 0x1f) && ((i++) < 1000)) {//<20ms, test is in 20 us |
| 1263 | delay_us(20); |
| 1264 | } |
| 1265 | ThermalValue =(unsigned char)phy_query_rf_reg(priv, RF_PATH_A, RF_T_METER, bMask20Bits, 1) & 0x01f; |
| 1266 | priv->pshare->Thermal_idx = (priv->pshare->Thermal_idx+1)%8; |
| 1267 | priv->pshare->Thermal_log[ priv->pshare->Thermal_idx ] = ThermalValue; |
| 1268 | for(i=0; i<8; i++) { |
| 1269 | if(!priv->pshare->Thermal_log[i]) |
| 1270 | return ThermalValue; |
| 1271 | sum += priv->pshare->Thermal_log[i]; |
| 1272 | } |
| 1273 | return (sum+4)>>3; |
| 1274 | } |
| 1275 | |
| 1276 | |
| 1277 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 1278 | |
| 1279 | #ifdef HIGH_POWER_EXT_PA |
| 1280 | void swingIndexRemap2(int *a, int b, int i) |
| 1281 | { |
| 1282 | |
| 1283 | u8 index_mapping_HighPower_92C[4][15] = { |
| 1284 | {0, 1, 3, 4, 6, 7, 9, 10, 12, 13, 15, 16, 18, 18, 18}, //2.4G, path A/MAC 0, decrease power |
| 1285 | {0, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22}, //2.4G, path A/MAC 0, increase power |
| 1286 | {0, 1, 3, 4, 6, 7, 9, 10, 12, 13, 15, 16, 18, 18, 18}, //2.4G, path A/MAC 0, decrease power |
| 1287 | {0, 3, 5, 6, 8, 9, 11, 12, 14, 15, 17, 18, 20, 21, 23}, //2.4G, path A/MAC 0, increase power |
| 1288 | }; |
| 1289 | |
| 1290 | int d = RTL_ABS(*a, b); |
| 1291 | int offset = 0; |
| 1292 | |
| 1293 | |
| 1294 | if(i == 0) |
| 1295 | offset = 1; |
| 1296 | else |
| 1297 | offset = 3; |
| 1298 | |
| 1299 | if(*a < b ) |
| 1300 | { |
| 1301 | //printk("\n\n Increase Power !! \n\n"); |
| 1302 | *a = b - index_mapping_HighPower_92C[offset][d]; |
| 1303 | } |
| 1304 | else |
| 1305 | { |
| 1306 | //printk("\n\n Decrease Power !! \n\n"); |
| 1307 | offset = offset - 1; |
| 1308 | *a = b + index_mapping_HighPower_92C[offset][d]; |
| 1309 | } |
| 1310 | |
| 1311 | //printk("\n\ a = %d, b = %d, offset = %d, d = %d, diff = %d \n\n", |
| 1312 | //*a, b, offset, d, index_mapping_HighPower_92C[offset][d]); |
| 1313 | |
| 1314 | } |
| 1315 | void swingIndexRemap(int *a, int b) |
| 1316 | { |
| 1317 | int d = (RTL_ABS(*a, b) *3)>>1; |
| 1318 | if(*a < b ) |
| 1319 | *a = b - d; |
| 1320 | else |
| 1321 | *a = b + d; |
| 1322 | } |
| 1323 | #endif |
| 1324 | |
| 1325 | void tx_power_tracking(struct rtl8192cd_priv *priv) |
| 1326 | { |
| 1327 | unsigned char ThermalValue = 0, delta, delta_LCK, delta_IQK; |
| 1328 | int ele_A, ele_D, value32, X, Y, ele_C; |
| 1329 | int OFDM_index[2]={0,0}, CCK_index; |
| 1330 | int i = 0; |
| 1331 | char is2T = ((GET_CHIP_VER(priv) == VERSION_8192C) ?1 :0); |
| 1332 | unsigned char TxPwrLevel[2]; |
| 1333 | unsigned char channel, OFDM_min_index = 6, rf=1; //OFDM BB Swing should be less than +3.0dB, which is required by Arthur |
| 1334 | #ifdef POWER_PERCENT_ADJUSTMENT |
| 1335 | signed char pwrdiff_percent; |
| 1336 | #endif |
| 1337 | #ifdef MP_TEST |
| 1338 | if ((OPMODE & WIFI_MP_STATE) || priv->pshare->rf_ft_var.mp_specific) { |
| 1339 | channel=priv->pshare->working_channel; |
| 1340 | if(priv->pshare->mp_txpwr_tracking == FALSE) |
| 1341 | return; |
| 1342 | } else |
| 1343 | #endif |
| 1344 | { |
| 1345 | channel = (priv->pmib->dot11RFEntry.dot11channel); |
| 1346 | } |
| 1347 | |
| 1348 | ThermalValue = getThermalValue(priv); |
| 1349 | |
| 1350 | rf += is2T; |
| 1351 | if(ThermalValue) { |
| 1352 | |
| 1353 | if(!priv->pshare->thermal_value) { |
| 1354 | priv->pshare->thermal_value = priv->pmib->dot11RFEntry.ther; |
| 1355 | priv->pshare->thermal_value_lck = ThermalValue; |
| 1356 | priv->pshare->thermal_value_iqk = ThermalValue; |
| 1357 | |
| 1358 | //Query OFDM path A default setting |
| 1359 | ele_D = phy_query_bb_reg(priv, REG_OFDM_0_XA_TX_IQ_IMBALANCE, bMaskDWord)&bMaskOFDM_D; |
| 1360 | for(i=0; i<OFDM_TABLE_SIZE; i++) { |
| 1361 | if(ele_D == (ofdm_swing_table[i]&bMaskOFDM_D)) { |
| 1362 | priv->pshare->OFDM_index[0] = i; |
| 1363 | priv->pshare->OFDM_index0[0] = i; |
| 1364 | break; |
| 1365 | } |
| 1366 | } |
| 1367 | |
| 1368 | //Query OFDM path B default setting |
| 1369 | if(is2T) { |
| 1370 | ele_D = phy_query_bb_reg(priv, REG_OFDM_0_XB_TX_IQ_IMBALANCE, bMaskDWord)&bMaskOFDM_D; |
| 1371 | for(i=0; i<OFDM_TABLE_SIZE; i++) { |
| 1372 | if(ele_D == (ofdm_swing_table[i]&bMaskOFDM_D)) { |
| 1373 | priv->pshare->OFDM_index[1] = i; |
| 1374 | priv->pshare->OFDM_index0[1] = i; |
| 1375 | break; |
| 1376 | } |
| 1377 | } |
| 1378 | } |
| 1379 | priv->pshare->CCK_index = get_CCK_swing_index(priv); |
| 1380 | priv->pshare->CCK_index0 = priv->pshare->CCK_index; |
| 1381 | |
| 1382 | } |
| 1383 | |
| 1384 | delta = RTL_ABS(ThermalValue, priv->pshare->thermal_value); |
| 1385 | delta_LCK = RTL_ABS(ThermalValue, priv->pshare->thermal_value_lck); |
| 1386 | delta_IQK = RTL_ABS(ThermalValue, priv->pshare->thermal_value_iqk); |
| 1387 | |
| 1388 | // printk("Readback Thermal Meter = 0x%lx pre thermal meter 0x%lx EEPROMthermalmeter 0x%lx delta 0x%lx delta_LCK 0x%lx delta_IQK 0x%lx\n", |
| 1389 | // ThermalValue, priv->pshare->thermal_value, priv->pmib->dot11RFEntry.ther, delta, delta_LCK, delta_IQK); |
| 1390 | |
| 1391 | if(delta_LCK > 1) { |
| 1392 | priv->pshare->thermal_value_lck = ThermalValue; |
| 1393 | #ifdef MP_TEST |
| 1394 | if(priv->pshare->rf_ft_var.mp_specific) |
| 1395 | { |
| 1396 | if((OPMODE & WIFI_MP_CTX_BACKGROUND) && !(OPMODE & WIFI_MP_CTX_PACKET)) |
| 1397 | printk("NOT do LCK during ctx !!!! \n"); |
| 1398 | else |
| 1399 | phy_lc_calibrate(priv); |
| 1400 | } |
| 1401 | else |
| 1402 | #endif |
| 1403 | phy_lc_calibrate(priv); |
| 1404 | } |
| 1405 | |
| 1406 | if(delta > 0) { |
| 1407 | if(ThermalValue > priv->pshare->thermal_value) { |
| 1408 | for(i = 0; i < rf; i++) |
| 1409 | priv->pshare->OFDM_index[i] -= delta; |
| 1410 | priv->pshare->CCK_index -= delta; |
| 1411 | } else { |
| 1412 | for(i = 0; i < rf; i++) |
| 1413 | priv->pshare->OFDM_index[i] += delta; |
| 1414 | priv->pshare->CCK_index += delta; |
| 1415 | } |
| 1416 | if(ThermalValue > priv->pmib->dot11RFEntry.ther) { |
| 1417 | for(i = 0; i < rf; i++) |
| 1418 | OFDM_index[i] = priv->pshare->OFDM_index[i]+1; |
| 1419 | CCK_index = priv->pshare->CCK_index+1; |
| 1420 | } else { |
| 1421 | for(i = 0; i < rf; i++) |
| 1422 | OFDM_index[i] = priv->pshare->OFDM_index[i]; |
| 1423 | CCK_index = priv->pshare->CCK_index; |
| 1424 | } |
| 1425 | #ifdef MP_TEST |
| 1426 | if ((OPMODE & WIFI_MP_STATE) || priv->pshare->rf_ft_var.mp_specific) { |
| 1427 | TxPwrLevel[0] = priv->pshare->mp_txpwr_patha; |
| 1428 | TxPwrLevel[1] = priv->pshare->mp_txpwr_pathb; |
| 1429 | } else |
| 1430 | #endif |
| 1431 | { |
| 1432 | TxPwrLevel[0] = priv->pmib->dot11RFEntry.pwrlevelHT40_1S_A[channel-1]; |
| 1433 | TxPwrLevel[1] = priv->pmib->dot11RFEntry.pwrlevelHT40_1S_B[channel-1]; |
| 1434 | |
| 1435 | if (priv->pshare->CurrentChannelBW == CHANNEL_WIDTH_20) { |
| 1436 | unsigned char offset = (priv->pmib->dot11RFEntry.pwrdiffHT20[channel-1] & 0x0f); |
| 1437 | TxPwrLevel[0] = COUNT_SIGN_OFFSET(TxPwrLevel[0], offset); |
| 1438 | offset = ((priv->pmib->dot11RFEntry.pwrdiffOFDM[channel-1] & 0xf0) >> 4); |
| 1439 | TxPwrLevel[1] = COUNT_SIGN_OFFSET(TxPwrLevel[1], offset); |
| 1440 | } |
| 1441 | #ifdef POWER_PERCENT_ADJUSTMENT |
| 1442 | pwrdiff_percent = PwrPercent2PwrLevel(priv->pmib->dot11RFEntry.power_percent); |
| 1443 | TxPwrLevel[0] = POWER_RANGE_CHECK(TxPwrLevel[0]+pwrdiff_percent); |
| 1444 | TxPwrLevel[1] = POWER_RANGE_CHECK(TxPwrLevel[1]+pwrdiff_percent); |
| 1445 | #endif |
| 1446 | } |
| 1447 | |
| 1448 | // printk("TxPwrLevel[0]=%d, TxPwrLevel[1]=%d\n", TxPwrLevel[0], TxPwrLevel[1]); |
| 1449 | for(i = 0; i < rf; i++) { |
| 1450 | if(/*TxPwrLevel[i] >=0 &&*/ TxPwrLevel[i] <=26) { |
| 1451 | if(ThermalValue > priv->pmib->dot11RFEntry.ther) { |
| 1452 | if (delta < 5) |
| 1453 | OFDM_index[i] -= 1; |
| 1454 | else |
| 1455 | OFDM_index[i] -= 2; |
| 1456 | } else if(delta > 5 && ThermalValue < priv->pmib->dot11RFEntry.ther) { |
| 1457 | OFDM_index[i] += 1; |
| 1458 | } |
| 1459 | } else if (TxPwrLevel[i] >= 27 && TxPwrLevel[i] <= 32 && ThermalValue > priv->pmib->dot11RFEntry.ther) { |
| 1460 | if (delta < 5) |
| 1461 | OFDM_index[i] -= 1; |
| 1462 | else |
| 1463 | OFDM_index[i] -= 2; |
| 1464 | } else if (TxPwrLevel[i] >= 32 && TxPwrLevel[i] <= 38 && ThermalValue > priv->pmib->dot11RFEntry.ther && delta > 5) { |
| 1465 | OFDM_index[i] -= 1; |
| 1466 | } |
| 1467 | |
| 1468 | #ifdef _TRACKING_TABLE_FILE |
| 1469 | if (priv->pshare->rf_ft_var.pwr_track_file) |
| 1470 | { |
| 1471 | int d = 0; |
| 1472 | |
| 1473 | OFDM_index[i] = priv->pshare->OFDM_index[i]; |
| 1474 | d = RTL_ABS(OFDM_index[i], priv->pshare->OFDM_index0[i]); |
| 1475 | |
| 1476 | if(OFDM_index[i] < priv->pshare->OFDM_index0[i]) |
| 1477 | { |
| 1478 | OFDM_index[i] = priv->pshare->OFDM_index0[i] - get_tx_tracking_index(priv, channel, i, d, 0, 0); |
| 1479 | } |
| 1480 | else |
| 1481 | { |
| 1482 | OFDM_index[i] = priv->pshare->OFDM_index0[i] + get_tx_tracking_index(priv, channel, i, d, 1, 0); |
| 1483 | } |
| 1484 | |
| 1485 | } |
| 1486 | else |
| 1487 | #endif |
| 1488 | { |
| 1489 | #ifdef HIGH_POWER_EXT_PA |
| 1490 | if (priv->pshare->rf_ft_var.use_ext_pa) { |
| 1491 | OFDM_index[i] = priv->pshare->OFDM_index[i]; |
| 1492 | swingIndexRemap2(&OFDM_index[i], priv->pshare->OFDM_index0[i], i); //Modify HP tracking table, from Arthur 2012.02.13 |
| 1493 | //swingIndexRemap(&OFDM_index[i], priv->pshare->OFDM_index0[i]); |
| 1494 | } |
| 1495 | #endif |
| 1496 | } |
| 1497 | if(OFDM_index[i] > OFDM_TABLE_SIZE-1) |
| 1498 | OFDM_index[i] = OFDM_TABLE_SIZE-1; |
| 1499 | else if (OFDM_index[i] < OFDM_min_index) |
| 1500 | OFDM_index[i] = OFDM_min_index; |
| 1501 | } |
| 1502 | i=0; |
| 1503 | { |
| 1504 | if(/*TxPwrLevel[i] >=0 &&*/ TxPwrLevel[i] <=26) { |
| 1505 | if(ThermalValue > priv->pmib->dot11RFEntry.ther) { |
| 1506 | if (delta < 5) |
| 1507 | CCK_index -= 1; |
| 1508 | else |
| 1509 | CCK_index -= 2; |
| 1510 | } else if(delta > 5 && ThermalValue < priv->pmib->dot11RFEntry.ther) { |
| 1511 | CCK_index += 1; |
| 1512 | } |
| 1513 | } else if (TxPwrLevel[i] >= 27 && TxPwrLevel[i] <= 32 && ThermalValue > priv->pmib->dot11RFEntry.ther) { |
| 1514 | if (delta < 5) |
| 1515 | CCK_index -= 1; |
| 1516 | else |
| 1517 | CCK_index -= 2; |
| 1518 | } else if (TxPwrLevel[i] >= 32 && TxPwrLevel[i] <= 38 && ThermalValue > priv->pmib->dot11RFEntry.ther && delta > 5) { |
| 1519 | CCK_index -= 1; |
| 1520 | } |
| 1521 | |
| 1522 | #ifdef _TRACKING_TABLE_FILE |
| 1523 | if (priv->pshare->rf_ft_var.pwr_track_file) |
| 1524 | { |
| 1525 | int d = 0; |
| 1526 | |
| 1527 | CCK_index = priv->pshare->CCK_index; |
| 1528 | d = RTL_ABS(CCK_index, priv->pshare->CCK_index0); |
| 1529 | |
| 1530 | if(CCK_index < priv->pshare->CCK_index0) |
| 1531 | { |
| 1532 | CCK_index = priv->pshare->CCK_index0 - get_tx_tracking_index(priv, channel, i, d, 0, 1); |
| 1533 | } |
| 1534 | else |
| 1535 | { |
| 1536 | CCK_index = priv->pshare->CCK_index0 + get_tx_tracking_index(priv, channel, i, d, 1, 1); |
| 1537 | } |
| 1538 | |
| 1539 | } |
| 1540 | else |
| 1541 | #endif |
| 1542 | { |
| 1543 | #ifdef HIGH_POWER_EXT_PA |
| 1544 | if (priv->pshare->rf_ft_var.use_ext_pa) { |
| 1545 | CCK_index = priv->pshare->CCK_index; |
| 1546 | swingIndexRemap2( &CCK_index, priv->pshare->CCK_index0, i); //Modify HP tracking table, from Arthur 2012.02.13 |
| 1547 | //swingIndexRemap( &CCK_index, priv->pshare->CCK_index0); |
| 1548 | } |
| 1549 | #endif |
| 1550 | } |
| 1551 | if(CCK_index > CCK_TABLE_SIZE-1) |
| 1552 | CCK_index = CCK_TABLE_SIZE-1; |
| 1553 | else if (CCK_index < 0) |
| 1554 | CCK_index = 0; |
| 1555 | } |
| 1556 | |
| 1557 | //Adujst OFDM Ant_A according to IQK result |
| 1558 | ele_D = (ofdm_swing_table[(unsigned int)OFDM_index[0]] & 0xFFC00000)>>22; |
| 1559 | X = priv->pshare->rege94; |
| 1560 | Y = priv->pshare->rege9c; |
| 1561 | |
| 1562 | if(X != 0) { |
| 1563 | if ((X & 0x00000200) != 0) |
| 1564 | X = X | 0xFFFFFC00; |
| 1565 | ele_A = ((X * ele_D)>>8)&0x000003FF; |
| 1566 | |
| 1567 | //new element C = element D x Y |
| 1568 | if ((Y & 0x00000200) != 0) |
| 1569 | Y = Y | 0xFFFFFC00; |
| 1570 | ele_C = ((Y * ele_D)>>8)&0x000003FF; |
| 1571 | |
| 1572 | //wirte new elements A, C, D to regC80 and regC94, element B is always 0 |
| 1573 | value32 = (ele_D<<22)|((ele_C&0x3F)<<16)|ele_A; |
| 1574 | phy_set_bb_reg(priv, REG_OFDM_0_XA_TX_IQ_IMBALANCE, bMaskDWord, value32); |
| 1575 | |
| 1576 | value32 = (ele_C&0x000003C0)>>6; |
| 1577 | phy_set_bb_reg(priv, REG_OFDM_0_XC_TX_AFE, bMaskH4Bits, value32); |
| 1578 | |
| 1579 | value32 = ((X * ele_D)>>7)&0x01; |
| 1580 | phy_set_bb_reg(priv, REG_OFDM_0_ECCA_THRESHOLD, BIT(24), value32); |
| 1581 | |
| 1582 | } else { |
| 1583 | phy_set_bb_reg(priv, REG_OFDM_0_XA_TX_IQ_IMBALANCE, bMaskDWord, ofdm_swing_table[(unsigned int)OFDM_index[0]]); |
| 1584 | phy_set_bb_reg(priv, REG_OFDM_0_XC_TX_AFE, bMaskH4Bits, 0x00); |
| 1585 | phy_set_bb_reg(priv, REG_OFDM_0_ECCA_THRESHOLD, BIT(24), 0x00); |
| 1586 | } |
| 1587 | |
| 1588 | |
| 1589 | set_CCK_swing_index(priv, CCK_index); |
| 1590 | |
| 1591 | |
| 1592 | if(is2T) { |
| 1593 | ele_D = (ofdm_swing_table[(unsigned int)OFDM_index[1]] & 0xFFC00000)>>22; |
| 1594 | X = priv->pshare->regeb4; |
| 1595 | Y = priv->pshare->regebc; |
| 1596 | |
| 1597 | if(X != 0) { |
| 1598 | if ((X & 0x00000200) != 0) //consider minus |
| 1599 | X = X | 0xFFFFFC00; |
| 1600 | ele_A = ((X * ele_D)>>8)&0x000003FF; |
| 1601 | |
| 1602 | //new element C = element D x Y |
| 1603 | if ((Y & 0x00000200) != 0) |
| 1604 | Y = Y | 0xFFFFFC00; |
| 1605 | ele_C = ((Y * ele_D)>>8)&0x00003FF; |
| 1606 | |
| 1607 | //wirte new elements A, C, D to regC88 and regC9C, element B is always 0 |
| 1608 | value32=(ele_D<<22)|((ele_C&0x3F)<<16) |ele_A; |
| 1609 | phy_set_bb_reg(priv, REG_OFDM_0_XB_TX_IQ_IMBALANCE, bMaskDWord, value32); |
| 1610 | |
| 1611 | value32 = (ele_C&0x000003C0)>>6; |
| 1612 | phy_set_bb_reg(priv, REG_OFDM_0_XD_TX_AFE, bMaskH4Bits, value32); |
| 1613 | |
| 1614 | value32 = ((X * ele_D)>>7)&0x01; |
| 1615 | phy_set_bb_reg(priv, REG_OFDM_0_ECCA_THRESHOLD, BIT(28), value32); |
| 1616 | |
| 1617 | } else { |
| 1618 | phy_set_bb_reg(priv, REG_OFDM_0_XB_TX_IQ_IMBALANCE, bMaskDWord, ofdm_swing_table[(unsigned int)OFDM_index[1]]); |
| 1619 | phy_set_bb_reg(priv, REG_OFDM_0_XD_TX_AFE, bMaskH4Bits, 0x00); |
| 1620 | phy_set_bb_reg(priv, REG_OFDM_0_ECCA_THRESHOLD, BIT(28), 0x00); |
| 1621 | } |
| 1622 | } |
| 1623 | } |
| 1624 | |
| 1625 | if(delta_IQK > 3) { |
| 1626 | priv->pshare->thermal_value_iqk = ThermalValue; |
| 1627 | #ifdef MP_TEST |
| 1628 | if(priv->pshare->rf_ft_var.mp_specific) |
| 1629 | { |
| 1630 | if((OPMODE & WIFI_MP_CTX_BACKGROUND) && !(OPMODE & WIFI_MP_CTX_PACKET)) |
| 1631 | printk("NOT do IQK during ctx !!!! \n"); |
| 1632 | else |
| 1633 | phy_iq_calibrate(priv); |
| 1634 | } |
| 1635 | else |
| 1636 | #endif |
| 1637 | phy_iq_calibrate(priv); |
| 1638 | } |
| 1639 | |
| 1640 | //update thermal meter value |
| 1641 | priv->pshare->thermal_value = ThermalValue; |
| 1642 | |
| 1643 | } |
| 1644 | } |
| 1645 | #endif |
| 1646 | |
| 1647 | |
| 1648 | #ifdef RX_GAIN_TRACK_92D |
| 1649 | static void rx_gain_tracking_92D(struct rtl8192cd_priv *priv) |
| 1650 | { |
| 1651 | u8 index_mapping[Rx_index_mapping_NUM] = { |
| 1652 | 0x0f, 0x0f, 0x0f, 0x0f, 0x0b, |
| 1653 | 0x0a, 0x09, 0x08, 0x07, 0x06, |
| 1654 | 0x05, 0x04, 0x04, 0x03, 0x02 |
| 1655 | }; |
| 1656 | |
| 1657 | u8 eRFPath, curMaxRFPath; |
| 1658 | u32 u4tmp; |
| 1659 | |
| 1660 | u4tmp = (index_mapping[(priv->pmib->dot11RFEntry.ther - priv->pshare->ThermalValue_RxGain)]) << 12; |
| 1661 | |
| 1662 | DEBUG_INFO("===>%s interface %d Rx Gain %x\n", __FUNCTION__, priv->pshare->wlandev_idx, u4tmp); |
| 1663 | |
| 1664 | if (priv->pmib->dot11RFEntry.macPhyMode == DUALMAC_DUALPHY) |
| 1665 | curMaxRFPath = RF_PATH_B; |
| 1666 | else |
| 1667 | curMaxRFPath = RF_PATH_MAX; |
| 1668 | |
| 1669 | for(eRFPath = RF_PATH_A; eRFPath < curMaxRFPath; eRFPath++) |
| 1670 | phy_set_rf_reg(priv, eRFPath, 0x3C, bMask20Bits, (priv->pshare->RegRF3C[eRFPath]&(~(0xF000)))|u4tmp); |
| 1671 | |
| 1672 | }; |
| 1673 | |
| 1674 | #endif |
| 1675 | |
| 1676 | #if 0 |
| 1677 | //#ifdef CONFIG_RTL_88E_SUPPORT //for 88e tx power tracking |
| 1678 | |
| 1679 | void odm_reset_iqk_result(struct rtl8192cd_priv *priv) |
| 1680 | { |
| 1681 | /* |
| 1682 | #if (DM_ODM_SUPPORT_TYPE == ODM_WIN || DM_ODM_SUPPORT_TYPE == ODM_CE) |
| 1683 | PADAPTER Adapter = p_dm_odm->Adapter; |
| 1684 | u1Byte i; |
| 1685 | |
| 1686 | if (!IS_HARDWARE_TYPE_8192D(Adapter)) |
| 1687 | return; |
| 1688 | #endif |
| 1689 | */ |
| 1690 | |
| 1691 | unsigned char i; |
| 1692 | |
| 1693 | //printk("PHY_ResetIQKResult:: settings regs %d default regs %d\n", sizeof(priv->pshare->IQKMatrixRegSetting)/sizeof(struct _IQK_MATRIX_REGS_SETTING), IQK_Matrix_Settings_NUM); |
| 1694 | //0xe94, 0xe9c, 0xea4, 0xeac, 0xeb4, 0xebc, 0xec4, 0xecc |
| 1695 | |
| 1696 | for(i = 0; i < IQK_Matrix_Settings_NUM; i++) |
| 1697 | { |
| 1698 | { |
| 1699 | priv->pshare->IQKMatrixRegSetting[i].Value[0][0] = |
| 1700 | priv->pshare->IQKMatrixRegSetting[i].Value[0][2] = |
| 1701 | priv->pshare->IQKMatrixRegSetting[i].Value[0][4] = |
| 1702 | priv->pshare->IQKMatrixRegSetting[i].Value[0][6] = 0x100; |
| 1703 | |
| 1704 | priv->pshare->IQKMatrixRegSetting[i].Value[0][1] = |
| 1705 | priv->pshare->IQKMatrixRegSetting[i].Value[0][3] = |
| 1706 | priv->pshare->IQKMatrixRegSetting[i].Value[0][5] = |
| 1707 | priv->pshare->IQKMatrixRegSetting[i].Value[0][7] = 0x0; |
| 1708 | |
| 1709 | priv->pshare->IQKMatrixRegSetting[i].bIQKDone = FALSE; |
| 1710 | |
| 1711 | } |
| 1712 | } |
| 1713 | |
| 1714 | } |
| 1715 | |
| 1716 | #define RF_PATH_A 0 //Radio Path A |
| 1717 | #define OFDM_TABLE_SIZE_92D 43 |
| 1718 | |
| 1719 | #define bRFRegOffsetMask 0xfffff |
| 1720 | |
| 1721 | |
| 1722 | //091212 chiyokolin |
| 1723 | void odm_txpowertracking_callback_thermal_meter_8188e(struct rtl8192cd_priv *priv) |
| 1724 | { |
| 1725 | |
| 1726 | //HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter); |
| 1727 | |
| 1728 | unsigned char ThermalValue = 0, delta, delta_LCK, delta_IQK, offset; |
| 1729 | unsigned char ThermalValue_AVG_count = 0; |
| 1730 | unsigned int ThermalValue_AVG = 0; |
| 1731 | int ele_A=0, ele_D, TempCCk, X, value32; |
| 1732 | int Y, ele_C=0; |
| 1733 | char OFDM_index[2], CCK_index=0, OFDM_index_old[2]={0,0}, CCK_index_old=0, index; |
| 1734 | unsigned int i = 0, j = 0; |
| 1735 | char is2T = FALSE; |
| 1736 | //char bInteralPA = FALSE; |
| 1737 | |
| 1738 | unsigned char OFDM_min_index = 6, rf; //OFDM BB Swing should be less than +3.0dB, which is required by Arthur |
| 1739 | unsigned char Indexforchannel = 0/*GetRightChnlPlaceforIQK(pHalData->CurrentChannel)*/; |
| 1740 | char OFDM_index_mapping[2][index_mapping_NUM_88E] = { |
| 1741 | {0, 0, 2, 3, 4, 4, //2.4G, decrease power |
| 1742 | 5, 6, 7, 7, 8, 9, |
| 1743 | 10, 10, 11}, // For lower temperature, 20120220 updated on 20120220. |
| 1744 | {0, 0, -1, -2, -3, -4, //2.4G, increase power |
| 1745 | -4, -4, -4, -5, -7, -8, |
| 1746 | -9, -9, -10}, |
| 1747 | }; |
| 1748 | unsigned char Thermal_mapping[2][index_mapping_NUM_88E] = { |
| 1749 | {0, 2, 4, 6, 8, 10, //2.4G, decrease power |
| 1750 | 12, 14, 16, 18, 20, 22, |
| 1751 | 24, 26, 27}, |
| 1752 | {0, 2, 4, 6, 8, 10, //2.4G,, increase power |
| 1753 | 12, 14, 16, 18, 20, 22, |
| 1754 | 25, 25, 25}, |
| 1755 | }; |
| 1756 | |
| 1757 | priv->pshare->TXPowerTrackingCallbackCnt++; //cosa add for debug |
| 1758 | priv->pshare->bTXPowerTrackingInit = TRUE; |
| 1759 | |
| 1760 | #if (MP_DRIVER == 1) |
| 1761 | priv->pshare->TxPowerTrackControl = 1; //priv->pshare->TxPowerTrackControl; //_eric_?? // <Kordan> We should keep updating the control variable according to HalData. |
| 1762 | // <Kordan> pshare->RegA24 will be initialized when ODM HW configuring, but MP configures with para files. |
| 1763 | priv->pshare->RegA24 = 0x090e1317; |
| 1764 | #endif |
| 1765 | |
| 1766 | |
| 1767 | #ifdef MP_TEST |
| 1768 | if ((OPMODE & WIFI_MP_STATE) || priv->pshare->rf_ft_var.mp_specific) { |
| 1769 | if(priv->pshare->mp_txpwr_tracking == FALSE) |
| 1770 | return; |
| 1771 | } |
| 1772 | #endif |
| 1773 | |
| 1774 | if(priv->pshare->Power_tracking_on_88E == 0) |
| 1775 | { |
| 1776 | priv->pshare->Power_tracking_on_88E = 1; |
| 1777 | phy_set_rf_reg(priv, RF_PATH_A, 0x42, (BIT(17) | BIT(16)), 0x03); |
| 1778 | return; |
| 1779 | } |
| 1780 | else |
| 1781 | { |
| 1782 | |
| 1783 | priv->pshare->Power_tracking_on_88E = 0; |
| 1784 | |
| 1785 | //printk("===>dm_TXPowerTrackingCallback_ThermalMeter_8188E txpowercontrol %d\n", priv->pshare->TxPowerTrackControl); |
| 1786 | |
| 1787 | ThermalValue = (unsigned char)phy_query_rf_reg(priv, RF_PATH_A, RF_T_METER_88E, 0xfc00, 1); //0x42: RF Reg[15:10] 88E |
| 1788 | |
| 1789 | printk("\nReadback Thermal Meter = 0x%x pre thermal meter 0x%x EEPROMthermalmeter 0x%x\n", ThermalValue, priv->pshare->ThermalValue, priv->pmib->dot11RFEntry.ther); |
| 1790 | |
| 1791 | } |
| 1792 | |
| 1793 | if(is2T) |
| 1794 | rf = 2; |
| 1795 | else |
| 1796 | rf = 1; |
| 1797 | |
| 1798 | if(ThermalValue) |
| 1799 | { |
| 1800 | // if(!pHalData->ThermalValue) |
| 1801 | { |
| 1802 | //Query OFDM path A default setting |
| 1803 | ele_D = phy_query_bb_reg(priv, REG_OFDM_0_XA_TX_IQ_IMBALANCE, bMaskDWord)&bMaskOFDM_D; |
| 1804 | |
| 1805 | for(i=0; i<OFDM_TABLE_SIZE_92D; i++) //find the index |
| 1806 | { |
| 1807 | if(ele_D == (ofdm_swing_table[i]&bMaskOFDM_D)) |
| 1808 | { |
| 1809 | OFDM_index_old[0] = (unsigned char)i; |
| 1810 | printk("Initial pathA ele_D reg0x%x = 0x%x, OFDM_index=0x%x\n", |
| 1811 | REG_OFDM_0_XA_TX_IQ_IMBALANCE, ele_D, OFDM_index_old[0]); |
| 1812 | break; |
| 1813 | } |
| 1814 | } |
| 1815 | |
| 1816 | //Query OFDM path B default setting |
| 1817 | if(is2T) |
| 1818 | { |
| 1819 | ele_D = phy_query_bb_reg(priv, REG_OFDM_0_XB_TX_IQ_IMBALANCE, bMaskDWord)&bMaskOFDM_D; |
| 1820 | for(i=0; i<OFDM_TABLE_SIZE_92D; i++) //find the index |
| 1821 | { |
| 1822 | if(ele_D == (ofdm_swing_table[i]&bMaskOFDM_D)) |
| 1823 | { |
| 1824 | OFDM_index_old[1] = (unsigned char)i; |
| 1825 | printk("Initial pathB ele_D reg0x%x = 0x%x, OFDM_index=0x%x\n", |
| 1826 | REG_OFDM_0_XB_TX_IQ_IMBALANCE, ele_D, OFDM_index_old[1]); |
| 1827 | break; |
| 1828 | } |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | { |
| 1833 | //Query CCK default setting From 0xa24 |
| 1834 | TempCCk = priv->pshare->RegA24; |
| 1835 | |
| 1836 | for(i=0 ; i<CCK_TABLE_SIZE ; i++) |
| 1837 | { |
| 1838 | if(priv->pshare->bCCKinCH14) |
| 1839 | { |
| 1840 | if(memcmp((void*)&TempCCk, (void*)&cck_swing_table_ch14[i][2], 4)==0) |
| 1841 | { |
| 1842 | CCK_index_old =(unsigned char) i; |
| 1843 | //printk("Initial reg0x%x = 0x%x, CCK_index=0x%x, ch 14 %d\n", |
| 1844 | //rCCK0_TxFilter2, TempCCk, CCK_index_old, priv->pshare->bCCKinCH14); |
| 1845 | break; |
| 1846 | } |
| 1847 | } |
| 1848 | else |
| 1849 | { |
| 1850 | //printk("RegA24: 0x%X, cck_swing_table_ch1_ch13[%d][2]: cck_swing_table_ch1_ch13[i][2]: 0x%X\n", TempCCk, i, cck_swing_table_ch1_ch13[i][2]); |
| 1851 | if(memcmp((void*)&TempCCk, (void*)&cck_swing_table_ch1_ch13[i][2], 4)==0) |
| 1852 | { |
| 1853 | CCK_index_old =(unsigned char) i; |
| 1854 | //printk("Initial reg0x%x = 0x%x, CCK_index=0x%x, ch14 %d\n", |
| 1855 | //rCCK0_TxFilter2, TempCCk, CCK_index_old, priv->pshare->bCCKinCH14); |
| 1856 | break; |
| 1857 | } |
| 1858 | } |
| 1859 | } |
| 1860 | } |
| 1861 | |
| 1862 | if(!priv->pshare->ThermalValue) |
| 1863 | { |
| 1864 | priv->pshare->ThermalValue = priv->pmib->dot11RFEntry.ther; |
| 1865 | priv->pshare->ThermalValue_LCK = ThermalValue; |
| 1866 | priv->pshare->ThermalValue_IQK = ThermalValue; |
| 1867 | |
| 1868 | for(i = 0; i < rf; i++) |
| 1869 | priv->pshare->OFDM_index[i] = OFDM_index_old[i]; |
| 1870 | priv->pshare->CCK_index = CCK_index_old; |
| 1871 | } |
| 1872 | |
| 1873 | if(priv->pshare->bReloadtxpowerindex) |
| 1874 | { |
| 1875 | printk("reload ofdm index for band switch\n"); |
| 1876 | } |
| 1877 | |
| 1878 | //calculate average thermal meter |
| 1879 | { |
| 1880 | priv->pshare->ThermalValue_AVG[priv->pshare->ThermalValue_AVG_index] = ThermalValue; |
| 1881 | priv->pshare->ThermalValue_AVG_index++; |
| 1882 | if(priv->pshare->ThermalValue_AVG_index == AVG_THERMAL_NUM_88E) |
| 1883 | priv->pshare->ThermalValue_AVG_index = 0; |
| 1884 | |
| 1885 | for(i = 0; i < AVG_THERMAL_NUM_88E; i++) |
| 1886 | { |
| 1887 | if(priv->pshare->ThermalValue_AVG[i]) |
| 1888 | { |
| 1889 | ThermalValue_AVG += priv->pshare->ThermalValue_AVG[i]; |
| 1890 | ThermalValue_AVG_count++; |
| 1891 | } |
| 1892 | } |
| 1893 | |
| 1894 | if(ThermalValue_AVG_count) |
| 1895 | { |
| 1896 | ThermalValue = (unsigned char)(ThermalValue_AVG / ThermalValue_AVG_count); |
| 1897 | printk("AVG Thermal Meter = 0x%x \n", ThermalValue); |
| 1898 | } |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | if(priv->pshare->bReloadtxpowerindex) |
| 1903 | { |
| 1904 | delta = ThermalValue > priv->pmib->dot11RFEntry.ther?(ThermalValue - priv->pmib->dot11RFEntry.ther):(priv->pmib->dot11RFEntry.ther - ThermalValue); |
| 1905 | priv->pshare->bReloadtxpowerindex = FALSE; |
| 1906 | priv->pshare->bDoneTxpower = FALSE; |
| 1907 | } |
| 1908 | else if(priv->pshare->bDoneTxpower) |
| 1909 | { |
| 1910 | delta = (ThermalValue > priv->pshare->ThermalValue)?(ThermalValue - priv->pshare->ThermalValue):(priv->pshare->ThermalValue - ThermalValue); |
| 1911 | } |
| 1912 | else |
| 1913 | { |
| 1914 | delta = ThermalValue > priv->pmib->dot11RFEntry.ther?(ThermalValue - priv->pmib->dot11RFEntry.ther):(priv->pmib->dot11RFEntry.ther - ThermalValue); |
| 1915 | } |
| 1916 | delta_LCK = (ThermalValue > priv->pshare->ThermalValue_LCK)?(ThermalValue - priv->pshare->ThermalValue_LCK):(priv->pshare->ThermalValue_LCK - ThermalValue); |
| 1917 | delta_IQK = (ThermalValue > priv->pshare->ThermalValue_IQK)?(ThermalValue - priv->pshare->ThermalValue_IQK):(priv->pshare->ThermalValue_IQK - ThermalValue); |
| 1918 | |
| 1919 | printk("Readback Thermal Meter = 0x%x \npre thermal meter 0x%x EEPROMthermalmeter 0x%x delta 0x%x \ndelta_LCK 0x%x delta_IQK 0x%x \n", ThermalValue, priv->pshare->ThermalValue, priv->pshare->EEPROMThermalMeter, delta, delta_LCK, delta_IQK); |
| 1920 | printk("pre thermal meter LCK 0x%x \npre thermal meter IQK 0x%x \ndelta_LCK_bound 0x%x delta_IQK_bound 0x%x\n", priv->pshare->ThermalValue_LCK, priv->pshare->ThermalValue_IQK, priv->pshare->delta_lck, priv->pshare->delta_iqk); |
| 1921 | |
| 1922 | |
| 1923 | //if((delta_LCK > pHalData->delta_lck) && (pHalData->delta_lck != 0)) |
| 1924 | if (delta_LCK >= 8) // Delta temperature is equal to or larger than 20 centigrade. |
| 1925 | { |
| 1926 | priv->pshare->ThermalValue_LCK = ThermalValue; |
| 1927 | phy_lc_calibrate(priv); |
| 1928 | } |
| 1929 | |
| 1930 | |
| 1931 | if(delta > 0 && priv->pshare->TxPowerTrackControl) |
| 1932 | { |
| 1933 | delta = ThermalValue > priv->pmib->dot11RFEntry.ther?(ThermalValue - priv->pmib->dot11RFEntry.ther):(priv->pmib->dot11RFEntry.ther - ThermalValue); |
| 1934 | |
| 1935 | //calculate new OFDM / CCK offset |
| 1936 | { |
| 1937 | { |
| 1938 | if(ThermalValue > priv->pmib->dot11RFEntry.ther) |
| 1939 | j = 1; |
| 1940 | else |
| 1941 | j = 0; |
| 1942 | |
| 1943 | for(offset = 0; offset < index_mapping_NUM_88E; offset++) |
| 1944 | { |
| 1945 | if(delta < Thermal_mapping[j][offset]) |
| 1946 | { |
| 1947 | if(offset != 0) |
| 1948 | offset--; |
| 1949 | break; |
| 1950 | } |
| 1951 | } |
| 1952 | if(offset >= index_mapping_NUM_88E) |
| 1953 | offset = index_mapping_NUM_88E-1; |
| 1954 | |
| 1955 | index = OFDM_index_mapping[j][offset]; |
| 1956 | |
| 1957 | printk("\nj = %d delta = %d, index = %d\n\n", j, delta, index); |
| 1958 | |
| 1959 | for(i = 0; i < rf; i++) |
| 1960 | OFDM_index[i] = priv->pshare->OFDM_index[i] + OFDM_index_mapping[j][offset]; |
| 1961 | CCK_index = priv->pshare->CCK_index + OFDM_index_mapping[j][offset]; |
| 1962 | } |
| 1963 | |
| 1964 | if(is2T) |
| 1965 | { |
| 1966 | printk("temp OFDM_A_index=0x%x, OFDM_B_index=0x%x, CCK_index=0x%x\n", |
| 1967 | priv->pshare->OFDM_index[0], priv->pshare->OFDM_index[1], priv->pshare->CCK_index); |
| 1968 | } |
| 1969 | else |
| 1970 | { |
| 1971 | printk("temp OFDM_A_index=0x%x, CCK_index=0x%x\n", |
| 1972 | priv->pshare->OFDM_index[0], priv->pshare->CCK_index); |
| 1973 | } |
| 1974 | |
| 1975 | for(i = 0; i < rf; i++) |
| 1976 | { |
| 1977 | if(OFDM_index[i] > OFDM_TABLE_SIZE_92D-1) |
| 1978 | { |
| 1979 | OFDM_index[i] = OFDM_TABLE_SIZE_92D-1; |
| 1980 | } |
| 1981 | else if (OFDM_index[i] < OFDM_min_index) |
| 1982 | { |
| 1983 | OFDM_index[i] = OFDM_min_index; |
| 1984 | } |
| 1985 | } |
| 1986 | |
| 1987 | { |
| 1988 | if(CCK_index > CCK_TABLE_SIZE-1) |
| 1989 | CCK_index = CCK_TABLE_SIZE-1; |
| 1990 | else if (CCK_index < 0) |
| 1991 | CCK_index = 0; |
| 1992 | } |
| 1993 | |
| 1994 | if(is2T) |
| 1995 | { |
| 1996 | printk("new OFDM_A_index=0x%x, OFDM_B_index=0x%x, CCK_index=0x%x\n", |
| 1997 | OFDM_index[0], OFDM_index[1], CCK_index); |
| 1998 | } |
| 1999 | else |
| 2000 | { |
| 2001 | printk("new OFDM_A_index=0x%x, CCK_index=0x%x\n", |
| 2002 | OFDM_index[0], CCK_index); |
| 2003 | } |
| 2004 | } |
| 2005 | |
| 2006 | //2 temporarily remove bNOPG |
| 2007 | //Config by SwingTable |
| 2008 | if(priv->pshare->TxPowerTrackControl /*&& !pHalData->bNOPG*/) |
| 2009 | { |
| 2010 | priv->pshare->bDoneTxpower = TRUE; |
| 2011 | |
| 2012 | //Adujst OFDM Ant_A according to IQK result |
| 2013 | ele_D = (ofdm_swing_table[(unsigned char)OFDM_index[0]] & 0xFFC00000)>>22; |
| 2014 | X = priv->pshare->IQKMatrixRegSetting[Indexforchannel].Value[0][0]; |
| 2015 | Y = priv->pshare->IQKMatrixRegSetting[Indexforchannel].Value[0][1]; |
| 2016 | |
| 2017 | if(X != 0) |
| 2018 | { |
| 2019 | if ((X & 0x00000200) != 0) |
| 2020 | X = X | 0xFFFFFC00; |
| 2021 | ele_A = ((X * ele_D)>>8)&0x000003FF; |
| 2022 | |
| 2023 | //new element C = element D x Y |
| 2024 | if ((Y & 0x00000200) != 0) |
| 2025 | Y = Y | 0xFFFFFC00; |
| 2026 | ele_C = ((Y * ele_D)>>8)&0x000003FF; |
| 2027 | |
| 2028 | //wirte new elements A, C, D to regC80 and regC94, element B is always 0 |
| 2029 | value32 = (ele_D<<22)|((ele_C&0x3F)<<16)|ele_A; |
| 2030 | phy_set_bb_reg(priv, REG_OFDM_0_XA_TX_IQ_IMBALANCE, bMaskDWord, value32); |
| 2031 | |
| 2032 | value32 = (ele_C&0x000003C0)>>6; |
| 2033 | phy_set_bb_reg(priv, REG_OFDM_0_XC_TX_AFE, bMaskH4Bits, value32); |
| 2034 | |
| 2035 | value32 = ((X * ele_D)>>7)&0x01; |
| 2036 | phy_set_bb_reg(priv, REG_OFDM_0_ECCA_THRESHOLD, BIT(24), value32); |
| 2037 | |
| 2038 | } |
| 2039 | else |
| 2040 | { |
| 2041 | phy_set_bb_reg(priv, REG_OFDM_0_XA_TX_IQ_IMBALANCE, bMaskDWord, ofdm_swing_table[(unsigned char)OFDM_index[0]]); |
| 2042 | phy_set_bb_reg(priv, REG_OFDM_0_XC_TX_AFE, bMaskH4Bits, 0x00); |
| 2043 | phy_set_bb_reg(priv, REG_OFDM_0_ECCA_THRESHOLD, BIT(24), 0x00); |
| 2044 | } |
| 2045 | |
| 2046 | //printk("TxPwrTracking for path A: X = 0x%x, Y = 0x%x ele_A = 0x%x ele_C = 0x%x ele_D = 0x%x 0xe94 = 0x%x 0xe9c = 0x%x\n", |
| 2047 | //(unsigned int)X, (unsigned int)Y, (unsigned int)ele_A, (unsigned int)ele_C, (unsigned int)ele_D, (unsigned int)X, (unsigned int)Y); |
| 2048 | |
| 2049 | { |
| 2050 | //Adjust CCK according to IQK result |
| 2051 | if(!priv->pshare->bCCKinCH14){ |
| 2052 | RTL_W8(0xa22, cck_swing_table_ch1_ch13[(unsigned char)CCK_index][0]); |
| 2053 | RTL_W8(0xa23, cck_swing_table_ch1_ch13[(unsigned char)CCK_index][1]); |
| 2054 | RTL_W8(0xa24, cck_swing_table_ch1_ch13[(unsigned char)CCK_index][2]); |
| 2055 | RTL_W8(0xa25, cck_swing_table_ch1_ch13[(unsigned char)CCK_index][3]); |
| 2056 | RTL_W8(0xa26, cck_swing_table_ch1_ch13[(unsigned char)CCK_index][4]); |
| 2057 | RTL_W8(0xa27, cck_swing_table_ch1_ch13[(unsigned char)CCK_index][5]); |
| 2058 | RTL_W8(0xa28, cck_swing_table_ch1_ch13[(unsigned char)CCK_index][6]); |
| 2059 | RTL_W8(0xa29, cck_swing_table_ch1_ch13[(unsigned char)CCK_index][7]); |
| 2060 | } |
| 2061 | else{ |
| 2062 | RTL_W8(0xa22, cck_swing_table_ch14[(unsigned char)CCK_index][0]); |
| 2063 | RTL_W8(0xa23, cck_swing_table_ch14[(unsigned char)CCK_index][1]); |
| 2064 | RTL_W8(0xa24, cck_swing_table_ch14[(unsigned char)CCK_index][2]); |
| 2065 | RTL_W8(0xa25, cck_swing_table_ch14[(unsigned char)CCK_index][3]); |
| 2066 | RTL_W8(0xa26, cck_swing_table_ch14[(unsigned char)CCK_index][4]); |
| 2067 | RTL_W8(0xa27, cck_swing_table_ch14[(unsigned char)CCK_index][5]); |
| 2068 | RTL_W8(0xa28, cck_swing_table_ch14[(unsigned char)CCK_index][6]); |
| 2069 | RTL_W8(0xa29, cck_swing_table_ch14[(unsigned char)CCK_index][7]); |
| 2070 | } |
| 2071 | } |
| 2072 | |
| 2073 | if(is2T) |
| 2074 | { |
| 2075 | ele_D = (ofdm_swing_table[(unsigned char)OFDM_index[1]] & 0xFFC00000)>>22; |
| 2076 | |
| 2077 | //new element A = element D x X |
| 2078 | X = priv->pshare->IQKMatrixRegSetting[Indexforchannel].Value[0][4]; |
| 2079 | Y = priv->pshare->IQKMatrixRegSetting[Indexforchannel].Value[0][5]; |
| 2080 | |
| 2081 | //if(X != 0 && pHalData->CurrentBandType92D == ODM_BAND_ON_2_4G) |
| 2082 | if((X != 0) && (priv->pmib->dot11RFEntry.phyBandSelect == PHY_BAND_2G)) |
| 2083 | |
| 2084 | { |
| 2085 | if ((X & 0x00000200) != 0) //consider minus |
| 2086 | X = X | 0xFFFFFC00; |
| 2087 | ele_A = ((X * ele_D)>>8)&0x000003FF; |
| 2088 | |
| 2089 | //new element C = element D x Y |
| 2090 | if ((Y & 0x00000200) != 0) |
| 2091 | Y = Y | 0xFFFFFC00; |
| 2092 | ele_C = ((Y * ele_D)>>8)&0x00003FF; |
| 2093 | |
| 2094 | //wirte new elements A, C, D to regC88 and regC9C, element B is always 0 |
| 2095 | value32=(ele_D<<22)|((ele_C&0x3F)<<16) |ele_A; |
| 2096 | phy_set_bb_reg(priv, REG_OFDM_0_XB_TX_IQ_IMBALANCE, bMaskDWord, value32); |
| 2097 | |
| 2098 | value32 = (ele_C&0x000003C0)>>6; |
| 2099 | phy_set_bb_reg(priv, REG_OFDM_0_XD_TX_AFE, bMaskH4Bits, value32); |
| 2100 | |
| 2101 | value32 = ((X * ele_D)>>7)&0x01; |
| 2102 | phy_set_bb_reg(priv, REG_OFDM_0_ECCA_THRESHOLD, BIT(28), value32); |
| 2103 | |
| 2104 | } |
| 2105 | else |
| 2106 | { |
| 2107 | phy_set_bb_reg(priv, REG_OFDM_0_XB_TX_IQ_IMBALANCE, bMaskDWord, ofdm_swing_table[(unsigned char)OFDM_index[1]]); |
| 2108 | phy_set_bb_reg(priv, REG_OFDM_0_XD_TX_AFE, bMaskH4Bits, 0x00); |
| 2109 | phy_set_bb_reg(priv, REG_OFDM_0_ECCA_THRESHOLD, BIT(28), 0x00); |
| 2110 | } |
| 2111 | |
| 2112 | //printk("TxPwrTracking path B: X = 0x%x, Y = 0x%x ele_A = 0x%x ele_C = 0x%x ele_D = 0x%x 0xeb4 = 0x%x 0xebc = 0x%x\n", |
| 2113 | //(unsigned int)X, (unsigned int)Y, (unsigned int)ele_A, (unsigned int)ele_C, (unsigned int)ele_D, (unsigned int)X, (unsigned int)Y); |
| 2114 | } |
| 2115 | |
| 2116 | printk("TxPwrTracking 0xc80 = 0x%x, 0xc94 = 0x%x RF 0x24 = 0x%x\n\n", phy_query_bb_reg(priv, 0xc80, bMaskDWord), phy_query_bb_reg(priv, 0xc94, bMaskDWord), phy_query_rf_reg(priv, RF_PATH_A, 0x24, bRFRegOffsetMask, 1)); |
| 2117 | } |
| 2118 | } |
| 2119 | |
| 2120 | |
| 2121 | #if 0 //DO NOT do IQK during 88E power tracking |
| 2122 | // if((delta_IQK > pHalData->delta_iqk) && (pHalData->delta_iqk != 0)) |
| 2123 | if (delta_IQK >= 8) // Delta temperature is equal to or larger than 20 centigrade. |
| 2124 | { |
| 2125 | odm_reset_iqk_result(priv); |
| 2126 | |
| 2127 | /* |
| 2128 | #if(DM_ODM_SUPPORT_TYPE & ODM_WIN) |
| 2129 | #if (DEV_BUS_TYPE == RT_PCI_INTERFACE) |
| 2130 | #if USE_WORKITEM |
| 2131 | platform_acquire_mutex(&pHalData->mxChnlBwControl); |
| 2132 | #else |
| 2133 | platform_acquire_spin_lock(Adapter, RT_CHANNEL_AND_BANDWIDTH_SPINLOCK); |
| 2134 | #endif |
| 2135 | #elif((DEV_BUS_TYPE == RT_USB_INTERFACE) || (DEV_BUS_TYPE == RT_SDIO_INTERFACE)) |
| 2136 | platform_acquire_mutex(&pHalData->mxChnlBwControl); |
| 2137 | #endif |
| 2138 | #endif |
| 2139 | */ |
| 2140 | priv->pshare->ThermalValue_IQK= ThermalValue; |
| 2141 | phy_iq_calibrate_8188e(priv, FALSE); |
| 2142 | |
| 2143 | /* |
| 2144 | #if(DM_ODM_SUPPORT_TYPE & ODM_WIN) |
| 2145 | #if (DEV_BUS_TYPE == RT_PCI_INTERFACE) |
| 2146 | #if USE_WORKITEM |
| 2147 | platform_release_mutex(&pHalData->mxChnlBwControl); |
| 2148 | #else |
| 2149 | platform_release_spin_lock(Adapter, RT_CHANNEL_AND_BANDWIDTH_SPINLOCK); |
| 2150 | #endif |
| 2151 | #elif((DEV_BUS_TYPE == RT_USB_INTERFACE) || (DEV_BUS_TYPE == RT_SDIO_INTERFACE)) |
| 2152 | platform_release_mutex(&pHalData->mxChnlBwControl); |
| 2153 | #endif |
| 2154 | #endif |
| 2155 | */ |
| 2156 | } |
| 2157 | #endif |
| 2158 | |
| 2159 | //update thermal meter value |
| 2160 | if(priv->pshare->TxPowerTrackControl) |
| 2161 | { |
| 2162 | //Adapter->HalFunc.SetHalDefVarHandler(Adapter, HAL_DEF_THERMAL_VALUE, &ThermalValue); |
| 2163 | priv->pshare->ThermalValue = ThermalValue; |
| 2164 | } |
| 2165 | |
| 2166 | } |
| 2167 | |
| 2168 | //printk("<===dm_TXPowerTrackingCallback_ThermalMeter_8188E\n"); |
| 2169 | |
| 2170 | priv->pshare->TXPowercount = 0; |
| 2171 | |
| 2172 | } |
| 2173 | |
| 2174 | |
| 2175 | |
| 2176 | |
| 2177 | #endif |
| 2178 | |
| 2179 | |
| 2180 | |
| 2181 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 2182 | |
| 2183 | void getDeltaValue(struct rtl8192cd_priv *priv) |
| 2184 | { |
| 2185 | unsigned int tempval[2]; |
| 2186 | |
| 2187 | tempval[0] = priv->pmib->dot11RFEntry.deltaIQK; |
| 2188 | tempval[1] = priv->pmib->dot11RFEntry.deltaLCK; |
| 2189 | |
| 2190 | switch(tempval[0]) |
| 2191 | { |
| 2192 | case 0: |
| 2193 | tempval[0] = 5; |
| 2194 | break; |
| 2195 | |
| 2196 | case 1: |
| 2197 | tempval[0] = 4; |
| 2198 | break; |
| 2199 | |
| 2200 | case 2: |
| 2201 | tempval[0] = 3; |
| 2202 | break; |
| 2203 | |
| 2204 | case 3: |
| 2205 | default: |
| 2206 | tempval[0] = 0; |
| 2207 | break; |
| 2208 | } |
| 2209 | |
| 2210 | switch(tempval[1]) |
| 2211 | { |
| 2212 | case 0: |
| 2213 | tempval[1] = 4; |
| 2214 | break; |
| 2215 | |
| 2216 | case 1: |
| 2217 | tempval[1] = 3; |
| 2218 | break; |
| 2219 | |
| 2220 | case 2: |
| 2221 | tempval[1] = 2; |
| 2222 | break; |
| 2223 | |
| 2224 | case 3: |
| 2225 | default: |
| 2226 | tempval[1] = 0; |
| 2227 | break; |
| 2228 | } |
| 2229 | |
| 2230 | priv->pshare->delta_iqk = tempval[0]; |
| 2231 | priv->pshare->delta_lck = tempval[1]; |
| 2232 | } |
| 2233 | |
| 2234 | void tx_power_tracking_92D(struct rtl8192cd_priv *priv) |
| 2235 | { |
| 2236 | u8 ThermalValue = 0, delta, delta_LCK, delta_IQK, index[2], offset, ThermalValue_AVG_count = 0; |
| 2237 | u32 ThermalValue_AVG = 0; |
| 2238 | int ele_A, ele_D, X, value32, Y, ele_C; |
| 2239 | char OFDM_index[2], CCK_index=0; |
| 2240 | int i = 0; |
| 2241 | char is2T = ((priv->pmib->dot11RFEntry.macPhyMode != DUALMAC_DUALPHY) ?1 :0); |
| 2242 | u8 OFDM_min_index = 6, OFDM_min_index_internalPA = 5, rf=1, channel; //OFDM BB Swing should be less than +3.0dB, which is required by Arthur u1Byte OFDM_min_index = 6, rf; //OFDM BB Swing should be less than +3.0dB, which is required by Arthur |
| 2243 | |
| 2244 | u8 index_mapping[5][index_mapping_NUM] = { |
| 2245 | {0, 1, 3, 6, 8, 9, //5G, path A/MAC 0, decrease power |
| 2246 | 11, 13, 14, 16, 17, 18, 18}, |
| 2247 | {0, 2, 4, 5, 7, 10, //5G, path A/MAC 0, increase power |
| 2248 | 12, 14, 16, 18, 18, 18, 18}, |
| 2249 | {0, 2, 3, 6, 8, 9, //5G, path B/MAC 1, decrease power |
| 2250 | 11, 13, 14, 16, 17, 18, 18}, |
| 2251 | {0, 2, 4, 5, 7, 10, //5G, path B/MAC 1, increase power |
| 2252 | 13, 16, 16, 18, 18, 18, 18}, |
| 2253 | {0, 1, 2, 3, 4, 5, //2.4G, for decreas power |
| 2254 | 6, 7, 7, 8, 9, 10, 10}, |
| 2255 | }; |
| 2256 | |
| 2257 | #if defined(RTL8192D_INT_PA) |
| 2258 | |
| 2259 | u8 index_mapping_internalPA[8][index_mapping_NUM] = { |
| 2260 | {0, 1, 3, 4, 6, 7, //5G, path A/MAC 0, ch36-64, decrease power |
| 2261 | 9, 11, 13, 15, 16, 16, 16}, |
| 2262 | {0, 1, 3, 4, 6, 7, //5G, path A/MAC 0, ch36-64, increase power |
| 2263 | 9, 11, 13, 15, 16, 18, 20}, |
| 2264 | {0, 1, 3, 4, 6, 7, //5G, path A/MAC 0, ch100-165, decrease power |
| 2265 | 9, 11, 13, 15, 16, 16, 16}, |
| 2266 | {0, 1, 3, 4, 6, 7, //5G, path A/MAC 0, ch100-165, increase power |
| 2267 | 9, 11, 13, 15, 16, 18, 20}, |
| 2268 | {0, 1, 3, 4, 6, 7, //5G, path B/MAC 1, ch36-64, decrease power |
| 2269 | 9, 11, 13, 15, 16, 16, 16}, |
| 2270 | {0, 1, 3, 4, 6, 7, //5G, path B/MAC 1, ch36-64, increase power |
| 2271 | 9, 11, 13, 15, 16, 18, 20}, |
| 2272 | {0, 1, 3, 4, 6, 7, //5G, path B/MAC 1, ch100-165, decrease power |
| 2273 | 9, 11, 13, 15, 16, 16, 16}, |
| 2274 | {0, 1, 3, 4, 6, 7, //5G, path B/MAC 1, ch100-165, increase power |
| 2275 | 9, 11, 13, 15, 16, 18, 20}, |
| 2276 | }; |
| 2277 | |
| 2278 | u8 bInteralPA[2]; |
| 2279 | |
| 2280 | #endif |
| 2281 | |
| 2282 | #ifdef DPK_92D |
| 2283 | short index_mapping_DPK[4][index_mapping_DPK_NUM]={ |
| 2284 | {0, 0, 1, 2, 2, //path A current thermal > PG thermal |
| 2285 | 3, 4, 5, 5, 6, |
| 2286 | 7, 7, 8, 9, 9}, |
| 2287 | {0, 0, -1, -2, -3, //path A current thermal < PG thermal |
| 2288 | -3, -4, -5, -6, -6, |
| 2289 | -7, -8, -9, -9, -10}, |
| 2290 | {0, 0, 1, 2, 2, //path B current thermal > PG thermal |
| 2291 | 3, 4, 5, 5, 6, |
| 2292 | 7, 7, 8, 9, 9}, |
| 2293 | {0, 0, -1, -2, -3, //path B current thermal < PG thermal |
| 2294 | -3, -4, -5, -6, -6, |
| 2295 | -7, -8, -9, -9, -10} |
| 2296 | }; |
| 2297 | |
| 2298 | u8 delta_DPK; |
| 2299 | short index_DPK[2] = { 0xb68, 0xb6c }, value_DPK, value_DPK_shift; |
| 2300 | int j; |
| 2301 | |
| 2302 | if(priv->pshare->bDPKworking) { |
| 2303 | DEBUG_INFO("DPK in progress abort tx power tracking \n"); |
| 2304 | return; |
| 2305 | } |
| 2306 | |
| 2307 | #endif |
| 2308 | |
| 2309 | |
| 2310 | #ifdef HIGH_POWER_EXT_PA //Modify HP tracking table, from Arthur 2012.02.13 |
| 2311 | |
| 2312 | u8 index_mapping_HighPower_PA[12][index_mapping_NUM] = { |
| 2313 | {0, 2, 3, 4, 7, 8, 10, 12, 13, 15, 16, 17, 18}, //5G, path A/MAC 0, ch36-64, decrease power |
| 2314 | {0, 2, 4, 7, 8, 10, 11, 15, 17, 19, 21, 23, 23}, //5G, path A/MAC 0, ch36-64, increase power |
| 2315 | {0, 4, 5, 8, 9, 11, 14, 15, 16, 17, 18, 19, 20}, //5G, path A/MAC 0, ch100-140, decrease power |
| 2316 | {0, 2, 4, 5, 7, 9, 13, 15, 19, 21, 22, 23, 23}, //5G, path A/MAC 0, ch100-140, increase power |
| 2317 | {0, 4, 5, 8, 9, 11, 14, 15, 17, 18, 19, 20, 21}, //5G, path A/MAC 0, ch149-165, decrease power |
| 2318 | {0, 2, 4, 6, 8, 10, 14, 16, 19, 21, 22, 24, 24}, //5G, path A/MAC 0, ch149-165, increase power |
| 2319 | {0, 4, 5, 6, 8, 9, 11, 12, 13, 14, 15, 16, 17}, //5G, path B/MAC 1, ch36-64, decrease power |
| 2320 | {0, 2, 4, 7, 8, 10, 11, 15, 17, 19, 21, 23, 23}, //5G, path B/MAC 1, ch36-64, increase power |
| 2321 | {0, 3, 4, 6, 7, 9, 12, 13, 14, 15, 17, 18, 19}, //5G, path B/MAC 1, ch100-140, decrease power |
| 2322 | {0, 2, 4, 5, 7, 9, 13, 15, 19, 21, 22, 23, 23}, //5G, path B/MAC 1, ch100-140, increase power |
| 2323 | {0, 3, 4, 6, 7, 9, 12, 13, 15, 16, 17, 18, 19}, //5G, path B/MAC 1, ch149-165, decrease power |
| 2324 | {0, 3, 5, 7, 9, 11, 13, 17, 19, 21, 22, 23, 23}, //5G, path B/MAC 1, ch149-165, increase power |
| 2325 | }; |
| 2326 | |
| 2327 | #endif |
| 2328 | |
| 2329 | #ifdef MP_TEST |
| 2330 | if ((OPMODE & WIFI_MP_STATE) || priv->pshare->rf_ft_var.mp_specific) { |
| 2331 | channel=priv->pshare->working_channel; |
| 2332 | if(priv->pshare->mp_txpwr_tracking == FALSE) |
| 2333 | return; |
| 2334 | } else |
| 2335 | #endif |
| 2336 | { |
| 2337 | channel = (priv->pmib->dot11RFEntry.dot11channel); |
| 2338 | } |
| 2339 | #if 0 |
| 2340 | if (priv->pshare->pwr_trk_ongoing==0) { |
| 2341 | phy_set_rf_reg(priv, RF_PATH_A, RF_T_METER_92D, bMask20Bits, 0x30000); |
| 2342 | priv->pshare->pwr_trk_ongoing = 1; |
| 2343 | return; |
| 2344 | } |
| 2345 | else |
| 2346 | #endif |
| 2347 | { |
| 2348 | ThermalValue =(unsigned char)phy_query_rf_reg(priv, RF_PATH_A, RF_T_METER_92D, 0xf800, 1); |
| 2349 | // priv->pshare->pwr_trk_ongoing = 0; |
| 2350 | #ifdef DPK_92D |
| 2351 | priv->pshare->ThermalValue_DPKtrack = ThermalValue; |
| 2352 | #endif |
| 2353 | } |
| 2354 | DEBUG_INFO("Readback Thermal Meter = 0x%lx pre thermal meter 0x%lx EEPROMthermalmeter 0x%lx\n", ThermalValue, |
| 2355 | priv->pshare->thermal_value, priv->pmib->dot11RFEntry.ther); |
| 2356 | |
| 2357 | if(is2T) |
| 2358 | rf = 2; |
| 2359 | else |
| 2360 | rf = 1; |
| 2361 | |
| 2362 | if (ThermalValue) { |
| 2363 | |
| 2364 | //Query OFDM path A default setting |
| 2365 | ele_D = phy_query_bb_reg(priv, REG_OFDM_0_XA_TX_IQ_IMBALANCE, bMaskDWord)&bMaskOFDM_D; |
| 2366 | for(i=0; i<OFDM_TABLE_SIZE_92D; i++) { //find the index |
| 2367 | if(ele_D == (OFDMSwingTable_92D[i]&bMaskOFDM_D)) { |
| 2368 | priv->pshare->OFDM_index0[0] = i; |
| 2369 | DEBUG_INFO("Initial pathA ele_D reg0x%x = 0x%lx, OFDM_index=0x%x\n", |
| 2370 | REG_OFDM_0_XA_TX_IQ_IMBALANCE, ele_D, priv->pshare->OFDM_index0[0]); |
| 2371 | break; |
| 2372 | } |
| 2373 | } |
| 2374 | |
| 2375 | //Query OFDM path B default setting |
| 2376 | if(is2T) { |
| 2377 | ele_D = phy_query_bb_reg(priv, REG_OFDM_0_XB_TX_IQ_IMBALANCE, bMaskDWord)&bMaskOFDM_D; |
| 2378 | for(i=0; i<OFDM_TABLE_SIZE_92D; i++) { |
| 2379 | if(ele_D == (OFDMSwingTable_92D[i]&bMaskOFDM_D)) { |
| 2380 | priv->pshare->OFDM_index0[1] = i; |
| 2381 | DEBUG_INFO("Initial pathB ele_D reg0x%x = 0x%lx, OFDM_index=0x%x\n", |
| 2382 | REG_OFDM_0_XB_TX_IQ_IMBALANCE, ele_D, priv->pshare->OFDM_index0[1]); |
| 2383 | break; |
| 2384 | } |
| 2385 | } |
| 2386 | } |
| 2387 | |
| 2388 | if(priv->pmib->dot11RFEntry.phyBandSelect == PHY_BAND_2G) { |
| 2389 | priv->pshare->CCK_index0 = get_CCK_swing_index(priv); |
| 2390 | } else { |
| 2391 | priv->pshare->CCK_index0 = 12; |
| 2392 | } |
| 2393 | |
| 2394 | if(!priv->pshare->thermal_value) { |
| 2395 | priv->pshare->thermal_value = priv->pmib->dot11RFEntry.ther; |
| 2396 | priv->pshare->thermal_value_lck = ThermalValue; |
| 2397 | priv->pshare->thermal_value_iqk = ThermalValue; |
| 2398 | #ifdef RX_GAIN_TRACK_92D |
| 2399 | priv->pshare->ThermalValue_RxGain = priv->pmib->dot11RFEntry.ther; |
| 2400 | #endif |
| 2401 | #ifdef DPK_92D |
| 2402 | priv->pshare->ThermalValue_DPK = ThermalValue; |
| 2403 | #endif |
| 2404 | for(i = 0; i < rf; i++) |
| 2405 | priv->pshare->OFDM_index[i] = priv->pshare->OFDM_index0[i]; |
| 2406 | priv->pshare->CCK_index = priv->pshare->CCK_index0; |
| 2407 | } |
| 2408 | |
| 2409 | |
| 2410 | //calculate average thermal meter |
| 2411 | { |
| 2412 | priv->pshare->Thermal_log[priv->pshare->Thermal_idx] = ThermalValue; |
| 2413 | priv->pshare->Thermal_idx = (priv->pshare->Thermal_idx+1)%8; |
| 2414 | |
| 2415 | for(i=0; i<8; i++) { |
| 2416 | if(priv->pshare->Thermal_log[i]) { |
| 2417 | ThermalValue_AVG += priv->pshare->Thermal_log[i]; |
| 2418 | ThermalValue_AVG_count++; |
| 2419 | } |
| 2420 | } |
| 2421 | |
| 2422 | if(ThermalValue_AVG_count) |
| 2423 | ThermalValue = (u8)(ThermalValue_AVG / ThermalValue_AVG_count); |
| 2424 | } |
| 2425 | |
| 2426 | |
| 2427 | delta = RTL_ABS(ThermalValue, priv->pshare->thermal_value); |
| 2428 | delta_LCK = RTL_ABS(ThermalValue, priv->pshare->thermal_value_lck); |
| 2429 | delta_IQK = RTL_ABS(ThermalValue, priv->pshare->thermal_value_iqk); |
| 2430 | |
| 2431 | // printk("Readback Thermal Meter = 0x%lx pre thermal meter 0x%lx EEPROMthermalmeter 0x%lx delta 0x%lx delta_LCK 0x%lx delta_IQK 0x%lx\n", |
| 2432 | // ThermalValue, priv->pshare->thermal_value, priv->pmib->dot11RFEntry.ther, delta, delta_LCK, delta_IQK); |
| 2433 | |
| 2434 | getDeltaValue(priv); |
| 2435 | |
| 2436 | #ifdef DPK_92D |
| 2437 | |
| 2438 | if(priv->pshare->bDPKstore) { |
| 2439 | |
| 2440 | priv->pshare->ThermalValue_DPK = ThermalValue; |
| 2441 | delta_DPK = 0; |
| 2442 | |
| 2443 | for(j = 0; j < rf; j++) { |
| 2444 | |
| 2445 | if(priv->pshare->ThermalValue_DPKstore > priv->pmib->dot11RFEntry.ther) |
| 2446 | value_DPK_shift = index_mapping_DPK[j*2][priv->pshare->ThermalValue_DPKstore- priv->pmib->dot11RFEntry.ther]; |
| 2447 | else |
| 2448 | value_DPK_shift = index_mapping_DPK[j*2+1][priv->pmib->dot11RFEntry.ther- priv->pshare->ThermalValue_DPKstore]; |
| 2449 | |
| 2450 | for(i = 0; i < index_mapping_DPK_NUM; i++) { |
| 2451 | priv->pshare->index_mapping_DPK_current[j*2][i] = |
| 2452 | index_mapping_DPK[j*2][i]-value_DPK_shift; |
| 2453 | priv->pshare->index_mapping_DPK_current[j*2+1][i] = |
| 2454 | index_mapping_DPK[j*2+1][i]-value_DPK_shift; |
| 2455 | } |
| 2456 | } |
| 2457 | } |
| 2458 | else |
| 2459 | { |
| 2460 | delta_DPK = RTL_ABS(ThermalValue, priv->pshare->ThermalValue_DPK); |
| 2461 | } |
| 2462 | |
| 2463 | for(j = 0; j < rf; j++) { |
| 2464 | if(!priv->pshare->bDPKdone[j]) |
| 2465 | priv->pshare->OFDM_min_index_internalPA_DPK[j] = 0; |
| 2466 | } |
| 2467 | |
| 2468 | #endif |
| 2469 | |
| 2470 | #if 1 |
| 2471 | if ((delta_LCK > priv->pshare->delta_lck) && (priv->pshare->delta_lck != 0)) { |
| 2472 | priv->pshare->thermal_value_lck = ThermalValue; |
| 2473 | PHY_LCCalibrate_92D(priv); |
| 2474 | } |
| 2475 | #endif |
| 2476 | if(delta > 0 |
| 2477 | #ifdef DPK_92D |
| 2478 | ||(priv->pshare->bDPKstore) |
| 2479 | #endif |
| 2480 | ){ |
| 2481 | if(delta == 0 && priv->pmib->dot11RFEntry.phyBandSelect == PHY_BAND_2G) |
| 2482 | goto TxPowerDPK; |
| 2483 | #ifdef DPK_92D |
| 2484 | if(priv->pshare->bDPKstore) |
| 2485 | priv->pshare->bDPKstore = FALSE; |
| 2486 | #endif |
| 2487 | delta = RTL_ABS(ThermalValue, priv->pmib->dot11RFEntry.ther); |
| 2488 | |
| 2489 | //calculate new OFDM / CCK offset |
| 2490 | { |
| 2491 | if (priv->pmib->dot11RFEntry.phyBandSelect == PHY_BAND_2G){ |
| 2492 | |
| 2493 | #ifdef _TRACKING_TABLE_FILE |
| 2494 | if (priv->pshare->rf_ft_var.pwr_track_file) { |
| 2495 | if(ThermalValue > priv->pmib->dot11RFEntry.ther) |
| 2496 | { |
| 2497 | for(i = 0; i < rf; i++) |
| 2498 | OFDM_index[i] = priv->pshare->OFDM_index[i] - get_tx_tracking_index(priv, channel, i, delta, 0, 0); |
| 2499 | |
| 2500 | CCK_index = priv->pshare->CCK_index - get_tx_tracking_index(priv, channel, 0, delta, 0, 1); |
| 2501 | } |
| 2502 | else |
| 2503 | { |
| 2504 | for(i = 0; i < rf; i++) |
| 2505 | OFDM_index[i] = priv->pshare->OFDM_index[i] + get_tx_tracking_index(priv, channel, i, delta, 1, 0); |
| 2506 | |
| 2507 | CCK_index = priv->pshare->CCK_index + get_tx_tracking_index(priv, channel, i, delta, 1, 1); |
| 2508 | } |
| 2509 | } |
| 2510 | else |
| 2511 | #endif |
| 2512 | { |
| 2513 | offset = 4; |
| 2514 | |
| 2515 | if(delta > index_mapping_NUM-1) |
| 2516 | index[0] = index_mapping[offset][index_mapping_NUM-1]; |
| 2517 | else |
| 2518 | index[0] = index_mapping[offset][delta]; |
| 2519 | |
| 2520 | if(ThermalValue > priv->pmib->dot11RFEntry.ther) { |
| 2521 | for(i = 0; i < rf; i++) |
| 2522 | OFDM_index[i] = priv->pshare->OFDM_index[i] - delta; |
| 2523 | CCK_index = priv->pshare->CCK_index - delta; |
| 2524 | } |
| 2525 | else { |
| 2526 | for(i = 0; i < rf; i++) |
| 2527 | OFDM_index[i] = priv->pshare->OFDM_index[i] + index[0]; |
| 2528 | CCK_index = priv->pshare->CCK_index + index[0]; |
| 2529 | } |
| 2530 | } |
| 2531 | } else if (priv->pmib->dot11RFEntry.phyBandSelect == PHY_BAND_5G) { |
| 2532 | for(i = 0; i < rf; i++){ |
| 2533 | |
| 2534 | #if defined(RTL8192D_INT_PA) |
| 2535 | |
| 2536 | if (priv->pmib->dot11RFEntry.macPhyMode == DUALMAC_DUALPHY && priv->pshare->wlandev_idx==1) //MAC 1 5G |
| 2537 | bInteralPA[i] = priv->pshare->phw->InternalPA5G[1]; |
| 2538 | else |
| 2539 | bInteralPA[i] = priv->pshare->phw->InternalPA5G[i]; |
| 2540 | |
| 2541 | if(bInteralPA[i]) { |
| 2542 | if(priv->pshare->wlandev_idx == 1 || i == 1/*rf*/) |
| 2543 | offset = 4; |
| 2544 | else |
| 2545 | offset = 0; |
| 2546 | if(channel >= 100 && channel <= 165) |
| 2547 | offset += 2; |
| 2548 | } |
| 2549 | else |
| 2550 | #endif |
| 2551 | { |
| 2552 | if(priv->pshare->wlandev_idx == 1 || i == 1) |
| 2553 | offset = 2; |
| 2554 | else |
| 2555 | offset = 0; |
| 2556 | } |
| 2557 | |
| 2558 | |
| 2559 | #ifdef HIGH_POWER_EXT_PA //Modify HP tracking table, from Arthur 2012.02.13 |
| 2560 | if(i == 0) |
| 2561 | { |
| 2562 | if(channel <= 99) |
| 2563 | offset = 0; |
| 2564 | else if(channel <= 140) |
| 2565 | offset = 2; |
| 2566 | else |
| 2567 | offset = 4; |
| 2568 | } |
| 2569 | else |
| 2570 | { |
| 2571 | if(channel <= 99) |
| 2572 | offset = 6; |
| 2573 | else if(channel <= 140) |
| 2574 | offset = 8; |
| 2575 | else |
| 2576 | offset = 10; |
| 2577 | } |
| 2578 | #endif |
| 2579 | |
| 2580 | |
| 2581 | if(ThermalValue > priv->pmib->dot11RFEntry.ther) //set larger Tx power |
| 2582 | offset++; |
| 2583 | #if defined(RTL8192D_INT_PA) |
| 2584 | if(bInteralPA[i]) { |
| 2585 | if(delta > index_mapping_NUM-1) |
| 2586 | index[i] = index_mapping_internalPA[offset][index_mapping_NUM-1]; |
| 2587 | else |
| 2588 | index[i] = index_mapping_internalPA[offset][delta]; |
| 2589 | } else |
| 2590 | #endif |
| 2591 | { |
| 2592 | if(delta > index_mapping_NUM-1) |
| 2593 | index[i] = index_mapping[offset][index_mapping_NUM-1]; |
| 2594 | else |
| 2595 | index[i] = index_mapping[offset][delta]; |
| 2596 | } |
| 2597 | |
| 2598 | |
| 2599 | |
| 2600 | #ifdef _TRACKING_TABLE_FILE |
| 2601 | if (priv->pshare->rf_ft_var.pwr_track_file) |
| 2602 | { |
| 2603 | if(ThermalValue > priv->pmib->dot11RFEntry.ther) |
| 2604 | index[i] = get_tx_tracking_index(priv, channel, i, delta, 0, 0); |
| 2605 | else |
| 2606 | index[i] = get_tx_tracking_index(priv, channel, i, delta, 1, 0); |
| 2607 | } |
| 2608 | else |
| 2609 | #endif |
| 2610 | { |
| 2611 | #ifdef HIGH_POWER_EXT_PA //Modify HP tracking table, from Arthur 2012.02.13 |
| 2612 | { |
| 2613 | if(delta > index_mapping_NUM-1) |
| 2614 | index[i] = index_mapping_HighPower_PA[offset][index_mapping_NUM-1]; |
| 2615 | else |
| 2616 | index[i] = index_mapping_HighPower_PA[offset][delta]; |
| 2617 | |
| 2618 | //printk("\n\n offset = %d delta = %d \n", offset, delta); |
| 2619 | //printk("index[%d]= %d\n\n", i, index[i]); |
| 2620 | } |
| 2621 | #endif |
| 2622 | } |
| 2623 | |
| 2624 | |
| 2625 | |
| 2626 | if(ThermalValue > priv->pmib->dot11RFEntry.ther) //set larger Tx power |
| 2627 | { |
| 2628 | #if 0 |
| 2629 | if(bInteralPA[i] && ThermalValue > 0x12) |
| 2630 | index[i] = ((delta/2)*3+(delta%2)); |
| 2631 | #endif |
| 2632 | OFDM_index[i] = priv->pshare->OFDM_index[i] -index[i]; |
| 2633 | } |
| 2634 | else |
| 2635 | { |
| 2636 | OFDM_index[i] = priv->pshare->OFDM_index[i] + index[i]; |
| 2637 | } |
| 2638 | } |
| 2639 | } |
| 2640 | |
| 2641 | if(is2T) |
| 2642 | { |
| 2643 | DEBUG_INFO("temp OFDM_A_index=0x%x, OFDM_B_index=0x%x, CCK_index=0x%x\n", |
| 2644 | priv->pshare->OFDM_index[0], priv->pshare->OFDM_index[1], priv->pshare->CCK_index); |
| 2645 | } |
| 2646 | else |
| 2647 | { |
| 2648 | DEBUG_INFO("temp OFDM_A_index=0x%x, CCK_index=0x%x\n", |
| 2649 | priv->pshare->OFDM_index[0], priv->pshare->CCK_index); |
| 2650 | } |
| 2651 | |
| 2652 | for(i = 0; i < rf; i++) |
| 2653 | { |
| 2654 | if(OFDM_index[i] > OFDM_TABLE_SIZE_92D-1) { |
| 2655 | OFDM_index[i] = OFDM_TABLE_SIZE_92D-1; |
| 2656 | } |
| 2657 | else if(priv->pmib->dot11RFEntry.phyBandSelect == PHY_BAND_2G) { |
| 2658 | if (OFDM_index[i] < (OFDM_min_index_internalPA)) |
| 2659 | OFDM_index[i] = (OFDM_min_index_internalPA); |
| 2660 | } else if(bInteralPA[i]) { |
| 2661 | #ifdef DPK_92D |
| 2662 | if (OFDM_index[i] < (OFDM_min_index_internalPA+ priv->pshare->OFDM_min_index_internalPA_DPK[i])) |
| 2663 | { |
| 2664 | priv->pshare->TxPowerLevelDPK[i] = OFDM_min_index_internalPA+ priv->pshare->OFDM_min_index_internalPA_DPK[i]-OFDM_index[i]; |
| 2665 | OFDM_index[i] = (OFDM_min_index_internalPA+ priv->pshare->OFDM_min_index_internalPA_DPK[i]); |
| 2666 | } |
| 2667 | else |
| 2668 | { |
| 2669 | priv->pshare->TxPowerLevelDPK[i] = 0; |
| 2670 | } |
| 2671 | #else |
| 2672 | if (OFDM_index[i] < (OFDM_min_index_internalPA)) |
| 2673 | { |
| 2674 | OFDM_index[i] = (OFDM_min_index_internalPA); |
| 2675 | } |
| 2676 | #endif |
| 2677 | } else if(OFDM_index[i] < OFDM_min_index) { |
| 2678 | #ifdef HIGH_POWER_EXT_PA //Modify HP tracking table, from Arthur 2012.02.13 |
| 2679 | #else |
| 2680 | OFDM_index[i] = OFDM_min_index; |
| 2681 | #endif |
| 2682 | } |
| 2683 | } |
| 2684 | |
| 2685 | if (priv->pmib->dot11RFEntry.phyBandSelect == PHY_BAND_2G){ |
| 2686 | if(CCK_index > CCK_TABLE_SIZE_92D-1) |
| 2687 | CCK_index = CCK_TABLE_SIZE_92D-1; |
| 2688 | else if (CCK_index < 0) |
| 2689 | CCK_index = 0; |
| 2690 | } |
| 2691 | |
| 2692 | if(is2T) { |
| 2693 | DEBUG_INFO("new OFDM_A_index=0x%x, OFDM_B_index=0x%x, CCK_index=0x%x\n", |
| 2694 | OFDM_index[0], OFDM_index[1], CCK_index); |
| 2695 | } |
| 2696 | else |
| 2697 | { |
| 2698 | DEBUG_INFO("new OFDM_A_index=0x%x, CCK_index=0x%x\n", |
| 2699 | OFDM_index[0], CCK_index); |
| 2700 | } |
| 2701 | } |
| 2702 | |
| 2703 | //Config by SwingTable |
| 2704 | { |
| 2705 | //Adujst OFDM Ant_A according to IQK result |
| 2706 | ele_D = (OFDMSwingTable_92D[(unsigned int)OFDM_index[0]] & 0xFFC00000)>>22; |
| 2707 | X = priv->pshare->RegE94; |
| 2708 | Y = priv->pshare->RegE9C; |
| 2709 | |
| 2710 | if(X != 0 && (priv->pmib->dot11RFEntry.phyBandSelect == PHY_BAND_2G)){ |
| 2711 | if ((X & 0x00000200) != 0) |
| 2712 | X = X | 0xFFFFFC00; |
| 2713 | ele_A = ((X * ele_D)>>8)&0x000003FF; |
| 2714 | |
| 2715 | //new element C = element D x Y |
| 2716 | if ((Y & 0x00000200) != 0) |
| 2717 | Y = Y | 0xFFFFFC00; |
| 2718 | ele_C = ((Y * ele_D)>>8)&0x000003FF; |
| 2719 | |
| 2720 | //wirte new elements A, C, D to regC80 and regC94, element B is always 0 |
| 2721 | value32 = (ele_D<<22)|((ele_C&0x3F)<<16)|ele_A; |
| 2722 | phy_set_bb_reg(priv, REG_OFDM_0_XA_TX_IQ_IMBALANCE, bMaskDWord, value32); |
| 2723 | |
| 2724 | value32 = (ele_C&0x000003C0)>>6; |
| 2725 | phy_set_bb_reg(priv, REG_OFDM_0_XC_TX_AFE, bMaskH4Bits, value32); |
| 2726 | |
| 2727 | value32 = ((X * ele_D)>>7)&0x01; |
| 2728 | phy_set_bb_reg(priv, REG_OFDM_0_ECCA_THRESHOLD, BIT(24), value32); |
| 2729 | |
| 2730 | } |
| 2731 | else |
| 2732 | { |
| 2733 | phy_set_bb_reg(priv, REG_OFDM_0_XA_TX_IQ_IMBALANCE, bMaskDWord, OFDMSwingTable_92D[(unsigned int)OFDM_index[0]]); |
| 2734 | phy_set_bb_reg(priv, REG_OFDM_0_XC_TX_AFE, bMaskH4Bits, 0x00); |
| 2735 | phy_set_bb_reg(priv, REG_OFDM_0_ECCA_THRESHOLD, BIT(24), 0x00); |
| 2736 | #ifdef MP_TEST |
| 2737 | if ((priv->pshare->rf_ft_var.mp_specific) && (!is2T)) { |
| 2738 | unsigned char str[50]; |
| 2739 | sprintf(str, "patha=%d,pathb=%d", priv->pshare->mp_txpwr_patha, priv->pshare->mp_txpwr_pathb); |
| 2740 | mp_set_tx_power(priv, str); |
| 2741 | } |
| 2742 | #endif |
| 2743 | } |
| 2744 | DEBUG_INFO("TxPwrTracking for interface %d path A: X = 0x%x, Y = 0x%x ele_A = 0x%x ele_C = 0x%x ele_D = 0x%x\n", |
| 2745 | priv->pshare->wlandev_idx, X, Y, ele_A, ele_C, ele_D); |
| 2746 | |
| 2747 | |
| 2748 | if(priv->pmib->dot11RFEntry.phyBandSelect == PHY_BAND_2G) |
| 2749 | { |
| 2750 | //Adjust CCK according to IQK result |
| 2751 | set_CCK_swing_index(priv, CCK_index); |
| 2752 | } |
| 2753 | |
| 2754 | if(is2T) |
| 2755 | { |
| 2756 | ele_D = (OFDMSwingTable_92D[(unsigned int)OFDM_index[1]] & 0xFFC00000)>>22; |
| 2757 | |
| 2758 | //new element A = element D x X |
| 2759 | X = priv->pshare->RegEB4; |
| 2760 | Y = priv->pshare->RegEBC; |
| 2761 | |
| 2762 | if(X != 0 && (priv->pmib->dot11RFEntry.phyBandSelect == PHY_BAND_2G)){ |
| 2763 | if ((X & 0x00000200) != 0) //consider minus |
| 2764 | X = X | 0xFFFFFC00; |
| 2765 | ele_A = ((X * ele_D)>>8)&0x000003FF; |
| 2766 | |
| 2767 | //new element C = element D x Y |
| 2768 | if ((Y & 0x00000200) != 0) |
| 2769 | Y = Y | 0xFFFFFC00; |
| 2770 | ele_C = ((Y * ele_D)>>8)&0x00003FF; |
| 2771 | |
| 2772 | //wirte new elements A, C, D to regC88 and regC9C, element B is always 0 |
| 2773 | value32=(ele_D<<22)|((ele_C&0x3F)<<16) |ele_A; |
| 2774 | phy_set_bb_reg(priv, REG_OFDM_0_XB_TX_IQ_IMBALANCE, bMaskDWord, value32); |
| 2775 | |
| 2776 | value32 = (ele_C&0x000003C0)>>6; |
| 2777 | phy_set_bb_reg(priv, REG_OFDM_0_XD_TX_AFE, bMaskH4Bits, value32); |
| 2778 | |
| 2779 | value32 = ((X * ele_D)>>7)&0x01; |
| 2780 | phy_set_bb_reg(priv, REG_OFDM_0_ECCA_THRESHOLD, BIT(28), value32); |
| 2781 | |
| 2782 | } |
| 2783 | else{ |
| 2784 | phy_set_bb_reg(priv, REG_OFDM_0_XB_TX_IQ_IMBALANCE, bMaskDWord, OFDMSwingTable_92D[(unsigned int)OFDM_index[1]]); |
| 2785 | phy_set_bb_reg(priv, REG_OFDM_0_XD_TX_AFE, bMaskH4Bits, 0x00); |
| 2786 | phy_set_bb_reg(priv, REG_OFDM_0_ECCA_THRESHOLD, BIT(28), 0x00); |
| 2787 | #ifdef MP_TEST |
| 2788 | if ((priv->pshare->rf_ft_var.mp_specific) ) { |
| 2789 | unsigned char str[50]; |
| 2790 | sprintf(str, "patha=%d,pathb=%d", priv->pshare->mp_txpwr_patha, priv->pshare->mp_txpwr_pathb); |
| 2791 | mp_set_tx_power(priv, str); |
| 2792 | |
| 2793 | } |
| 2794 | #endif |
| 2795 | } |
| 2796 | |
| 2797 | DEBUG_INFO("TxPwrTracking path B: X = 0x%x, Y = 0x%x ele_A = 0x%x ele_C = 0x%x ele_D = 0x%x\n", |
| 2798 | X, Y, ele_A, ele_C, ele_D); |
| 2799 | } |
| 2800 | |
| 2801 | DEBUG_INFO("TxPwrTracking 0xc80 = 0x%x, 0xc94 = 0x%x RF 0x24 = 0x%x\n", phy_query_bb_reg(priv, 0xc80, bMaskDWord), |
| 2802 | phy_query_bb_reg(priv, 0xc94, bMaskDWord), phy_query_rf_reg(priv, RF_PATH_A, 0x24, bMask20Bits,1)); |
| 2803 | } |
| 2804 | } |
| 2805 | |
| 2806 | TxPowerDPK: |
| 2807 | #ifdef DPK_92D |
| 2808 | { |
| 2809 | char bNOPG = FALSE; |
| 2810 | unsigned char pwrlevelHT40_1S_A = priv->pmib->dot11RFEntry.pwrlevelHT40_1S_A[channel-1]; |
| 2811 | if (priv->pmib->dot11RFEntry.phyBandSelect & PHY_BAND_5G) |
| 2812 | pwrlevelHT40_1S_A = priv->pmib->dot11RFEntry.pwrlevel5GHT40_1S_A[channel-1]; |
| 2813 | #ifdef CONFIG_RTL_92D_DMDP |
| 2814 | if ((priv->pmib->dot11RFEntry.macPhyMode==DUALMAC_DUALPHY) && |
| 2815 | (priv->pshare->wlandev_idx == 1) && (priv->pmib->dot11RFEntry.phyBandSelect & PHY_BAND_5G)) |
| 2816 | pwrlevelHT40_1S_A = priv->pmib->dot11RFEntry.pwrlevel5GHT40_1S_B[channel-1]; |
| 2817 | if (pwrlevelHT40_1S_A == 0) |
| 2818 | bNOPG = TRUE; |
| 2819 | #endif |
| 2820 | |
| 2821 | //for DPK |
| 2822 | if(delta_DPK > 0 && !bNOPG /*&& pHalData->bDPKdone*/) { |
| 2823 | for(i = 0; i < rf; i++) { |
| 2824 | if(bInteralPA[i] && priv->pshare->bDPKdone[i]) { |
| 2825 | if(ThermalValue > priv->pmib->dot11RFEntry.ther) |
| 2826 | value_DPK = priv->pshare->index_mapping_DPK_current[i*2][ThermalValue-priv->pmib->dot11RFEntry.ther]; |
| 2827 | else |
| 2828 | value_DPK = priv->pshare->index_mapping_DPK_current[i*2+1][priv->pmib->dot11RFEntry.ther-ThermalValue]; |
| 2829 | |
| 2830 | phy_set_bb_reg(priv, index_DPK[i], 0x7c00, value_DPK); |
| 2831 | } |
| 2832 | } |
| 2833 | priv->pshare->ThermalValue_DPK = ThermalValue; |
| 2834 | } |
| 2835 | } |
| 2836 | #endif |
| 2837 | priv->pshare->pwr_trk_ongoing = 0; |
| 2838 | #if 1 |
| 2839 | if ((delta_IQK > priv->pshare->delta_iqk) && (priv->pshare->delta_iqk != 0)) { |
| 2840 | priv->pshare->thermal_value_iqk = ThermalValue; |
| 2841 | phy_iq_calibrate(priv); |
| 2842 | } |
| 2843 | #endif |
| 2844 | |
| 2845 | #ifdef RX_GAIN_TRACK_92D |
| 2846 | if(priv->pmib->dot11RFEntry.ther && (priv->pmib->dot11RFEntry.phyBandSelect == PHY_BAND_5G) && |
| 2847 | (ThermalValue < priv->pmib->dot11RFEntry.ther)) { |
| 2848 | priv->pshare->ThermalValue_RxGain = ThermalValue; |
| 2849 | rx_gain_tracking_92D(priv); |
| 2850 | } |
| 2851 | #endif |
| 2852 | |
| 2853 | //update thermal meter value |
| 2854 | priv->pshare->thermal_value = ThermalValue; |
| 2855 | } |
| 2856 | } |
| 2857 | |
| 2858 | #endif |
| 2859 | |
| 2860 | //3 ============================================================ |
| 2861 | //3 EDCA Turbo |
| 2862 | //3 ============================================================ |
| 2863 | |
| 2864 | void init_EDCA_para(struct rtl8192cd_priv *priv, int mode) |
| 2865 | { |
| 2866 | static unsigned int slot_time, VO_TXOP, VI_TXOP, sifs_time; |
| 2867 | |
| 2868 | struct ParaRecord EDCA[4]; |
| 2869 | #ifdef RTL_MANUAL_EDCA |
| 2870 | //unsigned char acm_bitmap; |
| 2871 | #endif |
| 2872 | |
| 2873 | slot_time = 20; |
| 2874 | sifs_time = 10; |
| 2875 | |
| 2876 | if (mode & WIRELESS_11N) |
| 2877 | sifs_time = 16; |
| 2878 | |
| 2879 | #ifdef RTL_MANUAL_EDCA |
| 2880 | if( priv->pmib->dot11QosEntry.ManualEDCA ) { |
| 2881 | memset(EDCA, 0, 4*sizeof(struct ParaRecord)); |
| 2882 | if( OPMODE & WIFI_AP_STATE ) |
| 2883 | memcpy(EDCA, priv->pmib->dot11QosEntry.AP_manualEDCA, 4*sizeof(struct ParaRecord)); |
| 2884 | else |
| 2885 | memcpy(EDCA, priv->pmib->dot11QosEntry.STA_manualEDCA, 4*sizeof(struct ParaRecord)); |
| 2886 | |
| 2887 | |
| 2888 | if ((mode & WIRELESS_11N) || |
| 2889 | (mode & WIRELESS_11G)) { |
| 2890 | slot_time = 9; |
| 2891 | } |
| 2892 | |
| 2893 | |
| 2894 | RTL_W32(EDCA_VO_PARA, (EDCA[VO].TXOPlimit << 16) | (EDCA[VO].ECWmax << 12) | (EDCA[VO].ECWmin << 8) | (sifs_time + EDCA[VO].AIFSN * slot_time)); |
| 2895 | #ifdef WIFI_WMM |
| 2896 | if (QOS_ENABLE) |
| 2897 | RTL_W32(EDCA_VI_PARA, (EDCA[VI].TXOPlimit << 16) | (EDCA[VI].ECWmax << 12) | (EDCA[VI].ECWmin << 8) | (sifs_time + EDCA[VI].AIFSN * slot_time)); |
| 2898 | else |
| 2899 | #endif |
| 2900 | RTL_W32(EDCA_VI_PARA, (EDCA[BE].TXOPlimit << 16) | (EDCA[BE].ECWmax << 12) | (EDCA[BE].ECWmin << 8) | (sifs_time + EDCA[VI].AIFSN * slot_time)); |
| 2901 | |
| 2902 | RTL_W32(EDCA_BE_PARA, (EDCA[BE].TXOPlimit << 16) | (EDCA[BE].ECWmax << 12) | (EDCA[BE].ECWmin << 8) | (sifs_time + EDCA[BE].AIFSN * slot_time)); |
| 2903 | |
| 2904 | RTL_W32(EDCA_BK_PARA, (EDCA[BK].TXOPlimit << 16) | (EDCA[BK].ECWmax << 12) | (EDCA[BK].ECWmin << 8) | (sifs_time + EDCA[BK].AIFSN * slot_time)); |
| 2905 | }else |
| 2906 | #endif //RTL_MANUAL_EDCA |
| 2907 | { |
| 2908 | memset(EDCA, 0, 4*sizeof(struct ParaRecord)); |
| 2909 | /* copy BE, BK from static data */ |
| 2910 | if( OPMODE & WIFI_AP_STATE ) |
| 2911 | memcpy(EDCA, rtl_ap_EDCA, 2*sizeof(struct ParaRecord)); |
| 2912 | else |
| 2913 | memcpy(EDCA, rtl_sta_EDCA, 2*sizeof(struct ParaRecord)); |
| 2914 | |
| 2915 | /* VI, VO apply settings in AG by default */ |
| 2916 | if( OPMODE & WIFI_AP_STATE ) |
| 2917 | memcpy(&EDCA[2], &rtl_ap_EDCA[VI_AG], 2*sizeof(struct ParaRecord)); |
| 2918 | else |
| 2919 | memcpy(&EDCA[2], &rtl_sta_EDCA[VI_AG], 2*sizeof(struct ParaRecord)); |
| 2920 | |
| 2921 | if ((mode & WIRELESS_11N) || |
| 2922 | (mode & WIRELESS_11G)) { |
| 2923 | slot_time = 9; |
| 2924 | } else { |
| 2925 | /* replace with settings in B */ |
| 2926 | if( OPMODE & WIFI_AP_STATE ) |
| 2927 | memcpy(&EDCA[2], &rtl_ap_EDCA[VI], 2*sizeof(struct ParaRecord)); |
| 2928 | else |
| 2929 | memcpy(&EDCA[2], &rtl_sta_EDCA[VI], 2*sizeof(struct ParaRecord)); |
| 2930 | } |
| 2931 | VO_TXOP = EDCA[VO].TXOPlimit; |
| 2932 | VI_TXOP = EDCA[VI].TXOPlimit; |
| 2933 | |
| 2934 | RTL_W32(EDCA_VO_PARA, (VO_TXOP << 16) | (EDCA[VO].ECWmax << 12) | (EDCA[VO].ECWmin << 8) | (sifs_time + EDCA[VO].AIFSN * slot_time)); |
| 2935 | #ifdef WIFI_WMM |
| 2936 | if (QOS_ENABLE) |
| 2937 | RTL_W32(EDCA_VI_PARA, (VI_TXOP << 16) | (EDCA[VI].ECWmax << 12) | (EDCA[VI].ECWmin << 8) | (sifs_time + EDCA[VI].AIFSN * slot_time)); |
| 2938 | else |
| 2939 | #endif |
| 2940 | RTL_W32(EDCA_VI_PARA, (EDCA[BK].ECWmax << 12) | (EDCA[BK].ECWmin << 8) | (sifs_time + EDCA[VI].AIFSN * slot_time)); |
| 2941 | |
| 2942 | RTL_W32(EDCA_BE_PARA, ((EDCA[BE].ECWmax) << 12) | (EDCA[BE].ECWmin << 8) | (sifs_time + EDCA[BE].AIFSN * slot_time)); |
| 2943 | RTL_W32(EDCA_BK_PARA, (EDCA[BK].ECWmax << 12) | (EDCA[BK].ECWmin << 8) | (sifs_time + EDCA[BK].AIFSN * slot_time)); |
| 2944 | |
| 2945 | |
| 2946 | RTL_W8(ACMHWCTRL, 0x00); |
| 2947 | } |
| 2948 | |
| 2949 | priv->pshare->iot_mode_enable = 0; |
| 2950 | if (priv->pshare->rf_ft_var.wifi_beq_iot) |
| 2951 | priv->pshare->iot_mode_VI_exist = 0; |
| 2952 | priv->pshare->iot_mode_VO_exist = 0; |
| 2953 | |
| 2954 | #ifdef WMM_VIBE_PRI |
| 2955 | priv->pshare->iot_mode_BE_exist = 0; |
| 2956 | #endif |
| 2957 | #ifdef WMM_BEBK_PRI |
| 2958 | priv->pshare->iot_mode_BK_exist = 0; |
| 2959 | #endif |
| 2960 | #ifdef LOW_TP_TXOP |
| 2961 | priv->pshare->BE_cwmax_enhance = 0; |
| 2962 | #endif |
| 2963 | } |
| 2964 | |
| 2965 | void choose_IOT_main_sta(struct rtl8192cd_priv *priv, struct stat_info *pstat) |
| 2966 | { |
| 2967 | int i, assoc_num = GET_ROOT(priv)->assoc_num; |
| 2968 | #ifdef MBSSID |
| 2969 | if (GET_ROOT(priv)->pmib->miscEntry.vap_enable){ |
| 2970 | for (i=0; i<RTL8192CD_NUM_VWLAN; ++i) |
| 2971 | assoc_num += GET_ROOT(priv)->pvap_priv[i]-> assoc_num; |
| 2972 | } |
| 2973 | #endif |
| 2974 | #ifdef UNIVERSAL_REPEATER |
| 2975 | if (IS_DRV_OPEN(GET_VXD_PRIV(GET_ROOT(priv)))) |
| 2976 | assoc_num += GET_VXD_PRIV(GET_ROOT(priv))-> assoc_num; |
| 2977 | #endif |
| 2978 | #ifdef WDS |
| 2979 | if(GET_ROOT(priv)->pmib->dot11WdsInfo.wdsEnabled) |
| 2980 | assoc_num ++; |
| 2981 | #endif |
| 2982 | |
| 2983 | if (priv->pshare->rf_ft_var.low_tp_no_aggr) { |
| 2984 | unsigned long sta_tp = (pstat->current_tx_bytes + pstat->current_rx_bytes) >> 17; |
| 2985 | if (!pstat->low_tp_disable_ampdu && sta_tp <= 2) |
| 2986 | pstat->low_tp_disable_ampdu = 1; |
| 2987 | else if (pstat->low_tp_disable_ampdu && sta_tp >= 5) |
| 2988 | pstat->low_tp_disable_ampdu = 0; |
| 2989 | } |
| 2990 | |
| 2991 | if ((GET_ROOT(priv)->up_time % 2) == 0) { |
| 2992 | unsigned int tx_2s_avg = 0; |
| 2993 | unsigned int rx_2s_avg = 0; |
| 2994 | int i=0, aggReady=0; |
| 2995 | unsigned long total_sum = (priv->pshare->current_tx_bytes+priv->pshare->current_rx_bytes); |
| 2996 | |
| 2997 | pstat->current_tx_bytes += pstat->tx_byte_cnt; |
| 2998 | pstat->current_rx_bytes += pstat->rx_byte_cnt; |
| 2999 | |
| 3000 | if (total_sum != 0) { |
| 3001 | if (total_sum <= 1000000) { |
| 3002 | tx_2s_avg = (unsigned int)((pstat->current_tx_bytes*100) / total_sum); |
| 3003 | rx_2s_avg = (unsigned int)((pstat->current_rx_bytes*100) / total_sum); |
| 3004 | } else { |
| 3005 | tx_2s_avg = (unsigned int)(pstat->current_tx_bytes / (total_sum / 100)); |
| 3006 | rx_2s_avg = (unsigned int)(pstat->current_rx_bytes / (total_sum / 100)); |
| 3007 | } |
| 3008 | } |
| 3009 | |
| 3010 | for(i=0; i<8; i++) |
| 3011 | aggReady += (pstat->ADDBA_ready[i]); |
| 3012 | |
| 3013 | if( (pstat->IOTPeer==HT_IOT_PEER_INTEL) |
| 3014 | || (pstat->ht_cap_len && aggReady)) { |
| 3015 | |
| 3016 | if ((assoc_num==1) || (tx_2s_avg + rx_2s_avg >= 25)) { |
| 3017 | priv->pshare->highTP_found_pstat = pstat; |
| 3018 | } /*this STA's TXRX packet very close AP's total TXRX packet then let it as highTP_found_pstat*/ |
| 3019 | else if(RTL_ABS((pstat->current_tx_bytes + pstat->current_rx_bytes) , total_sum)<50){ |
| 3020 | priv->pshare->highTP_found_pstat = pstat; |
| 3021 | } |
| 3022 | #ifdef CLIENT_MODE |
| 3023 | if (OPMODE & WIFI_STATION_STATE) { |
| 3024 | // if(pstat->is_ralink_sta && ((tx_2s_avg + rx_2s_avg) >= 45)) |
| 3025 | if(pstat->IOTPeer == HT_IOT_PEER_RALINK && ((tx_2s_avg + rx_2s_avg) >= 45)) |
| 3026 | priv->pshare->highTP_found_pstat = pstat; |
| 3027 | } |
| 3028 | #endif |
| 3029 | } |
| 3030 | } |
| 3031 | else { |
| 3032 | pstat->current_tx_bytes = pstat->tx_byte_cnt; |
| 3033 | pstat->current_rx_bytes = pstat->rx_byte_cnt; |
| 3034 | } |
| 3035 | } |
| 3036 | |
| 3037 | |
| 3038 | void rxBB_dm(struct rtl8192cd_priv *priv) |
| 3039 | { |
| 3040 | if ((priv->up_time % 3) == 1) { |
| 3041 | if (priv->pshare->rssi_min != 0xff) { |
| 3042 | if (priv->pshare->rf_ft_var.dig_enable) { |
| 3043 | // for DIG checking |
| 3044 | check_DIG_by_rssi(priv, priv->pshare->rssi_min); |
| 3045 | } |
| 3046 | //#ifdef INTERFERENCE_CONTROL |
| 3047 | if (priv->pshare->rf_ft_var.nbi_filter_enable) { |
| 3048 | check_NBI_by_rssi(priv, priv->pshare->rssi_min); |
| 3049 | } |
| 3050 | //#endif |
| 3051 | } |
| 3052 | |
| 3053 | #ifdef MP_TEST |
| 3054 | if (!((OPMODE & WIFI_MP_STATE) || priv->pshare->rf_ft_var.mp_specific)) |
| 3055 | #endif |
| 3056 | { |
| 3057 | #ifdef HIGH_POWER_EXT_LNA |
| 3058 | if (!priv->pshare->rf_ft_var.use_ext_lna) |
| 3059 | #endif |
| 3060 | CCK_CCA_dynamic_enhance(priv, priv->pshare->rssi_min); |
| 3061 | } |
| 3062 | } |
| 3063 | if (priv->pshare->rf_ft_var.adaptivity_enable){ |
| 3064 | unsigned char IGI; |
| 3065 | IGI = RTL_R8(0xc50); |
| 3066 | rtl8192cd_Adaptivity(priv,IGI); |
| 3067 | } |
| 3068 | } |
| 3069 | |
| 3070 | /* |
| 3071 | * IOT related functions |
| 3072 | */ |
| 3073 | void IOT_engine(struct rtl8192cd_priv *priv) |
| 3074 | { |
| 3075 | #ifdef WIFI_WMM |
| 3076 | unsigned int switch_turbo = 0; |
| 3077 | #endif |
| 3078 | #ifdef MBSSID |
| 3079 | int i; |
| 3080 | #endif |
| 3081 | int assoc_num = priv->assoc_num; |
| 3082 | struct stat_info *pstat = priv->pshare->highTP_found_pstat; |
| 3083 | |
| 3084 | if(pstat) { |
| 3085 | if((pstat->tx_avarage + pstat->rx_avarage) < (1<<17)) // 1M bps |
| 3086 | pstat = NULL; |
| 3087 | } |
| 3088 | #if defined(RTL_MANUAL_EDCA) && defined(WIFI_WMM) |
| 3089 | if(priv->pmib->dot11QosEntry.ManualEDCA) |
| 3090 | return ; |
| 3091 | #endif |
| 3092 | |
| 3093 | #ifdef MBSSID |
| 3094 | if (GET_ROOT(priv)->pmib->miscEntry.vap_enable){ |
| 3095 | for (i=0; i<RTL8192CD_NUM_VWLAN; ++i) |
| 3096 | assoc_num += GET_ROOT(priv)->pvap_priv[i]-> assoc_num; |
| 3097 | } |
| 3098 | #endif |
| 3099 | #ifdef UNIVERSAL_REPEATER |
| 3100 | if (IS_DRV_OPEN(GET_VXD_PRIV(GET_ROOT(priv)))) |
| 3101 | assoc_num += GET_VXD_PRIV(GET_ROOT(priv))-> assoc_num; |
| 3102 | #endif |
| 3103 | #ifdef WDS |
| 3104 | if(GET_ROOT(priv)->pmib->dot11WdsInfo.wdsEnabled) |
| 3105 | assoc_num ++; |
| 3106 | #endif |
| 3107 | |
| 3108 | #ifdef WIFI_WMM |
| 3109 | if (QOS_ENABLE) { |
| 3110 | if (!priv->pmib->dot11OperationEntry.wifi_specific || |
| 3111 | ((OPMODE & WIFI_AP_STATE) && (priv->pmib->dot11OperationEntry.wifi_specific))) { |
| 3112 | if (priv->pshare->iot_mode_enable && |
| 3113 | ((priv->pshare->phw->VO_pkt_count > 50) || |
| 3114 | (priv->pshare->phw->VI_pkt_count > 50) || |
| 3115 | (priv->pshare->phw->BK_pkt_count > 50))) { |
| 3116 | priv->pshare->iot_mode_enable = 0; |
| 3117 | switch_turbo++; |
| 3118 | } else if ((!priv->pshare->iot_mode_enable) && |
| 3119 | ((priv->pshare->phw->VO_pkt_count < 50) && |
| 3120 | (priv->pshare->phw->VI_pkt_count < 50) && |
| 3121 | (priv->pshare->phw->BK_pkt_count < 50))) { |
| 3122 | priv->pshare->iot_mode_enable++; |
| 3123 | switch_turbo++; |
| 3124 | } |
| 3125 | } |
| 3126 | |
| 3127 | if ((OPMODE & WIFI_AP_STATE) && priv->pmib->dot11OperationEntry.wifi_specific) { |
| 3128 | if (!priv->pshare->iot_mode_VO_exist && (priv->pshare->phw->VO_pkt_count > 50)) { |
| 3129 | priv->pshare->iot_mode_VO_exist++; |
| 3130 | switch_turbo++; |
| 3131 | } else if (priv->pshare->iot_mode_VO_exist && (priv->pshare->phw->VO_pkt_count < 50)) { |
| 3132 | priv->pshare->iot_mode_VO_exist = 0; |
| 3133 | switch_turbo++; |
| 3134 | } |
| 3135 | |
| 3136 | #ifdef WMM_VIBE_PRI |
| 3137 | if (priv->pshare->iot_mode_VO_exist) { |
| 3138 | //printk("[%s %d] BE_pkt_count=%d\n", __FUNCTION__, __LINE__, priv->pshare->phw->BE_pkt_count); |
| 3139 | if (!priv->pshare->iot_mode_BE_exist && (priv->pshare->phw->BE_pkt_count > 250)) { |
| 3140 | priv->pshare->iot_mode_BE_exist++; |
| 3141 | switch_turbo++; |
| 3142 | } else if (priv->pshare->iot_mode_BE_exist && (priv->pshare->phw->BE_pkt_count < 250)) { |
| 3143 | priv->pshare->iot_mode_BE_exist = 0; |
| 3144 | switch_turbo++; |
| 3145 | } |
| 3146 | } |
| 3147 | #endif |
| 3148 | |
| 3149 | #ifdef WMM_BEBK_PRI |
| 3150 | if (priv->pshare->phw->BE_pkt_count) { |
| 3151 | //printk("[%s %d] BK_pkt_count=%d\n", __FUNCTION__, __LINE__, priv->pshare->phw->BK_pkt_count); |
| 3152 | if (!priv->pshare->iot_mode_BK_exist && (priv->pshare->phw->BK_pkt_count > 250)) { |
| 3153 | priv->pshare->iot_mode_BK_exist++; |
| 3154 | switch_turbo++; |
| 3155 | EDEBUG("switch_turbo++\n"); |
| 3156 | } else if (priv->pshare->iot_mode_BE_exist && (priv->pshare->phw->BK_pkt_count < 250)) { |
| 3157 | priv->pshare->iot_mode_BK_exist = 0; |
| 3158 | switch_turbo++; |
| 3159 | EDEBUG("switch_turbo++\n"); |
| 3160 | } |
| 3161 | } |
| 3162 | #endif |
| 3163 | |
| 3164 | if (priv->pshare->rf_ft_var.wifi_beq_iot) { |
| 3165 | if (!priv->pshare->iot_mode_VI_exist && (priv->pshare->phw->VI_rx_pkt_count > 50)) { |
| 3166 | priv->pshare->iot_mode_VI_exist++; |
| 3167 | switch_turbo++; |
| 3168 | } else if (priv->pshare->iot_mode_VI_exist && (priv->pshare->phw->VI_rx_pkt_count < 50)) { |
| 3169 | priv->pshare->iot_mode_VI_exist = 0; |
| 3170 | switch_turbo++; |
| 3171 | } |
| 3172 | } |
| 3173 | |
| 3174 | #ifdef CONFIG_RTL_92D_DMDP |
| 3175 | if ((GET_CHIP_VER(priv) == VERSION_8192D) && (priv->pmib->dot11RFEntry.macPhyMode == DUALMAC_DUALPHY)) { |
| 3176 | unsigned int tp = (unsigned int)(priv->ext_stats.tx_avarage>>17) + (unsigned int)(priv->ext_stats.rx_avarage>>17); |
| 3177 | if (priv->pshare->rf_ft_var.wifi_beq_iot) { |
| 3178 | if (priv->pshare->wifi_beq_lower && priv->pshare->iot_mode_VI_exist && tp <= 20) { |
| 3179 | priv->pshare->wifi_beq_lower= 0; |
| 3180 | switch_turbo++; |
| 3181 | } else if (!priv->pshare->wifi_beq_lower&& (!priv->pshare->iot_mode_VI_exist || tp > 20)) { |
| 3182 | priv->pshare->wifi_beq_lower= 1; |
| 3183 | switch_turbo++; |
| 3184 | } |
| 3185 | } |
| 3186 | } |
| 3187 | #endif |
| 3188 | } |
| 3189 | |
| 3190 | #ifdef CLIENT_MODE |
| 3191 | if ((OPMODE & WIFI_STATION_STATE) && (priv->pmib->dot11OperationEntry.wifi_specific)) |
| 3192 | { |
| 3193 | if (priv->pshare->iot_mode_enable && |
| 3194 | (((priv->pshare->phw->VO_pkt_count > 50) || |
| 3195 | (priv->pshare->phw->VI_pkt_count > 50) || |
| 3196 | (priv->pshare->phw->BK_pkt_count > 50)) || |
| 3197 | (pstat && (!pstat->ADDBA_ready[0]) & (!pstat->ADDBA_ready[3])))) |
| 3198 | { |
| 3199 | priv->pshare->iot_mode_enable = 0; |
| 3200 | switch_turbo++; |
| 3201 | } |
| 3202 | else if ((!priv->pshare->iot_mode_enable) && |
| 3203 | (((priv->pshare->phw->VO_pkt_count < 50) && |
| 3204 | (priv->pshare->phw->VI_pkt_count < 50) && |
| 3205 | (priv->pshare->phw->BK_pkt_count < 50)) && |
| 3206 | (pstat && (pstat->ADDBA_ready[0] | pstat->ADDBA_ready[3])))) |
| 3207 | { |
| 3208 | priv->pshare->iot_mode_enable++; |
| 3209 | switch_turbo++; |
| 3210 | } |
| 3211 | } |
| 3212 | #endif |
| 3213 | |
| 3214 | priv->pshare->phw->VO_pkt_count = 0; |
| 3215 | priv->pshare->phw->VI_pkt_count = 0; |
| 3216 | if (priv->pshare->rf_ft_var.wifi_beq_iot) |
| 3217 | priv->pshare->phw->VI_rx_pkt_count = 0; |
| 3218 | priv->pshare->phw->BK_pkt_count = 0; |
| 3219 | #ifdef WMM_VIBE_PRI |
| 3220 | priv->pshare->phw->BE_pkt_count = 0; |
| 3221 | #endif |
| 3222 | } |
| 3223 | #endif |
| 3224 | |
| 3225 | if ((priv->up_time % 2) == 0) { |
| 3226 | /* |
| 3227 | * decide EDCA content for different chip vendor |
| 3228 | */ |
| 3229 | #ifdef WIFI_WMM |
| 3230 | if (QOS_ENABLE && (!priv->pmib->dot11OperationEntry.wifi_specific || |
| 3231 | ((OPMODE & WIFI_AP_STATE) && (priv->pmib->dot11OperationEntry.wifi_specific == 2)) |
| 3232 | #ifdef CLIENT_MODE |
| 3233 | || ((OPMODE & WIFI_STATION_STATE) && (priv->pmib->dot11OperationEntry.wifi_specific == 2)) |
| 3234 | #endif |
| 3235 | )) { |
| 3236 | if (pstat && pstat->rssi >= priv->pshare->rf_ft_var.txop_enlarge_upper) { |
| 3237 | #ifdef LOW_TP_TXOP |
| 3238 | |
| 3239 | |
| 3240 | if (pstat->IOTPeer==HT_IOT_PEER_INTEL) |
| 3241 | |
| 3242 | { |
| 3243 | |
| 3244 | if (priv->pshare->txop_enlarge != 0xe) { |
| 3245 | priv->pshare->txop_enlarge = 0xe; |
| 3246 | if (priv->pshare->iot_mode_enable) |
| 3247 | switch_turbo++; |
| 3248 | } |
| 3249 | } else if (priv->pshare->txop_enlarge != 2) { |
| 3250 | priv->pshare->txop_enlarge = 2; |
| 3251 | if (priv->pshare->iot_mode_enable) |
| 3252 | switch_turbo++; |
| 3253 | } |
| 3254 | #else //LOW_TP_TXOP |
| 3255 | |
| 3256 | if (priv->pshare->txop_enlarge != 2) { |
| 3257 | |
| 3258 | |
| 3259 | { |
| 3260 | if (pstat->IOTPeer==HT_IOT_PEER_INTEL) |
| 3261 | priv->pshare->txop_enlarge = 0xe; |
| 3262 | else if (pstat->IOTPeer==HT_IOT_PEER_RALINK) |
| 3263 | priv->pshare->txop_enlarge = 0xd; |
| 3264 | else |
| 3265 | priv->pshare->txop_enlarge = 2; |
| 3266 | |
| 3267 | } |
| 3268 | |
| 3269 | if (priv->pshare->iot_mode_enable) |
| 3270 | switch_turbo++; |
| 3271 | } |
| 3272 | #endif //LOW_TP_TXOP |
| 3273 | } else if (!pstat || pstat->rssi < priv->pshare->rf_ft_var.txop_enlarge_lower) { |
| 3274 | if (priv->pshare->txop_enlarge) { |
| 3275 | priv->pshare->txop_enlarge = 0; |
| 3276 | if (priv->pshare->iot_mode_enable) |
| 3277 | switch_turbo++; |
| 3278 | } |
| 3279 | } |
| 3280 | #ifdef LOW_TP_TXOP |
| 3281 | // for Intel IOT, need to enlarge CW MAX from 6 to 10 |
| 3282 | |
| 3283 | |
| 3284 | if (pstat && pstat->IOTPeer==HT_IOT_PEER_INTEL && (((pstat->tx_avarage+pstat->rx_avarage)>>10) < |
| 3285 | priv->pshare->rf_ft_var.cwmax_enhance_thd)) |
| 3286 | |
| 3287 | { |
| 3288 | if (!priv->pshare->BE_cwmax_enhance && priv->pshare->iot_mode_enable) { |
| 3289 | priv->pshare->BE_cwmax_enhance = 1; |
| 3290 | switch_turbo++; |
| 3291 | } |
| 3292 | } else { |
| 3293 | if (priv->pshare->BE_cwmax_enhance) { |
| 3294 | priv->pshare->BE_cwmax_enhance = 0; |
| 3295 | switch_turbo++; |
| 3296 | } |
| 3297 | } |
| 3298 | #endif |
| 3299 | } |
| 3300 | #endif |
| 3301 | |
| 3302 | priv->pshare->current_tx_bytes = 0; |
| 3303 | priv->pshare->current_rx_bytes = 0; |
| 3304 | } |
| 3305 | |
| 3306 | #ifdef SW_TX_QUEUE |
| 3307 | if (GET_HCI_TYPE(priv) == RTL_HCI_PCIE) { |
| 3308 | if ((assoc_num > 1) && (AMPDU_ENABLE)) |
| 3309 | { |
| 3310 | unsigned int total_tp = (unsigned int)(priv->ext_stats.tx_avarage>>17)+(unsigned int)(priv->ext_stats.rx_avarage>>17); |
| 3311 | if(total_tp > 0) { |
| 3312 | if (((unsigned int)(priv->ext_stats.tx_avarage>>17) * 100/total_tp) > 30) |
| 3313 | { |
| 3314 | if (priv->pshare->swq_txmac_chg >= priv->pshare->rf_ft_var.swq_en_highthd) |
| 3315 | { |
| 3316 | if ((priv->pshare->swq_en == 0)) |
| 3317 | { |
| 3318 | switch_turbo++; |
| 3319 | if (priv->pshare->txop_enlarge == 0) |
| 3320 | priv->pshare->txop_enlarge = 2; |
| 3321 | priv->pshare->swq_en = 1; |
| 3322 | priv->pshare->swqen_keeptime = priv->up_time; |
| 3323 | } |
| 3324 | else |
| 3325 | { |
| 3326 | if ((switch_turbo > 0) && (priv->pshare->txop_enlarge == 0) && (priv->pshare->iot_mode_enable != 0)) |
| 3327 | { |
| 3328 | priv->pshare->txop_enlarge = 2; |
| 3329 | switch_turbo--; |
| 3330 | } |
| 3331 | } |
| 3332 | } |
| 3333 | else if(priv->pshare->swq_txmac_chg <= priv->pshare->rf_ft_var.swq_dis_lowthd) |
| 3334 | { |
| 3335 | priv->pshare->swq_en = 0; |
| 3336 | priv->pshare->swqen_keeptime = 0; |
| 3337 | } |
| 3338 | else if ((priv->pshare->swq_en == 1) && (switch_turbo > 0) && (priv->pshare->txop_enlarge == 0) && (priv->pshare->iot_mode_enable != 0)) |
| 3339 | { |
| 3340 | priv->pshare->txop_enlarge = 2; |
| 3341 | switch_turbo--; |
| 3342 | } |
| 3343 | } |
| 3344 | else if (((unsigned int)(priv->ext_stats.tx_avarage>>17) * 100/total_tp) < 20) |
| 3345 | { |
| 3346 | priv->pshare->swq_en = 0; |
| 3347 | priv->pshare->swqen_keeptime = 0; |
| 3348 | } |
| 3349 | } |
| 3350 | //debug msg |
| 3351 | //printk("swq=%d,sw=%d,en=%d,mode=%d\n", priv->pshare->swq_en, switch_turbo, priv->pshare->txop_enlarge, priv->pshare->iot_mode_enable); |
| 3352 | } |
| 3353 | #if 1//defined(CONFIG_RTL_819XD) |
| 3354 | else if( (assoc_num == 1) && (priv->up_time % 2)== 0 && (AMPDU_ENABLE) ) { |
| 3355 | //if (pstat) { |
| 3356 | // if ((pstat) && pstat->is_intel_sta) { |
| 3357 | if ((pstat) && pstat->IOTPeer == HT_IOT_PEER_INTEL) { |
| 3358 | // int en_thd = 14417920; |
| 3359 | //if ((priv->pshare->swq_en == 0) && (pstat->current_tx_bytes > en_thd) && (pstat->current_rx_bytes > en_thd) ) { //50Mbps |
| 3360 | if ((pstat->current_tx_bytes > 14417920) && (priv->pshare->swq_en == 0)) { // && (pstat->current_rx_bytes > 14417920) && (priv->pshare->swq_en == 0)) { //55Mbps |
| 3361 | priv->pshare->swq_en = 1; |
| 3362 | priv->pshare->swqen_keeptime = priv->up_time; |
| 3363 | } |
| 3364 | //else if ((priv->pshare->swq_en == 1) && ((pstat->tx_avarage < 4587520) || (pstat->rx_avarage < 4587520))) { //35Mbps |
| 3365 | else if ((pstat->tx_avarage < 9175040) && (priv->pshare->swq_en == 1)) { //35Mbps |
| 3366 | priv->pshare->swq_en = 0; |
| 3367 | priv->pshare->swqen_keeptime = 0; |
| 3368 | } |
| 3369 | } |
| 3370 | else { |
| 3371 | priv->pshare->swq_en = 0; |
| 3372 | priv->pshare->swqen_keeptime = 0; |
| 3373 | } |
| 3374 | } |
| 3375 | #endif |
| 3376 | } |
| 3377 | #endif |
| 3378 | |
| 3379 | #ifdef WIFI_WMM |
| 3380 | #ifdef LOW_TP_TXOP |
| 3381 | if ((!priv->pmib->dot11OperationEntry.wifi_specific || (priv->pmib->dot11OperationEntry.wifi_specific == 2)) |
| 3382 | && QOS_ENABLE) { |
| 3383 | |
| 3384 | if (switch_turbo || priv->pshare->rf_ft_var.low_tp_txop) { |
| 3385 | unsigned int thd_tp; |
| 3386 | unsigned char under_thd; |
| 3387 | unsigned int curr_tp; |
| 3388 | |
| 3389 | if (priv->pmib->dot11BssType.net_work_type & (WIRELESS_11N | WIRELESS_11G)) |
| 3390 | { |
| 3391 | struct rtl8192cd_priv *tmppriv; |
| 3392 | // Determine the upper bound throughput threshold. |
| 3393 | if (priv->pmib->dot11BssType.net_work_type & WIRELESS_11N) { |
| 3394 | if (priv->assoc_num && priv->assoc_num != priv->pshare->ht_sta_num) |
| 3395 | thd_tp = priv->pshare->rf_ft_var.low_tp_txop_thd_g; |
| 3396 | else |
| 3397 | thd_tp = priv->pshare->rf_ft_var.low_tp_txop_thd_n; |
| 3398 | } |
| 3399 | else |
| 3400 | thd_tp = priv->pshare->rf_ft_var.low_tp_txop_thd_g; |
| 3401 | |
| 3402 | // Determine to close txop. |
| 3403 | curr_tp = (unsigned int)(priv->ext_stats.tx_avarage>>17) + (unsigned int)(priv->ext_stats.rx_avarage>>17); |
| 3404 | #ifdef MBSSID |
| 3405 | if (GET_ROOT(priv)->pmib->miscEntry.vap_enable) { |
| 3406 | for (i=0; i<RTL8192CD_NUM_VWLAN; ++i) { |
| 3407 | tmppriv = GET_ROOT(priv)->pvap_priv[i]; |
| 3408 | if (IS_DRV_OPEN(tmppriv)) |
| 3409 | curr_tp += (unsigned int)(tmppriv->ext_stats.tx_avarage>>17) + (unsigned int)(tmppriv->ext_stats.rx_avarage>>17); |
| 3410 | } |
| 3411 | } |
| 3412 | #endif |
| 3413 | #ifdef UNIVERSAL_REPEATER |
| 3414 | tmppriv = GET_VXD_PRIV(GET_ROOT(priv)); |
| 3415 | if (IS_DRV_OPEN(tmppriv)) |
| 3416 | curr_tp += (unsigned int)(tmppriv->ext_stats.tx_avarage>>17) + (unsigned int)(tmppriv->ext_stats.rx_avarage>>17); |
| 3417 | #endif |
| 3418 | if (curr_tp <= thd_tp && curr_tp >= priv->pshare->rf_ft_var.low_tp_txop_thd_low) |
| 3419 | under_thd = 1; |
| 3420 | else |
| 3421 | under_thd = 0; |
| 3422 | } |
| 3423 | else |
| 3424 | { |
| 3425 | under_thd = 0; |
| 3426 | } |
| 3427 | |
| 3428 | if (switch_turbo) { |
| 3429 | priv->pshare->rf_ft_var.low_tp_txop_close = under_thd; |
| 3430 | priv->pshare->rf_ft_var.low_tp_txop_count = 0; |
| 3431 | } else if (priv->pshare->iot_mode_enable && (priv->pshare->rf_ft_var.low_tp_txop_close != under_thd)) { |
| 3432 | priv->pshare->rf_ft_var.low_tp_txop_count++; |
| 3433 | if (priv->pshare->rf_ft_var.low_tp_txop_close || |
| 3434 | (priv->pshare->rf_ft_var.low_tp_txop_count ==priv->pshare->rf_ft_var.low_tp_txop_delay)) { |
| 3435 | priv->pshare->rf_ft_var.low_tp_txop_count = 0; |
| 3436 | priv->pshare->rf_ft_var.low_tp_txop_close = under_thd; |
| 3437 | switch_turbo++; |
| 3438 | } |
| 3439 | } else { |
| 3440 | priv->pshare->rf_ft_var.low_tp_txop_count = 0; |
| 3441 | } |
| 3442 | } |
| 3443 | } |
| 3444 | #endif |
| 3445 | |
| 3446 | if (switch_turbo) |
| 3447 | IOT_EDCA_switch(priv, priv->pmib->dot11BssType.net_work_type, priv->pshare->iot_mode_enable); |
| 3448 | #endif |
| 3449 | } |
| 3450 | |
| 3451 | |
| 3452 | #ifdef WIFI_WMM |
| 3453 | void IOT_EDCA_switch(struct rtl8192cd_priv *priv, int mode, char enable) |
| 3454 | { |
| 3455 | unsigned int slot_time = 20, sifs_time = 10, BE_TXOP = 47, VI_TXOP = 94; |
| 3456 | unsigned int vi_cw_max = 4, vi_cw_min = 3, vi_aifs; |
| 3457 | |
| 3458 | if (!(!priv->pmib->dot11OperationEntry.wifi_specific || |
| 3459 | ((OPMODE & WIFI_AP_STATE) && (priv->pmib->dot11OperationEntry.wifi_specific)) |
| 3460 | #ifdef CLIENT_MODE |
| 3461 | || ((OPMODE & WIFI_STATION_STATE) && (priv->pmib->dot11OperationEntry.wifi_specific)) |
| 3462 | #endif |
| 3463 | )) |
| 3464 | return; |
| 3465 | |
| 3466 | if ((mode & WIRELESS_11N) && (priv->pshare->ht_sta_num |
| 3467 | #ifdef WDS |
| 3468 | || ((OPMODE & WIFI_AP_STATE) && priv->pmib->dot11WdsInfo.wdsEnabled && priv->pmib->dot11WdsInfo.wdsNum) |
| 3469 | #endif |
| 3470 | )) |
| 3471 | sifs_time = 16; |
| 3472 | |
| 3473 | if (mode & (WIRELESS_11G | WIRELESS_11N)) { |
| 3474 | slot_time = 9; |
| 3475 | } else { |
| 3476 | BE_TXOP = 94; |
| 3477 | VI_TXOP = 188; |
| 3478 | } |
| 3479 | |
| 3480 | #if 0 //defined(CONFIG_RTL_8196D) || defined(CONFIG_RTL_8196E) || (defined(CONFIG_RTL_8197D) && !defined(CONFIG_PORT0_EXT_GIGA)) |
| 3481 | if (priv->pshare->is_40m_bw) |
| 3482 | { |
| 3483 | BE_TXOP = 23; |
| 3484 | } |
| 3485 | #endif |
| 3486 | |
| 3487 | if ((OPMODE & WIFI_AP_STATE) && priv->pmib->dot11OperationEntry.wifi_specific) { |
| 3488 | if (priv->pshare->iot_mode_VO_exist) { |
| 3489 | #ifdef WMM_VIBE_PRI |
| 3490 | if (priv->pshare->iot_mode_BE_exist) { |
| 3491 | vi_cw_max = 5; |
| 3492 | vi_cw_min = 3; |
| 3493 | vi_aifs = (sifs_time + ((OPMODE & WIFI_AP_STATE)?1:2) * slot_time); |
| 3494 | } else |
| 3495 | #endif |
| 3496 | { |
| 3497 | vi_cw_max = 6; |
| 3498 | vi_cw_min = 4; |
| 3499 | vi_aifs = 0x2b; |
| 3500 | } |
| 3501 | } else { |
| 3502 | vi_aifs = (sifs_time + ((OPMODE & WIFI_AP_STATE)?1:2) * slot_time); |
| 3503 | } |
| 3504 | |
| 3505 | RTL_W32(EDCA_VI_PARA, ((VI_TXOP*(1-priv->pshare->iot_mode_VO_exist)) << 16) |
| 3506 | | (vi_cw_max << 12) | (vi_cw_min << 8) | vi_aifs); |
| 3507 | |
| 3508 | #ifdef WMM_BEBK_PRI |
| 3509 | #ifdef CONFIG_RTL_88E_SUPPORT |
| 3510 | if ((GET_CHIP_VER(priv) == VERSION_8188E ) && priv->pshare->iot_mode_BK_exist) { |
| 3511 | RTL_W32(EDCA_BK_PARA, (10 << 12) | (6 << 8) | 0x4f); |
| 3512 | } |
| 3513 | #endif |
| 3514 | #endif |
| 3515 | } |
| 3516 | |
| 3517 | if (!enable || (priv->pshare->rf_ft_var.wifi_beq_iot && priv->pshare->iot_mode_VI_exist)) { |
| 3518 | if (priv->pshare->rf_ft_var.wifi_beq_iot && priv->pshare->iot_mode_VI_exist) { |
| 3519 | #ifdef CONFIG_RTL_92D_DMDP |
| 3520 | if ((GET_CHIP_VER(priv) == VERSION_8192D) && (priv->pmib->dot11RFEntry.macPhyMode == DUALMAC_DUALPHY)) { |
| 3521 | if (priv->pshare->wifi_beq_lower) |
| 3522 | RTL_W32(EDCA_BE_PARA, (10 << 12) | (4 << 8) | (sifs_time + 10 * slot_time)); |
| 3523 | else |
| 3524 | RTL_W32(EDCA_BE_PARA, (6 << 12) | (4 << 8) | (sifs_time + 3 * slot_time)); |
| 3525 | } else |
| 3526 | #endif |
| 3527 | RTL_W32(EDCA_BE_PARA, (10 << 12) | (4 << 8) | 0x4f); |
| 3528 | } else { |
| 3529 | RTL_W32(EDCA_BE_PARA, (((OPMODE & WIFI_AP_STATE)?6:10) << 12) | (4 << 8) |
| 3530 | | (sifs_time + 3 * slot_time)); |
| 3531 | } |
| 3532 | RTL_W16(RD_CTRL, RTL_R16(RD_CTRL) | DIS_TXOP_CFE); |
| 3533 | } else { |
| 3534 | #ifdef LOW_TP_TXOP |
| 3535 | int txop; |
| 3536 | unsigned int cw_max; |
| 3537 | unsigned int txop_close; |
| 3538 | |
| 3539 | cw_max = ((priv->pshare->BE_cwmax_enhance) ? 10 : 6); |
| 3540 | txop_close = ((priv->pshare->rf_ft_var.low_tp_txop && priv->pshare->rf_ft_var.low_tp_txop_close) ? 1 : 0); |
| 3541 | txop = (txop_close ? 0 : (BE_TXOP*2)); |
| 3542 | #endif |
| 3543 | if (priv->pshare->ht_sta_num |
| 3544 | #ifdef WDS |
| 3545 | || ((OPMODE & WIFI_AP_STATE) && (mode & WIRELESS_11N) && |
| 3546 | priv->pmib->dot11WdsInfo.wdsEnabled && priv->pmib->dot11WdsInfo.wdsNum) |
| 3547 | #endif |
| 3548 | ) { |
| 3549 | /* |
| 3550 | if (priv->pshare->txop_enlarge == 0xf) { |
| 3551 | // is 8192S client |
| 3552 | RTL_W32(EDCA_BE_PARA, ((BE_TXOP*2) << 16) | |
| 3553 | (6 << 12) | (4 << 8) | (sifs_time + slot_time+ 0xf)); // 0xf is 92s circuit delay |
| 3554 | priv->pshare->txop_enlarge = 2; |
| 3555 | } |
| 3556 | else |
| 3557 | */ |
| 3558 | if (priv->pshare->txop_enlarge == 0xe) { |
| 3559 | #ifndef LOW_TP_TXOP |
| 3560 | // is intel client, use a different edca value |
| 3561 | #if 0 //defined(CONFIG_RTL_8196D) || defined(CONFIG_RTL_8196E) || (defined(CONFIG_RTL_8197D) && !defined(CONFIG_PORT0_EXT_GIGA)) |
| 3562 | RTL_W32(EDCA_BE_PARA, (BE_TXOP*2 << 16) | (6 << 12) | (5 << 8) | 0x1f); |
| 3563 | #else |
| 3564 | //RTL_W32(EDCA_BE_PARA, (BE_TXOP*2 << 16) | (6 << 12) | (4 << 8) | 0x1f); |
| 3565 | if (get_rf_mimo_mode(priv) == RF_1T1R) |
| 3566 | RTL_W32(EDCA_BE_PARA, (BE_TXOP*2 << 16) | (6 << 12) | (5 << 8) | 0x1f); |
| 3567 | else |
| 3568 | RTL_W32(EDCA_BE_PARA, (BE_TXOP*2 << 16) | (8 << 12) | (5 << 8) | 0x1f); |
| 3569 | |
| 3570 | RTL_W16(RD_CTRL, RTL_R16(RD_CTRL) & ~(DIS_TXOP_CFE)); |
| 3571 | #endif |
| 3572 | priv->pshare->txop_enlarge = 2; |
| 3573 | } else if (priv->pshare->txop_enlarge == 0xd) { |
| 3574 | // is intel ralink, use a different edca value |
| 3575 | RTL_W32(EDCA_BE_PARA, (BE_TXOP*2 << 16) | (4 << 12) | (3 << 8) | 0x19); |
| 3576 | priv->pshare->txop_enlarge = 2; |
| 3577 | } else { |
| 3578 | if (priv->pshare->txop_enlarge == 0) |
| 3579 | RTL_W16(RD_CTRL, RTL_R16(RD_CTRL) | DIS_TXOP_CFE); |
| 3580 | |
| 3581 | if (get_rf_mimo_mode(priv) == RF_2T2R) |
| 3582 | #if 0 //defined(CONFIG_RTL_8196D) || defined(CONFIG_RTL_8196E) || (defined(CONFIG_RTL_8197D) && !defined(CONFIG_PORT0_EXT_GIGA)) |
| 3583 | RTL_W32(EDCA_BE_PARA, ((BE_TXOP*priv->pshare->txop_enlarge) << 16) | |
| 3584 | (6 << 12) | (5 << 8) | (sifs_time + 3 * slot_time)); |
| 3585 | #else |
| 3586 | RTL_W32(EDCA_BE_PARA, ((BE_TXOP*priv->pshare->txop_enlarge) << 16) | |
| 3587 | (6 << 12) | (4 << 8) | (sifs_time + 3 * slot_time)); |
| 3588 | #endif |
| 3589 | else |
| 3590 | #if 0 //defined(CONFIG_RTL_8196D) || defined(CONFIG_RTL_8196E) || (defined(CONFIG_RTL_8197D) && !defined(CONFIG_PORT0_EXT_GIGA)) |
| 3591 | RTL_W32(EDCA_BE_PARA, ((BE_TXOP*priv->pshare->txop_enlarge) << 16) | |
| 3592 | (5 << 12) | (4 << 8) | (sifs_time + 2 * slot_time)); |
| 3593 | #else |
| 3594 | RTL_W32(EDCA_BE_PARA, ((BE_TXOP*priv->pshare->txop_enlarge) << 16) | |
| 3595 | (5 << 12) | (3 << 8) | (sifs_time + 2 * slot_time)); |
| 3596 | #endif |
| 3597 | |
| 3598 | #else |
| 3599 | // is intel client, use a different edca value |
| 3600 | if (get_rf_mimo_mode(priv) == RF_1T1R) |
| 3601 | RTL_W32(EDCA_BE_PARA, (BE_TXOP*2 << 16) | (6 << 12) | (5 << 8) | 0x1f); |
| 3602 | else |
| 3603 | RTL_W32(EDCA_BE_PARA, (txop << 16) | (cw_max << 12) | (4 << 8) | 0x1f); |
| 3604 | } else { |
| 3605 | txop = (txop_close ? 0: (BE_TXOP*priv->pshare->txop_enlarge)); |
| 3606 | |
| 3607 | if (get_rf_mimo_mode(priv) == RF_2T2R) |
| 3608 | RTL_W32(EDCA_BE_PARA, (txop << 16) | (cw_max << 12) | (4 << 8) | (sifs_time + 3 * slot_time)); |
| 3609 | else |
| 3610 | RTL_W32(EDCA_BE_PARA, (txop << 16) | (((priv->pshare->BE_cwmax_enhance) ? 10 : 5) << 12) | |
| 3611 | (3 << 8) | (sifs_time + 2 * slot_time)); |
| 3612 | #endif |
| 3613 | } |
| 3614 | } else { |
| 3615 | #ifdef LOW_TP_TXOP |
| 3616 | RTL_W32(EDCA_BE_PARA, (txop << 16) | (cw_max << 12) | (4 << 8) | (sifs_time + 3 * slot_time)); |
| 3617 | #else |
| 3618 | #if defined(CONFIG_RTL_8196D) || defined(CONFIG_RTL_8197DL) || defined(CONFIG_RTL_8196E) || (defined(CONFIG_RTL_8197D) && !defined(CONFIG_PORT0_EXT_GIGA)) |
| 3619 | RTL_W32(EDCA_BE_PARA, (BE_TXOP*2 << 16) | (6 << 12) | (5 << 8) | (sifs_time + 3 * slot_time)); |
| 3620 | #else |
| 3621 | RTL_W32(EDCA_BE_PARA, (BE_TXOP*2 << 16) | (6 << 12) | (4 << 8) | (sifs_time + 3 * slot_time)); |
| 3622 | #endif |
| 3623 | if (priv->pshare->txop_enlarge == 0xe) |
| 3624 | RTL_W16(RD_CTRL, RTL_R16(RD_CTRL) & ~(DIS_TXOP_CFE)); |
| 3625 | else |
| 3626 | RTL_W16(RD_CTRL, RTL_R16(RD_CTRL) | DIS_TXOP_CFE); |
| 3627 | #endif |
| 3628 | } |
| 3629 | /* |
| 3630 | if (priv->pmib->dot11OperationEntry.wifi_specific == 2) { |
| 3631 | RTL_W16(NAV_PROT_LEN, 0x01C0); |
| 3632 | RTL_W8(CFEND_TH, 0xFF); |
| 3633 | set_fw_reg(priv, 0xfd000ab0, 0, 0); |
| 3634 | } |
| 3635 | */ |
| 3636 | } |
| 3637 | } |
| 3638 | |
| 3639 | //end of IOT_EDCA_switch |
| 3640 | //======================================================================================================== |
| 3641 | |
| 3642 | #if 0 |
| 3643 | void check_NAV_prot_len(struct rtl8192cd_priv *priv, struct stat_info *pstat, unsigned int disassoc) |
| 3644 | { |
| 3645 | if ((priv->pmib->dot11BssType.net_work_type & WIRELESS_11N) && pstat |
| 3646 | && pstat->ht_cap_len && pstat->is_intel_sta) { |
| 3647 | if (!disassoc && (pstat->MIMO_ps & _HT_MIMO_PS_DYNAMIC_)) { |
| 3648 | setSTABitMap(&priv->pshare->mimo_ps_dynamic_sta, pstat->cmn_info.aid); |
| 3649 | } else { |
| 3650 | clearSTABitMap(&priv->pshare->mimo_ps_dynamic_sta, pstat->cmn_info.aid); |
| 3651 | } |
| 3652 | |
| 3653 | #ifdef CONFIG_RTL_88E_SUPPORT |
| 3654 | if (GET_CHIP_VER(priv) != VERSION_8188E) |
| 3655 | #endif |
| 3656 | { |
| 3657 | if (orSTABitMap(&priv->pshare->mimo_ps_dynamic_sta) { |
| 3658 | RTL_W8(NAV_PROT_LEN, 0x40); |
| 3659 | } else { |
| 3660 | RTL_W8(NAV_PROT_LEN, 0x20); |
| 3661 | } |
| 3662 | } |
| 3663 | } |
| 3664 | } |
| 3665 | #endif |
| 3666 | #endif |
| 3667 | |
| 3668 | |
| 3669 | //3 ============================================================ |
| 3670 | //3 FA statistic functions |
| 3671 | //3 ============================================================ |
| 3672 | #if 0 |
| 3673 | |
| 3674 | #if !defined(CONFIG_RTL_NEW_AUTOCH) |
| 3675 | static |
| 3676 | #endif |
| 3677 | void reset_FA_reg(struct rtl8192cd_priv *priv) |
| 3678 | { |
| 3679 | #if !defined(CONFIG_RTL_NEW_AUTOCH) |
| 3680 | unsigned char value8; |
| 3681 | |
| 3682 | value8 = RTL_R8(0xd03); |
| 3683 | RTL_W8(0xd03, value8 | 0x08); // regD00[27]=1 to reset these OFDM FA counters |
| 3684 | value8 = RTL_R8(0xd03); |
| 3685 | RTL_W8(0xd03, value8 & 0xF7); // regD00[27]=0 to start counting |
| 3686 | value8 = RTL_R8(0xa2d); |
| 3687 | RTL_W8(0xa2d, value8 & 0x3F); // regA2D[7:6]=00 to disable counting |
| 3688 | value8 = RTL_R8(0xa2d); |
| 3689 | RTL_W8(0xa2d, value8 | 0x80); // regA2D[7:6]=10 to enable counting |
| 3690 | #else |
| 3691 | /* cck CCA */ |
| 3692 | phy_set_bb_reg(priv, 0xa2c, BIT(13) | BIT(12), 0); |
| 3693 | phy_set_bb_reg(priv, 0xa2c, BIT(13) | BIT(12), 2); |
| 3694 | /* cck FA*/ |
| 3695 | phy_set_bb_reg(priv, 0xa2c, BIT(15) | BIT(14), 0); |
| 3696 | phy_set_bb_reg(priv, 0xa2c, BIT(15) | BIT(14), 2); |
| 3697 | /* ofdm */ |
| 3698 | phy_set_bb_reg(priv, 0xd00, BIT(27), 1); |
| 3699 | phy_set_bb_reg(priv, 0xd00, BIT(27), 0); |
| 3700 | #endif |
| 3701 | |
| 3702 | #if defined(CONFIG_RTL_92D_SUPPORT) && defined(CONFIG_RTL_NOISE_CONTROL) |
| 3703 | if (GET_CHIP_VER(priv) == VERSION_8192D){ |
| 3704 | phy_set_bb_reg(priv, 0xf14, BIT(16),1); |
| 3705 | phy_set_bb_reg(priv, 0xf14, BIT(16),0); |
| 3706 | RTL_W32(RXERR_RPT, RTL_R32(RXERR_RPT)|BIT(27)); |
| 3707 | RTL_W32(RXERR_RPT, RTL_R32(RXERR_RPT)&(~BIT(27))); |
| 3708 | } |
| 3709 | #endif |
| 3710 | |
| 3711 | #ifdef CONFIG_RTL_88E_SUPPORT |
| 3712 | if (GET_CHIP_VER(priv)==VERSION_8188E) { |
| 3713 | phy_set_bb_reg(priv, 0xc0c, BIT(31), 1); |
| 3714 | phy_set_bb_reg(priv, 0xc0c, BIT(31), 0); |
| 3715 | } |
| 3716 | #endif |
| 3717 | } |
| 3718 | |
| 3719 | #if defined(CONFIG_RTL_NEW_AUTOCH) |
| 3720 | void hold_CCA_FA_counter(struct rtl8192cd_priv *priv) |
| 3721 | { |
| 3722 | /* hold cck CCA & FA counter */ |
| 3723 | phy_set_bb_reg(priv, 0xa2c, BIT(12), 1); |
| 3724 | phy_set_bb_reg(priv, 0xa2c, BIT(14), 1); |
| 3725 | |
| 3726 | /* hold ofdm CCA & FA counter */ |
| 3727 | phy_set_bb_reg(priv, 0xc00, BIT(31), 1); |
| 3728 | phy_set_bb_reg(priv, 0xd00, BIT(31), 1); |
| 3729 | } |
| 3730 | |
| 3731 | void release_CCA_FA_counter(struct rtl8192cd_priv *priv) |
| 3732 | { |
| 3733 | /* release cck CCA & FA counter */ |
| 3734 | phy_set_bb_reg(priv, 0xa2c, BIT(12), 0); |
| 3735 | phy_set_bb_reg(priv, 0xa2c, BIT(14), 0); |
| 3736 | |
| 3737 | /* release ofdm CCA & FA counter */ |
| 3738 | phy_set_bb_reg(priv, 0xc00, BIT(31), 0); |
| 3739 | phy_set_bb_reg(priv, 0xd00, BIT(31), 0); |
| 3740 | |
| 3741 | #ifdef CONFIG_RTL_88E_SUPPORT |
| 3742 | if (GET_CHIP_VER(priv)==VERSION_8188E) { |
| 3743 | phy_set_bb_reg(priv, 0xc0c, BIT(31), 1); |
| 3744 | phy_set_bb_reg(priv, 0xc0c, BIT(31), 0); |
| 3745 | } |
| 3746 | #endif |
| 3747 | } |
| 3748 | |
| 3749 | |
| 3750 | void _FA_statistic(struct rtl8192cd_priv *priv) |
| 3751 | { |
| 3752 | // read OFDM FA counters |
| 3753 | priv->pshare->ofdm_FA_cnt1 = RTL_R16(0xda2); |
| 3754 | priv->pshare->ofdm_FA_cnt2 = RTL_R16(0xda4); |
| 3755 | priv->pshare->ofdm_FA_cnt3 = RTL_R16(0xda6); |
| 3756 | priv->pshare->ofdm_FA_cnt4 = RTL_R16(0xda8); |
| 3757 | |
| 3758 | priv->pshare->cck_FA_cnt = (RTL_R8(0xa5b) << 8) + RTL_R8(0xa5c); |
| 3759 | |
| 3760 | #ifdef INTERFERENCE_CONTROL |
| 3761 | priv->pshare->ofdm_FA_total_cnt = (unsigned int) priv->pshare->ofdm_FA_cnt1 + |
| 3762 | priv->pshare->ofdm_FA_cnt2 + priv->pshare->ofdm_FA_cnt3 + |
| 3763 | priv->pshare->ofdm_FA_cnt4 + RTL_R16(0xcf0) + RTL_R16(0xcf2); |
| 3764 | |
| 3765 | priv->pshare->FA_total_cnt = priv->pshare->ofdm_FA_total_cnt + priv->pshare->cck_FA_cnt; |
| 3766 | #else |
| 3767 | priv->pshare->FA_total_cnt = priv->pshare->ofdm_FA_cnt1 + priv->pshare->ofdm_FA_cnt2 + |
| 3768 | priv->pshare->ofdm_FA_cnt3 + priv->pshare->ofdm_FA_cnt4 + |
| 3769 | priv->pshare->cck_FA_cnt + RTL_R16(0xcf0) + RTL_R16(0xcf2); |
| 3770 | #endif |
| 3771 | } |
| 3772 | #endif |
| 3773 | |
| 3774 | void FA_statistic(struct rtl8192cd_priv *priv) |
| 3775 | { |
| 3776 | |
| 3777 | #if defined(CONFIG_RTL_92D_SUPPORT) && defined(CONFIG_RTL_NOISE_CONTROL) |
| 3778 | if (GET_CHIP_VER(priv) == VERSION_8192D){ |
| 3779 | // priv->pshare->F90_cnt = phy_query_bb_reg(priv, 0xf90, bMaskHWord); |
| 3780 | priv->pshare->F94_cnt = phy_query_bb_reg(priv, 0xf94, bMaskHWord); |
| 3781 | priv->pshare->F94_cntOK = phy_query_bb_reg(priv, 0xf94, bMaskLWord); |
| 3782 | RTL_W32(RXERR_RPT,(RTL_R32(RXERR_RPT)&0x0fffffff)|0x70000000); |
| 3783 | priv->pshare->Reg664_cnt = RTL_R32(RXERR_RPT) & 0xfffff; |
| 3784 | RTL_W32(RXERR_RPT,(RTL_R32(RXERR_RPT)&0x0fffffff)|0x60000000); |
| 3785 | priv->pshare->Reg664_cntOK = RTL_R32(RXERR_RPT) & 0xfffff; |
| 3786 | } |
| 3787 | #endif |
| 3788 | |
| 3789 | #if !defined(CONFIG_RTL_NEW_AUTOCH) |
| 3790 | signed char value8; |
| 3791 | |
| 3792 | // read OFDM FA counters |
| 3793 | priv->pshare->ofdm_FA_cnt1 = RTL_R16(0xda2); |
| 3794 | priv->pshare->ofdm_FA_cnt2 = RTL_R16(0xda4); |
| 3795 | priv->pshare->ofdm_FA_cnt3 = RTL_R16(0xda6); |
| 3796 | priv->pshare->ofdm_FA_cnt4 = RTL_R16(0xda8); |
| 3797 | |
| 3798 | // read the CCK FA counters |
| 3799 | value8 = RTL_R8(0xa2d); |
| 3800 | RTL_W8(0xa2d, value8 | 0x40); // regA2D[6]=1 to hold and read the CCK FA counters |
| 3801 | priv->pshare->cck_FA_cnt = RTL_R8(0xa5b); |
| 3802 | priv->pshare->cck_FA_cnt = priv->pshare->cck_FA_cnt << 8; |
| 3803 | priv->pshare->cck_FA_cnt += RTL_R8(0xa5c); |
| 3804 | #ifdef INTERFERENCE_CONTROL |
| 3805 | priv->pshare->ofdm_FA_total_cnt = (unsigned int) priv->pshare->ofdm_FA_cnt1 + |
| 3806 | priv->pshare->ofdm_FA_cnt2 + priv->pshare->ofdm_FA_cnt3 + |
| 3807 | priv->pshare->ofdm_FA_cnt4 + RTL_R16(0xcf0) + RTL_R16(0xcf2); |
| 3808 | |
| 3809 | priv->pshare->FA_total_cnt = priv->pshare->ofdm_FA_total_cnt + priv->pshare->cck_FA_cnt; |
| 3810 | #else |
| 3811 | |
| 3812 | priv->pshare->FA_total_cnt = priv->pshare->ofdm_FA_cnt1 + priv->pshare->ofdm_FA_cnt2 + |
| 3813 | priv->pshare->ofdm_FA_cnt3 + priv->pshare->ofdm_FA_cnt4 + |
| 3814 | priv->pshare->cck_FA_cnt + RTL_R16(0xcf0) + RTL_R16(0xcf2); |
| 3815 | #endif |
| 3816 | if (priv->pshare->rf_ft_var.rssi_dump) |
| 3817 | priv->pshare->CCA_total_cnt = ((RTL_R8(0xa60)<<8)|RTL_R8(0xa61)) + RTL_R16(0xda0); |
| 3818 | #else |
| 3819 | hold_CCA_FA_counter(priv); |
| 3820 | _FA_statistic(priv); |
| 3821 | |
| 3822 | if (priv->pshare->rf_ft_var.rssi_dump) |
| 3823 | priv->pshare->CCA_total_cnt = ((RTL_R8(0xa60)<<8)|RTL_R8(0xa61)) + RTL_R16(0xda0); |
| 3824 | |
| 3825 | release_CCA_FA_counter(priv); |
| 3826 | #endif |
| 3827 | |
| 3828 | reset_FA_reg(priv); |
| 3829 | |
| 3830 | #if defined(CONFIG_RTL_92D_SUPPORT) && defined(CONFIG_RTL_NOISE_CONTROL) |
| 3831 | if (GET_CHIP_VER(priv) == VERSION_8192D){ |
| 3832 | if (priv->pmib->dot11RFEntry.phyBandSelect == PHY_BAND_5G && !(OPMODE & WIFI_SITE_MONITOR)) { |
| 3833 | if (priv->pshare->DNC_on == 0){ |
| 3834 | //if ((priv->pshare->F94_cnt + priv->pshare->F90_cnt)> 3000){ |
| 3835 | /* Reg 664: x > y && x > 1000 |
| 3836 | Reg F94: x > 0.75*y && x > 1000 */ |
| 3837 | if (((priv->pshare->Reg664_cnt>priv->pshare->Reg664_cntOK) && (priv->pshare->Reg664_cnt > 1000))|| |
| 3838 | ((priv->pshare->F94_cnt > ((priv->pshare->Reg664_cntOK*3)>>2)) && (priv->pshare->F94_cnt > 1000))) { |
| 3839 | priv->ext_stats.tp_average_pre = (priv->ext_stats.tx_avarage+priv->ext_stats.rx_avarage)>>17; |
| 3840 | priv->pshare->DNC_on = 1; |
| 3841 | priv->pshare->DNC_chk_cnt = 1; |
| 3842 | priv->pshare->DNC_chk = 2; // 0: don't check, 1; check, 2: just entering DNC |
| 3843 | //phy_set_bb_reg(priv, 0xb30, bMaskDWord, 0x00a00000); |
| 3844 | phy_set_bb_reg(priv, 0x870, bMaskDWord, 0x07600760); |
| 3845 | phy_set_bb_reg(priv, 0xc50, bMaskByte0, 0x20); |
| 3846 | phy_set_bb_reg(priv, 0xc58, bMaskByte0, 0x20); |
| 3847 | //printk("Dynamic Noise Control ON\n"); |
| 3848 | } |
| 3849 | } else { |
| 3850 | if ((priv->pshare->DNC_chk_cnt % 5)==0){ // check every 5*2=10 seconds |
| 3851 | unsigned long tp_now = (priv->ext_stats.tx_avarage+priv->ext_stats.rx_avarage)>>17; |
| 3852 | priv->pshare->DNC_chk_cnt = 0; |
| 3853 | |
| 3854 | if ((priv->pshare->DNC_chk == 2) && (tp_now < priv->ext_stats.tp_average_pre+5)){ |
| 3855 | //no advantage, leave DNC state |
| 3856 | priv->pshare->DNC_on = 0; |
| 3857 | priv->pshare->DNC_chk = 0; |
| 3858 | //phy_set_bb_reg(priv, 0xb30, bMaskDWord, 0); |
| 3859 | phy_set_bb_reg(priv, 0x870, bMaskDWord, 0x07000700); |
| 3860 | } |
| 3861 | else |
| 3862 | { |
| 3863 | priv->pshare->DNC_chk = 0; |
| 3864 | |
| 3865 | /* If TP < 20M or TP varies more than 5M. Start Checking...*/ |
| 3866 | if ((tp_now < 20) || ((tp_now < (priv->ext_stats.tp_average_pre-5))|| (tp_now > (priv->ext_stats.tp_average_pre+5)))){ |
| 3867 | priv->pshare->DNC_chk = 1; |
| 3868 | //phy_set_bb_reg(priv, 0xb30, bMaskDWord, 0); |
| 3869 | phy_set_bb_reg(priv, 0x870, bMaskDWord, 0x07000700); |
| 3870 | if (!rtk_timer_pending(&priv->dnc_timer)) { |
| 3871 | //printk("... Start Check Noise ...\n"); |
| 3872 | rtk_mod_timer(&priv->dnc_timer, jiffies + RTL_MILISECONDS_TO_JIFFIES(100)); // 100 ms |
| 3873 | } |
| 3874 | } |
| 3875 | } |
| 3876 | |
| 3877 | priv->ext_stats.tp_average_pre = tp_now; |
| 3878 | |
| 3879 | } else if ((priv->pshare->DNC_chk_cnt % 5)==1 && priv->pshare->DNC_chk == 1) { |
| 3880 | priv->pshare->DNC_chk = 0; |
| 3881 | //if ((priv->pshare->F94_cnt + priv->pshare->F90_cnt) < 120) { |
| 3882 | if ((priv->pshare->F94_cnt + priv->pshare->Reg664_cnt) < 120) { |
| 3883 | priv->pshare->DNC_on = 0; |
| 3884 | //phy_set_bb_reg(priv, 0xb30, bMaskDWord, 0); |
| 3885 | phy_set_bb_reg(priv, 0x870, bMaskDWord, 0x07000700); |
| 3886 | //printk("Dynamic Noise Control OFF\n"); |
| 3887 | } |
| 3888 | } |
| 3889 | priv->pshare->DNC_chk_cnt++; |
| 3890 | } |
| 3891 | } |
| 3892 | } |
| 3893 | #endif |
| 3894 | } |
| 3895 | |
| 3896 | |
| 3897 | //3 ============================================================ |
| 3898 | //3 Rate Adaptive |
| 3899 | //3 ============================================================ |
| 3900 | |
| 3901 | void check_RA_by_rssi(struct rtl8192cd_priv *priv, struct stat_info *pstat) |
| 3902 | { |
| 3903 | int level = 0; |
| 3904 | |
| 3905 | switch (pstat->cmn_info.ra_info.rssi_level) { |
| 3906 | case 1: |
| 3907 | if (pstat->rssi >= priv->pshare->rf_ft_var.raGoDownUpper) |
| 3908 | level = 1; |
| 3909 | else if ((pstat->rssi >= priv->pshare->rf_ft_var.raGoDown20MLower) || |
| 3910 | ((priv->pshare->is_40m_bw) && (pstat->ht_cap_len) && |
| 3911 | (pstat->rssi >= priv->pshare->rf_ft_var.raGoDown40MLower) && |
| 3912 | (pstat->ht_cap_buf.ht_cap_info & cpu_to_le16(_HTCAP_SUPPORT_CH_WDTH_)))) |
| 3913 | level = 2; |
| 3914 | else |
| 3915 | level = 3; |
| 3916 | break; |
| 3917 | case 2: |
| 3918 | if (pstat->rssi > priv->pshare->rf_ft_var.raGoUpUpper) |
| 3919 | level = 1; |
| 3920 | else if ((pstat->rssi < priv->pshare->rf_ft_var.raGoDown40MLower) || |
| 3921 | ((!pstat->ht_cap_len || !priv->pshare->is_40m_bw || |
| 3922 | !(pstat->ht_cap_buf.ht_cap_info & cpu_to_le16(_HTCAP_SUPPORT_CH_WDTH_))) && |
| 3923 | (pstat->rssi < priv->pshare->rf_ft_var.raGoDown20MLower))) |
| 3924 | level = 3; |
| 3925 | else |
| 3926 | level = 2; |
| 3927 | break; |
| 3928 | case 3: |
| 3929 | if (pstat->rssi > priv->pshare->rf_ft_var.raGoUpUpper) |
| 3930 | level = 1; |
| 3931 | else if ((pstat->rssi > priv->pshare->rf_ft_var.raGoUp20MLower) || |
| 3932 | ((priv->pshare->is_40m_bw) && (pstat->ht_cap_len) && |
| 3933 | (pstat->rssi > priv->pshare->rf_ft_var.raGoUp40MLower) && |
| 3934 | (pstat->ht_cap_buf.ht_cap_info & cpu_to_le16(_HTCAP_SUPPORT_CH_WDTH_)))) |
| 3935 | level = 2; |
| 3936 | else |
| 3937 | level = 3; |
| 3938 | break; |
| 3939 | default: |
| 3940 | if (isErpSta(pstat)) |
| 3941 | DEBUG_ERR("wrong rssi level setting\n"); |
| 3942 | break; |
| 3943 | } |
| 3944 | |
| 3945 | if (level != pstat->cmn_info.ra_info.rssi_level) { |
| 3946 | pstat->cmn_info.ra_info.rssi_level = level; |
| 3947 | #ifdef CONFIG_RTL_88E_SUPPORT |
| 3948 | if (GET_CHIP_VER(priv)==VERSION_8188E) { |
| 3949 | #ifdef TXREPORT |
| 3950 | add_RATid(priv, pstat); |
| 3951 | #endif |
| 3952 | } else |
| 3953 | #endif |
| 3954 | { |
| 3955 | #if defined(CONFIG_RTL_92D_SUPPORT) || defined(CONFIG_RTL_92C_SUPPORT) |
| 3956 | add_update_RATid(priv, pstat); |
| 3957 | #endif |
| 3958 | } |
| 3959 | } |
| 3960 | } |
| 3961 | #endif |
| 3962 | |
| 3963 | #if defined(CONFIG_RTL_92C_SUPPORT) || defined(CONFIG_RTL_92D_SUPPORT) |
| 3964 | |
| 3965 | void check_txrate_by_reg(struct rtl8192cd_priv *priv, struct stat_info *pstat) |
| 3966 | { |
| 3967 | unsigned char initial_rate = 0x7f; |
| 3968 | unsigned char legacyRA =0 ; |
| 3969 | |
| 3970 | if( should_restrict_Nrate(priv, pstat) && is_fixedMCSTxRate(priv, pstat)) |
| 3971 | legacyRA = 1; |
| 3972 | |
| 3973 | if (!pstat->cmn_info.ra_info.disable_ra) |
| 3974 | { |
| 3975 | if (is_auto_rate(priv , pstat) || legacyRA) |
| 3976 | { |
| 3977 | initial_rate = RTL_R8(INIDATA_RATE_SEL + REMAP_AID(pstat)) & 0x7f; |
| 3978 | if (initial_rate == 0x7f) |
| 3979 | return; |
| 3980 | |
| 3981 | if ((initial_rate&0x3f) < 12) { |
| 3982 | pstat->current_tx_rate = dot11_rate_table[initial_rate&0x3f]; |
| 3983 | pstat->ht_current_tx_info &= ~TX_USE_SHORT_GI; |
| 3984 | } else { |
| 3985 | pstat->current_tx_rate = HT_RATE_ID + ((initial_rate&0x3f) -12); |
| 3986 | if (initial_rate & BIT(6)) |
| 3987 | pstat->ht_current_tx_info |= TX_USE_SHORT_GI; |
| 3988 | else |
| 3989 | pstat->ht_current_tx_info &= ~TX_USE_SHORT_GI; |
| 3990 | } |
| 3991 | |
| 3992 | priv->pshare->current_tx_rate = pstat->current_tx_rate; |
| 3993 | priv->pshare->ht_current_tx_info = pstat->ht_current_tx_info; |
| 3994 | } else if (pstat->ht_cap_len) { |
| 3995 | unsigned int is_sgi = 0; |
| 3996 | |
| 3997 | if (priv->pshare->is_40m_bw && (pstat->tx_bw == CHANNEL_WIDTH_40) |
| 3998 | #ifdef WIFI_11N_2040_COEXIST |
| 3999 | && !((OPMODE & WIFI_AP_STATE) && priv->pmib->dot11nConfigEntry.dot11nCoexist && |
| 4000 | (priv->bg_ap_timeout || orForce20_Switch20Map(priv) |
| 4001 | )) |
| 4002 | #endif |
| 4003 | ) { |
| 4004 | if (priv->pmib->dot11nConfigEntry.dot11nShortGIfor40M |
| 4005 | && (pstat->ht_cap_buf.ht_cap_info & cpu_to_le16(_HTCAP_SHORTGI_40M_))) |
| 4006 | is_sgi++; |
| 4007 | } else if (priv->pmib->dot11nConfigEntry.dot11nShortGIfor20M |
| 4008 | && (pstat->ht_cap_buf.ht_cap_info & cpu_to_le16(_HTCAP_SHORTGI_20M_))) { |
| 4009 | is_sgi++; |
| 4010 | } |
| 4011 | |
| 4012 | if (is_sgi) |
| 4013 | pstat->ht_current_tx_info |= TX_USE_SHORT_GI; |
| 4014 | else |
| 4015 | pstat->ht_current_tx_info &= ~TX_USE_SHORT_GI; |
| 4016 | } |
| 4017 | |
| 4018 | if (priv->pshare->is_40m_bw && (pstat->tx_bw == CHANNEL_WIDTH_40)) |
| 4019 | pstat->ht_current_tx_info |= TX_USE_40M_MODE; |
| 4020 | else |
| 4021 | pstat->ht_current_tx_info &= ~TX_USE_40M_MODE; |
| 4022 | |
| 4023 | priv->pshare->ht_current_tx_info = pstat->ht_current_tx_info; |
| 4024 | } else { |
| 4025 | DEBUG_INFO("sta has no aid found to check current tx rate\n"); |
| 4026 | } |
| 4027 | } |
| 4028 | #endif |
| 4029 | #if 0 |
| 4030 | void add_RATid(struct rtl8192cd_priv *priv, struct stat_info *pstat) |
| 4031 | { |
| 4032 | unsigned char limit=16; |
| 4033 | int i; |
| 4034 | unsigned long flags; |
| 4035 | unsigned int update_reg=0; |
| 4036 | |
| 4037 | SAVE_INT_AND_CLI(flags); |
| 4038 | |
| 4039 | pstat->tx_ra_bitmap = 0; |
| 4040 | |
| 4041 | for (i=0; i<32; i++) { |
| 4042 | if (pstat->bssrateset[i]) |
| 4043 | pstat->tx_ra_bitmap |= get_bit_value_from_ieee_value(pstat->bssrateset[i]&0x7f); |
| 4044 | } |
| 4045 | |
| 4046 | if (pstat->ht_cap_len) { |
| 4047 | if ((pstat->MIMO_ps & _HT_MIMO_PS_STATIC_) || |
| 4048 | (get_rf_mimo_mode(priv)== RF_1T2R) || |
| 4049 | (get_rf_mimo_mode(priv)== RF_1T1R)) |
| 4050 | limit=8; |
| 4051 | |
| 4052 | for (i=0; i<limit; i++) { |
| 4053 | if (pstat->ht_cap_buf.support_mcs[i/8] & BIT(i%8)) |
| 4054 | pstat->tx_ra_bitmap |= BIT(i+12); |
| 4055 | } |
| 4056 | } |
| 4057 | |
| 4058 | if (pstat->ht_cap_len) { |
| 4059 | unsigned int set_sgi = 0; |
| 4060 | if (priv->pshare->is_40m_bw && (pstat->tx_bw == CHANNEL_WIDTH_40) |
| 4061 | #ifdef WIFI_11N_2040_COEXIST |
| 4062 | && !((OPMODE & WIFI_AP_STATE) && priv->pmib->dot11nConfigEntry.dot11nCoexist && |
| 4063 | (priv->bg_ap_timeout || orForce20_Switch20Map(priv) |
| 4064 | )) |
| 4065 | #endif |
| 4066 | ) { |
| 4067 | if (pstat->ht_cap_buf.ht_cap_info & cpu_to_le16(_HTCAP_SHORTGI_40M_) |
| 4068 | && priv->pmib->dot11nConfigEntry.dot11nShortGIfor40M) |
| 4069 | set_sgi++; |
| 4070 | } else if (pstat->ht_cap_buf.ht_cap_info & cpu_to_le16(_HTCAP_SHORTGI_20M_) && |
| 4071 | priv->pmib->dot11nConfigEntry.dot11nShortGIfor20M) { |
| 4072 | set_sgi++; |
| 4073 | } |
| 4074 | |
| 4075 | if (set_sgi) { |
| 4076 | #if defined(CONFIG_RTL_88E_SUPPORT) && defined(TXREPORT) |
| 4077 | if (GET_CHIP_VER(priv)==VERSION_8188E) |
| 4078 | priv->pshare->RaInfo[pstat->cmn_info.aid].SGIEnable = 1; |
| 4079 | else |
| 4080 | #endif |
| 4081 | pstat->tx_ra_bitmap |= BIT(28); |
| 4082 | } |
| 4083 | #if defined(CONFIG_RTL_88E_SUPPORT) && defined(TXREPORT) |
| 4084 | else { |
| 4085 | if (GET_CHIP_VER(priv)==VERSION_8188E) |
| 4086 | priv->pshare->RaInfo[pstat->cmn_info.aid].SGIEnable = 0; |
| 4087 | } |
| 4088 | #endif |
| 4089 | } |
| 4090 | #if defined(CONFIG_RTL_88E_SUPPORT) && defined(TXREPORT) |
| 4091 | else { |
| 4092 | if (GET_CHIP_VER(priv)==VERSION_8188E) |
| 4093 | priv->pshare->RaInfo[pstat->cmn_info.aid].SGIEnable = 0; |
| 4094 | } |
| 4095 | #endif |
| 4096 | |
| 4097 | if ((pstat->cmn_info.ra_info.rssi_level < 1) || (pstat->cmn_info.ra_info.rssi_level > 3)) { |
| 4098 | if (pstat->rssi >= priv->pshare->rf_ft_var.raGoDownUpper) |
| 4099 | pstat->cmn_info.ra_info.rssi_level = 1; |
| 4100 | else if ((pstat->rssi >= priv->pshare->rf_ft_var.raGoDown20MLower) || |
| 4101 | ((priv->pshare->is_40m_bw) && (pstat->ht_cap_len) && |
| 4102 | (pstat->rssi >= priv->pshare->rf_ft_var.raGoDown40MLower) && |
| 4103 | (pstat->ht_cap_buf.ht_cap_info & cpu_to_le16(_HTCAP_SUPPORT_CH_WDTH_)))) |
| 4104 | pstat->cmn_info.ra_info.rssi_level = 2; |
| 4105 | else |
| 4106 | pstat->cmn_info.ra_info.rssi_level = 3; |
| 4107 | } |
| 4108 | |
| 4109 | if ((priv->pmib->dot11BssType.net_work_type & WIRELESS_11A) && |
| 4110 | ((OPMODE & WIFI_AP_STATE) || (priv->pmib->dot11RFEntry.phyBandSelect & PHY_BAND_5G))) |
| 4111 | pstat->tx_ra_bitmap &= 0xfffffff0; //disable cck rate |
| 4112 | |
| 4113 | #ifdef P2P_SUPPORT |
| 4114 | if(pstat->is_p2p_client){ |
| 4115 | pstat->tx_ra_bitmap &= 0xfffffff0; //disable cck rate |
| 4116 | } |
| 4117 | #endif |
| 4118 | |
| 4119 | // rate adaptive by rssi |
| 4120 | if ((priv->pmib->dot11BssType.net_work_type & WIRELESS_11N) && pstat->ht_cap_len && (!should_restrict_Nrate(priv, pstat))) { |
| 4121 | if ((get_rf_mimo_mode(priv) == RF_1T2R) || (get_rf_mimo_mode(priv) == RF_1T1R)) { |
| 4122 | switch (pstat->cmn_info.ra_info.rssi_level) { |
| 4123 | case 1: |
| 4124 | pstat->tx_ra_bitmap &= 0x100f0000; |
| 4125 | break; |
| 4126 | case 2: |
| 4127 | pstat->tx_ra_bitmap &= 0x100ff000; |
| 4128 | break; |
| 4129 | case 3: |
| 4130 | if (priv->pshare->is_40m_bw) |
| 4131 | pstat->tx_ra_bitmap &= 0x100ff005; |
| 4132 | else |
| 4133 | pstat->tx_ra_bitmap &= 0x100ff001; |
| 4134 | break; |
| 4135 | } |
| 4136 | } else { |
| 4137 | switch (pstat->cmn_info.ra_info.rssi_level) { |
| 4138 | case 1: |
| 4139 | pstat->tx_ra_bitmap &= 0x1f8f0000; |
| 4140 | break; |
| 4141 | case 2: |
| 4142 | pstat->tx_ra_bitmap &= 0x1f8ff000; |
| 4143 | break; |
| 4144 | case 3: |
| 4145 | if (priv->pshare->is_40m_bw) |
| 4146 | pstat->tx_ra_bitmap &= 0x010ff005; |
| 4147 | else |
| 4148 | pstat->tx_ra_bitmap &= 0x010ff001; |
| 4149 | break; |
| 4150 | } |
| 4151 | |
| 4152 | // Don't need to mask high rates due to new rate adaptive parameters |
| 4153 | //if (pstat->is_broadcom_sta) // use MCS12 as the highest rate vs. Broadcom sta |
| 4154 | // pstat->tx_ra_bitmap &= 0x81ffffff; |
| 4155 | |
| 4156 | // NIC driver will report not supporting MCS15 and MCS14 in asoc req |
| 4157 | //if (pstat->is_rtl8190_sta && !pstat->is_2t_mimo_sta) |
| 4158 | // pstat->tx_ra_bitmap &= 0x83ffffff; // if Realtek 1x2 sta, don't use MCS15 and MCS14 |
| 4159 | } |
| 4160 | } |
| 4161 | else if (((priv->pmib->dot11BssType.net_work_type & WIRELESS_11G) && isErpSta(pstat)) || |
| 4162 | ((priv->pmib->dot11BssType.net_work_type & WIRELESS_11A) && |
| 4163 | ((OPMODE & WIFI_AP_STATE) || (priv->pmib->dot11RFEntry.phyBandSelect & PHY_BAND_5G)))) |
| 4164 | { |
| 4165 | switch (pstat->cmn_info.ra_info.rssi_level) { |
| 4166 | case 1: |
| 4167 | pstat->tx_ra_bitmap &= 0x00000f00; |
| 4168 | break; |
| 4169 | case 2: |
| 4170 | pstat->tx_ra_bitmap &= 0x00000ff0; |
| 4171 | break; |
| 4172 | case 3: |
| 4173 | pstat->tx_ra_bitmap &= 0x00000ff5; |
| 4174 | break; |
| 4175 | } |
| 4176 | } else { |
| 4177 | pstat->tx_ra_bitmap &= 0x0000000d; |
| 4178 | } |
| 4179 | |
| 4180 | // Client mode IOT issue, Button 2009.07.17 |
| 4181 | #ifdef CLIENT_MODE |
| 4182 | if(OPMODE & WIFI_STATION_STATE) { |
| 4183 | if(!pstat->is_rtl8192s_sta && pstat->is_realtek_sta && pstat->is_legacy_encrpt) |
| 4184 | pstat->tx_ra_bitmap &= 0x0001ffff; // up to MCS4 |
| 4185 | } |
| 4186 | #endif |
| 4187 | #if defined(CONFIG_RTL_92D_SUPPORT) && defined (USB_POWER_SUPPORT) |
| 4188 | if ((GET_CHIP_VER(priv)==VERSION_8192D) && (priv->pmib->dot11RFEntry.phyBandSelect & PHY_BAND_5G)) |
| 4189 | pstat->tx_ra_bitmap &= USB_RA_MASK; |
| 4190 | #endif |
| 4191 | |
| 4192 | update_remapAid(priv, pstat); |
| 4193 | |
| 4194 | #if defined(CONFIG_RTL_88E_SUPPORT) && defined(TXREPORT) |
| 4195 | if (GET_CHIP_VER(priv)==VERSION_8188E) { |
| 4196 | #ifndef RATEADAPTIVE_BY_ODM |
| 4197 | if (pstat->tx_ra_bitmap & 0xff000) { |
| 4198 | if (priv->pshare->is_40m_bw) |
| 4199 | priv->pshare->RaInfo[pstat->cmn_info.aid].RateID = ARFR_1T_40M; |
| 4200 | else |
| 4201 | priv->pshare->RaInfo[pstat->cmn_info.aid].RateID = ARFR_1T_20M; |
| 4202 | } else if (pstat->tx_ra_bitmap & 0xff0) { |
| 4203 | priv->pshare->RaInfo[pstat->cmn_info.aid].RateID = ARFR_BG_MIX; |
| 4204 | } else { |
| 4205 | priv->pshare->RaInfo[pstat->cmn_info.aid].RateID = ARFR_B_ONLY; |
| 4206 | } |
| 4207 | |
| 4208 | priv->pshare->RaInfo[pstat->cmn_info.aid].RateMask = pstat->tx_ra_bitmap; |
| 4209 | ARFBRefresh(priv, &priv->pshare->RaInfo[pstat->cmn_info.aid]); |
| 4210 | #else |
| 4211 | struct _odm_ra_info_* pRAInfo = &(ODMPTR->ra_info[pstat->cmn_info.aid]); |
| 4212 | if (pstat->tx_ra_bitmap & 0xff000) { |
| 4213 | if (priv->pshare->is_40m_bw) |
| 4214 | pRAInfo->RateID = ARFR_1T_40M; |
| 4215 | else |
| 4216 | pRAInfo->RateID = ARFR_1T_20M; |
| 4217 | } else if (pstat->tx_ra_bitmap & 0xff0) { |
| 4218 | pRAInfo->RateID = ARFR_BG_MIX; |
| 4219 | } else { |
| 4220 | pRAInfo->RateID = ARFR_B_ONLY; |
| 4221 | } |
| 4222 | odm_ra_update_rate_info_8188e(ODMPTR, pstat->cmn_info.aid, pRAInfo->RateID, pstat->tx_ra_bitmap, pRAInfo->RateSGI); |
| 4223 | #endif |
| 4224 | } else |
| 4225 | #endif |
| 4226 | #if defined(CONFIG_RTL_92C_SUPPORT) || defined(CONFIG_RTL_92D_SUPPORT) |
| 4227 | { |
| 4228 | |
| 4229 | if (!pstat->cmn_info.ra_info.disable_ra) |
| 4230 | { |
| 4231 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 4232 | if (priv->pmib->dot11RFEntry.phyBandSelect == PHY_BAND_5G) |
| 4233 | { |
| 4234 | pstat->tx_ra_bitmap &= 0xfffffff0; |
| 4235 | if (pstat->tx_ra_bitmap & 0xff00000) { |
| 4236 | if (priv->pshare->is_40m_bw) |
| 4237 | set_RATid_cmd(priv, REMAP_AID(pstat), ARFR_2T_Band_A_40M, pstat->tx_ra_bitmap); |
| 4238 | else |
| 4239 | set_RATid_cmd(priv, REMAP_AID(pstat), ARFR_2T_Band_A_20M, pstat->tx_ra_bitmap); |
| 4240 | update_reg++; |
| 4241 | } else if (pstat->tx_ra_bitmap & 0xff000) { |
| 4242 | if (priv->pshare->is_40m_bw) |
| 4243 | set_RATid_cmd(priv, REMAP_AID(pstat), ARFR_2T_Band_A_40M, pstat->tx_ra_bitmap); |
| 4244 | else |
| 4245 | set_RATid_cmd(priv, REMAP_AID(pstat), ARFR_2T_Band_A_20M, pstat->tx_ra_bitmap); |
| 4246 | } else if (pstat->tx_ra_bitmap & 0xff0) { |
| 4247 | set_RATid_cmd(priv, REMAP_AID(pstat), ARFR_Band_A_BMC, pstat->tx_ra_bitmap); |
| 4248 | } else { |
| 4249 | set_RATid_cmd(priv, REMAP_AID(pstat), ARFR_Band_A_BMC, pstat->tx_ra_bitmap); |
| 4250 | } |
| 4251 | } else |
| 4252 | #endif |
| 4253 | { |
| 4254 | if (pstat->tx_ra_bitmap & 0xff00000) { |
| 4255 | if (priv->pshare->is_40m_bw) |
| 4256 | set_RATid_cmd(priv, REMAP_AID(pstat), ARFR_2T_40M, pstat->tx_ra_bitmap); |
| 4257 | else |
| 4258 | set_RATid_cmd(priv, REMAP_AID(pstat), ARFR_2T_20M, pstat->tx_ra_bitmap); |
| 4259 | update_reg++; |
| 4260 | } else if (pstat->tx_ra_bitmap & 0xff000) { |
| 4261 | if (priv->pshare->is_40m_bw) |
| 4262 | set_RATid_cmd(priv, REMAP_AID(pstat), ARFR_1T_40M, pstat->tx_ra_bitmap); |
| 4263 | else |
| 4264 | set_RATid_cmd(priv, REMAP_AID(pstat), ARFR_1T_20M, pstat->tx_ra_bitmap); |
| 4265 | } else if (pstat->tx_ra_bitmap & 0xff0) { |
| 4266 | set_RATid_cmd(priv, REMAP_AID(pstat), ARFR_BG_MIX, pstat->tx_ra_bitmap); |
| 4267 | } else { |
| 4268 | set_RATid_cmd(priv, REMAP_AID(pstat), ARFR_B_ONLY, pstat->tx_ra_bitmap); |
| 4269 | } |
| 4270 | } |
| 4271 | |
| 4272 | /* |
| 4273 | * Rate adaptive algorithm. |
| 4274 | * If the STA is 2R, we set the inti rate to MCS 15 |
| 4275 | */ |
| 4276 | if (update_reg) { |
| 4277 | if (!pstat->check_init_tx_rate && (pstat->rssi > 55)) { |
| 4278 | pstat->check_init_tx_rate = 1; |
| 4279 | } |
| 4280 | } |
| 4281 | DEBUG_INFO("Add id %d val %08x to ratr\n", pstat->cmn_info.aid, pstat->tx_ra_bitmap); |
| 4282 | } else { |
| 4283 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 4284 | if (priv->pmib->dot11RFEntry.phyBandSelect == PHY_BAND_5G) { |
| 4285 | if (priv->pshare->is_40m_bw) |
| 4286 | set_RATid_cmd(priv, priv->pshare->fw_support_sta_num, ARFR_2T_Band_A_40M, 0x1ffffff0); |
| 4287 | else |
| 4288 | set_RATid_cmd(priv, priv->pshare->fw_support_sta_num, ARFR_2T_Band_A_20M, 0x1ffffff0); |
| 4289 | } else |
| 4290 | #endif |
| 4291 | { |
| 4292 | if (priv->pshare->is_40m_bw) |
| 4293 | set_RATid_cmd(priv, priv->pshare->fw_support_sta_num, ARFR_2T_40M, 0x1fffffff); |
| 4294 | else |
| 4295 | set_RATid_cmd(priv, priv->pshare->fw_support_sta_num, ARFR_2T_20M, 0x1fffffff); |
| 4296 | } |
| 4297 | |
| 4298 | } |
| 4299 | } |
| 4300 | #endif |
| 4301 | |
| 4302 | RESTORE_INT(flags); |
| 4303 | } |
| 4304 | #endif |
| 4305 | |
| 4306 | void set_rssi_cmd(struct rtl8192cd_priv *priv, struct stat_info *pstat) |
| 4307 | { |
| 4308 | #ifndef SMP_SYNC |
| 4309 | unsigned long flags; |
| 4310 | #endif |
| 4311 | unsigned int content = 0; |
| 4312 | |
| 4313 | int rssi = pstat->rssi; |
| 4314 | |
| 4315 | #ifdef HIGH_POWER_EXT_PA |
| 4316 | if( priv->pshare->rf_ft_var.use_ext_pa ) |
| 4317 | rssi += RSSI_DIFF_PA; |
| 4318 | if( rssi > 100) |
| 4319 | rssi = 100; |
| 4320 | #endif |
| 4321 | |
| 4322 | |
| 4323 | SAVE_INT_AND_CLI(flags); |
| 4324 | |
| 4325 | /* |
| 4326 | * set rssi |
| 4327 | */ |
| 4328 | content = rssi<< 24; |
| 4329 | |
| 4330 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 4331 | /* |
| 4332 | * set max macid |
| 4333 | */ |
| 4334 | if (GET_CHIP_VER(priv) == VERSION_8192D){ |
| 4335 | content |= priv->pshare->max_fw_macid << 16; |
| 4336 | } |
| 4337 | #endif |
| 4338 | |
| 4339 | /* |
| 4340 | * set macid |
| 4341 | */ |
| 4342 | content |= REMAP_AID(pstat) << 8; |
| 4343 | |
| 4344 | /* |
| 4345 | * set cmd id |
| 4346 | */ |
| 4347 | content |= H2C_CMD_RSSI; |
| 4348 | |
| 4349 | signin_h2c_cmd(priv, content, 0); |
| 4350 | |
| 4351 | RESTORE_INT(flags); |
| 4352 | } |
| 4353 | |
| 4354 | #if defined(CONFIG_RTL_92D_SUPPORT) || defined(CONFIG_RTL_92C_SUPPORT) |
| 4355 | #ifdef CONFIG_PCI_HCI |
| 4356 | static __always_inline void add_rssi_timer(unsigned long task_priv) |
| 4357 | { |
| 4358 | struct rtl8192cd_priv *priv = (struct rtl8192cd_priv *)task_priv; |
| 4359 | struct stat_info *pstat = NULL; |
| 4360 | unsigned int set_timer = 0; |
| 4361 | unsigned long flags = 0; |
| 4362 | |
| 4363 | if (!(priv->drv_state & DRV_STATE_OPEN)) |
| 4364 | return; |
| 4365 | |
| 4366 | if (rtk_timer_pending(&priv->add_rssi_timer)) |
| 4367 | rtk_del_timer_sync(&priv->add_rssi_timer); |
| 4368 | |
| 4369 | #ifdef PCIE_POWER_SAVING |
| 4370 | if ((priv->pwr_state == L2) || (priv->pwr_state == L1)) |
| 4371 | return; |
| 4372 | #endif |
| 4373 | |
| 4374 | if (!list_empty(&priv->addrssi_list)) { |
| 4375 | pstat = list_entry(priv->addrssi_list.next, struct stat_info, addrssi_list); |
| 4376 | if (!pstat) |
| 4377 | return; |
| 4378 | |
| 4379 | if (!is_h2c_buf_occupy(priv)) { |
| 4380 | set_rssi_cmd(priv, pstat); |
| 4381 | if (!list_empty(&pstat->addrssi_list)) { |
| 4382 | SAVE_INT_AND_CLI(flags); |
| 4383 | SMP_LOCK(flags); |
| 4384 | list_del_init(&pstat->addrssi_list); |
| 4385 | RESTORE_INT(flags); |
| 4386 | SMP_UNLOCK(flags); |
| 4387 | } |
| 4388 | |
| 4389 | if (!list_empty(&priv->addrssi_list)) |
| 4390 | set_timer++; |
| 4391 | } else { |
| 4392 | set_timer++; |
| 4393 | } |
| 4394 | } |
| 4395 | |
| 4396 | if (set_timer) |
| 4397 | rtk_mod_timer(&priv->add_rssi_timer, jiffies + RTL_MILISECONDS_TO_JIFFIES(50)); // 50 ms |
| 4398 | } |
| 4399 | DEFINE_TIMER_CALLBACK(add_rssi_timer); |
| 4400 | |
| 4401 | void init_add_rssi_timer(struct rtl8192cd_priv *priv) |
| 4402 | { |
| 4403 | rtk_timer_setup(&(priv->add_rssi_timer), add_rssi_timer, (unsigned long)priv, 0); |
| 4404 | } |
| 4405 | |
| 4406 | void add_update_rssi(struct rtl8192cd_priv *priv, struct stat_info *pstat) |
| 4407 | { |
| 4408 | #ifndef SMP_SYNC |
| 4409 | unsigned long flags; |
| 4410 | #endif |
| 4411 | |
| 4412 | if (is_h2c_buf_occupy(priv)) { |
| 4413 | if (list_empty(&pstat->addrssi_list)) { |
| 4414 | SAVE_INT_AND_CLI(flags); |
| 4415 | list_add_tail(&(pstat->addrssi_list), &(priv->addrssi_list)); |
| 4416 | RESTORE_INT(flags); |
| 4417 | |
| 4418 | if (!rtk_timer_pending(&priv->add_rssi_timer)) |
| 4419 | rtk_mod_timer(&priv->add_rssi_timer, jiffies + RTL_MILISECONDS_TO_JIFFIES(50)); // 50 ms |
| 4420 | } |
| 4421 | } else { |
| 4422 | set_rssi_cmd(priv, pstat); |
| 4423 | } |
| 4424 | } |
| 4425 | #endif // CONFIG_PCI_HCI |
| 4426 | |
| 4427 | #ifdef CONFIG_USB_HCI |
| 4428 | void add_update_rssi(struct rtl8192cd_priv *priv, struct stat_info *pstat) |
| 4429 | { |
| 4430 | notify_update_sta_rssi(priv, pstat); |
| 4431 | } |
| 4432 | #endif // CONFIG_USB_HCI |
| 4433 | #endif // CONFIG_RTL_92D_SUPPORT || CONFIG_RTL_92C_SUPPORT |
| 4434 | |
| 4435 | |
| 4436 | void set_RATid_cmd(struct rtl8192cd_priv *priv, unsigned int macid, unsigned int rateid, unsigned int ratemask) |
| 4437 | { |
| 4438 | unsigned int content = 0; |
| 4439 | unsigned short ext_content = 0; |
| 4440 | |
| 4441 | //#ifdef CONFIG_RTL_8812_SUPPORT |
| 4442 | if(! CHIP_VER_92X_SERIES(priv)) |
| 4443 | return; |
| 4444 | //#endif |
| 4445 | |
| 4446 | /* |
| 4447 | * set ratemask |
| 4448 | */ |
| 4449 | ext_content = ratemask & 0xffff; |
| 4450 | content = ((ratemask & 0xfff0000) >> 16) << 8; |
| 4451 | |
| 4452 | /* |
| 4453 | * set short GI |
| 4454 | */ |
| 4455 | if (ratemask & BIT(28)) |
| 4456 | content |= BIT(29); |
| 4457 | |
| 4458 | /* |
| 4459 | * set macid (station aid) |
| 4460 | */ |
| 4461 | content |= (macid & 0x1f) << 24; |
| 4462 | |
| 4463 | /* |
| 4464 | * set rateid (ARFR table) |
| 4465 | */ |
| 4466 | content |= (rateid & 0xf) << 20; |
| 4467 | |
| 4468 | /* |
| 4469 | * set ext_content used |
| 4470 | */ |
| 4471 | content |= BIT(7); |
| 4472 | |
| 4473 | /* |
| 4474 | * set cmd id |
| 4475 | */ |
| 4476 | content |= H2C_CMD_MACID; |
| 4477 | |
| 4478 | signin_h2c_cmd(priv, content, ext_content); |
| 4479 | } |
| 4480 | |
| 4481 | |
| 4482 | |
| 4483 | //3 ============================================================ |
| 4484 | //3 EDCCA |
| 4485 | //3 ============================================================ |
| 4486 | #if 0 |
| 4487 | void check_EDCCA(struct rtl8192cd_priv *priv, short rssi) |
| 4488 | { |
| 4489 | if ((priv->pshare->rf_ft_var.edcca_thd) && (priv->pmib->dot11RFEntry.dot11channel==14 |
| 4490 | || priv->pshare->is_40m_bw |
| 4491 | #if defined(CONFIG_RTL_92D_SUPPORT) |
| 4492 | || (priv->pmib->dot11RFEntry.phyBandSelect & PHY_BAND_5G) |
| 4493 | #endif |
| 4494 | )) { |
| 4495 | if((rssi > priv->pshare->rf_ft_var.edcca_thd) && (priv->pshare->phw->EDCCA_on == 0)) { |
| 4496 | RTL_W32(REG_OFDM_0_ECCA_THRESHOLD, 0xfc03fd); |
| 4497 | priv->pshare->phw->EDCCA_on =1; |
| 4498 | } else if( (rssi < priv->pshare->rf_ft_var.edcca_thd-5) && priv->pshare->phw->EDCCA_on) { |
| 4499 | RTL_W32(REG_OFDM_0_ECCA_THRESHOLD, 0x7f037f); |
| 4500 | priv->pshare->phw->EDCCA_on =0; |
| 4501 | } |
| 4502 | } |
| 4503 | if ((!priv->pshare->rf_ft_var.edcca_thd) && priv->pshare->phw->EDCCA_on) { |
| 4504 | RTL_W32(0xc4c, 0x7f037f); |
| 4505 | priv->pshare->phw->EDCCA_on = 0; |
| 4506 | } |
| 4507 | } |
| 4508 | #endif |
| 4509 | |
| 4510 | //3 ============================================================ |
| 4511 | //3 Antenna Diversity |
| 4512 | //3 ============================================================ |
| 4513 | #ifdef SW_ANT_SWITCH |
| 4514 | |
| 4515 | // |
| 4516 | // 20100514 Luke/Joseph: |
| 4517 | // Add new function to reset antenna diversity state after link. |
| 4518 | // |
| 4519 | |
| 4520 | void resetSwAntDivVariable(struct rtl8192cd_priv *priv) |
| 4521 | { |
| 4522 | priv->pshare->RSSI_sum_R = 0; |
| 4523 | priv->pshare->RSSI_cnt_R = 0; |
| 4524 | priv->pshare->RSSI_sum_L = 0; |
| 4525 | priv->pshare->RSSI_cnt_L = 0; |
| 4526 | priv->pshare->TXByteCnt_R = 0; |
| 4527 | priv->pshare->TXByteCnt_L = 0; |
| 4528 | priv->pshare->RXByteCnt_R = 0; |
| 4529 | priv->pshare->RXByteCnt_L = 0; |
| 4530 | |
| 4531 | } |
| 4532 | void sw_ant_div_rest_after_link(struct rtl8192cd_priv *priv) |
| 4533 | { |
| 4534 | priv->pshare->RSSI_test = FALSE; |
| 4535 | priv->pshare->DM_SWAT_Table.try_flag = SWAW_STEP_RESET; |
| 4536 | memset(priv->pshare->DM_SWAT_Table.SelectAntennaMap, 0, sizeof(priv->pshare->DM_SWAT_Table.SelectAntennaMap)); |
| 4537 | priv->pshare->DM_SWAT_Table.mapIndex = 0; |
| 4538 | priv->pshare->lastTxOkCnt = (unsigned long long)priv->net_stats.tx_bytes; |
| 4539 | priv->pshare->lastRxOkCnt = (unsigned long long)priv->net_stats.rx_bytes; |
| 4540 | resetSwAntDivVariable(priv); |
| 4541 | } |
| 4542 | |
| 4543 | |
| 4544 | void dm_SW_AntennaSwitchInit(struct rtl8192cd_priv *priv) |
| 4545 | { |
| 4546 | if(!priv->pshare->rf_ft_var.antSw_enable) |
| 4547 | return; |
| 4548 | |
| 4549 | // if (GET_CHIP_VER(priv) == VERSION_8188C) |
| 4550 | if(get_rf_mimo_mode(priv)== RF_1T1R) |
| 4551 | priv->pshare->rf_ft_var.antSw_select = 0; |
| 4552 | |
| 4553 | //RT_TRACE(COMP_SWAS, DBG_LOUD, ("SWAS:Init SW Antenna Switch\n")); |
| 4554 | resetSwAntDivVariable(priv); |
| 4555 | priv->pshare->DM_SWAT_Table.CurAntenna = Antenna_L; |
| 4556 | priv->pshare->DM_SWAT_Table.try_flag = SWAW_STEP_RESET; |
| 4557 | memset(priv->pshare->DM_SWAT_Table.SelectAntennaMap, 0, sizeof(priv->pshare->DM_SWAT_Table.SelectAntennaMap)); |
| 4558 | priv->pshare->DM_SWAT_Table.mapIndex = 0; |
| 4559 | |
| 4560 | #ifdef GPIO_ANT_SWITCH |
| 4561 | #ifdef CONFIG_RTL_92D_DMDP |
| 4562 | if(priv->pshare->wlandev_idx==0) |
| 4563 | priv->pshare->rf_ft_var.antHw_enable=0; |
| 4564 | else |
| 4565 | return; |
| 4566 | #endif |
| 4567 | // GPIO 45 : |
| 4568 | // GPIO_MOD => data port |
| 4569 | // GPIO_IO_SEL => output |
| 4570 | RTL_W32(GPIO_PIN_CTRL, 0x00300000| RTL_R32(GPIO_PIN_CTRL)); |
| 4571 | phy_set_bb_reg(priv, GPIO_PIN_CTRL, 0x3000, priv->pshare->DM_SWAT_Table.CurAntenna); |
| 4572 | RTL_W32(rFPGA0_XCD_RFParameter, RTL_R32(rFPGA0_XCD_RFParameter)| BIT(15)|BIT(16)); // enable ANTSEL |
| 4573 | |
| 4574 | #else |
| 4575 | RTL_W32(LEDCFG, RTL_R32(LEDCFG) | BIT(23) ); //enable LED[1:0] pin as ANTSEL |
| 4576 | |
| 4577 | if ( !priv->pshare->rf_ft_var.antSw_select) { |
| 4578 | RTL_W32(REG_FPGA0_XAB_RF_PARAMETER, RTL_R32(REG_FPGA0_XAB_RF_PARAMETER) | BIT(13) ); //select ANTESEL from path A |
| 4579 | RTL_W32(REG_FPGA0_XAB_RF_INTERFACE_SW, RTL_R32(REG_FPGA0_XAB_RF_INTERFACE_SW) | BIT(8)| BIT(9) ); // enable ANTSEL A as SW control |
| 4580 | RTL_W32(REG_FPGA0_XA_RF_INTERFACE_OE, (RTL_R32(REG_FPGA0_XA_RF_INTERFACE_OE) & ~(BIT(8)|BIT(9)))| 0x01<<8 ); // 0x01: left antenna, 0x02: right antenna |
| 4581 | } else { |
| 4582 | RTL_W32(REG_FPGA0_XAB_RF_PARAMETER, RTL_R32(REG_FPGA0_XAB_RF_PARAMETER) & ~ BIT(13) ); //select ANTESEL from path B |
| 4583 | RTL_W32(REG_FPGA0_XAB_RF_INTERFACE_SW, RTL_R32(REG_FPGA0_XAB_RF_INTERFACE_SW) | BIT(24)| BIT(25) ); // enable ANTSEL B as SW control |
| 4584 | RTL_W32(REG_FPGA0_XB_RF_INTERFACE_OE, (RTL_R32(REG_FPGA0_XB_RF_INTERFACE_OE) & ~(BIT(8)|BIT(9)))| 0x01<<8 ); // 0x01: left antenna, 0x02: right antenna |
| 4585 | } |
| 4586 | RTL_W16(rFPGA0_TxInfo, (RTL_R16(rFPGA0_TxInfo)&0xf0ff) | BIT(8) ); // b11-b8=0001 |
| 4587 | #endif |
| 4588 | |
| 4589 | // Move the timer initialization to InitializeVariables function. |
| 4590 | //platform_initialize_timer(Adapter, &pMgntInfo->SwAntennaSwitchTimer, (void *)dm_SW_AntennaSwitchCallback, NULL, "SwAntennaSwitchTimer"); |
| 4591 | } |
| 4592 | // |
| 4593 | // 20100514 Luke/Joseph: |
| 4594 | // Add new function for antenna diversity after link. |
| 4595 | // This is the main function of antenna diversity after link. |
| 4596 | // This function is called in HalDmWatchDog() and dm_SW_AntennaSwitchCallback(). |
| 4597 | // HalDmWatchDog() calls this function with SWAW_STEP_PEAK to initialize the antenna test. |
| 4598 | // In SWAW_STEP_PEAK, another antenna and a 500ms timer will be set for testing. |
| 4599 | // After 500ms, dm_SW_AntennaSwitchCallback() calls this function to compare the signal just |
| 4600 | // listened on the air with the RSSI of original antenna. |
| 4601 | // It chooses the antenna with better RSSI. |
| 4602 | // There is also a aged policy for error trying. Each error trying will cost more 5 seconds waiting |
| 4603 | // penalty to get next try. |
| 4604 | // |
| 4605 | void dm_SW_AntennaSwitch(struct rtl8192cd_priv *priv, char Step) |
| 4606 | { |
| 4607 | unsigned long long curTxOkCnt, curRxOkCnt; |
| 4608 | unsigned long long CurByteCnt, PreByteCnt; |
| 4609 | int Score_R=0, Score_L=0; |
| 4610 | int RSSI_R, RSSI_L; |
| 4611 | char nextAntenna=priv->pshare->DM_SWAT_Table.CurAntenna; |
| 4612 | int i; |
| 4613 | |
| 4614 | //1 1. Determine which condition should turn off Antenna Diversity |
| 4615 | |
| 4616 | #ifdef MP_TEST |
| 4617 | if ((OPMODE & WIFI_MP_STATE) || priv->pshare->rf_ft_var.mp_specific) |
| 4618 | return; |
| 4619 | #endif |
| 4620 | |
| 4621 | // if(!(GET_CHIP_VER(priv) == VERSION_8188C) || !priv->pshare->rf_ft_var.antSw_enable) |
| 4622 | // return; |
| 4623 | |
| 4624 | if((!priv->assoc_num) |
| 4625 | #ifdef PCIE_POWER_SAVING |
| 4626 | || (priv->pwr_state == L2) || (priv->pwr_state == L1) |
| 4627 | #endif |
| 4628 | ){ |
| 4629 | sw_ant_div_rest_after_link(priv); |
| 4630 | return; |
| 4631 | } |
| 4632 | |
| 4633 | // Handling step mismatch condition. |
| 4634 | // Peak step is not finished at last time. Recover the variable and check again. |
| 4635 | if( Step != priv->pshare->DM_SWAT_Table.try_flag) |
| 4636 | { |
| 4637 | sw_ant_div_rest_after_link(priv); |
| 4638 | } |
| 4639 | |
| 4640 | //1 2. Initialization: Select a assocaiated AP or STA as RSSI target |
| 4641 | if(priv->pshare->DM_SWAT_Table.try_flag == SWAW_STEP_RESET) { |
| 4642 | #ifdef CLIENT_MODE |
| 4643 | if((OPMODE & (WIFI_STATION_STATE | WIFI_ASOC_STATE)) == (WIFI_STATION_STATE | WIFI_ASOC_STATE)) { |
| 4644 | // Target: Infrastructure mode AP. |
| 4645 | priv->pshare->RSSI_target = NULL; |
| 4646 | } |
| 4647 | #endif |
| 4648 | resetSwAntDivVariable(priv); |
| 4649 | priv->pshare->DM_SWAT_Table.try_flag = SWAW_STEP_PEAK; |
| 4650 | return; |
| 4651 | } |
| 4652 | else { |
| 4653 | |
| 4654 | //1 3. Antenna Diversity |
| 4655 | |
| 4656 | //2 Calculate TX and RX OK bytes |
| 4657 | |
| 4658 | curTxOkCnt = (unsigned long long)priv->net_stats.tx_bytes - priv->pshare->lastTxOkCnt; |
| 4659 | curRxOkCnt = (unsigned long long)priv->net_stats.rx_bytes - priv->pshare->lastRxOkCnt; |
| 4660 | priv->pshare->lastTxOkCnt = (unsigned long long)priv->net_stats.tx_bytes; |
| 4661 | priv->pshare->lastRxOkCnt = (unsigned long long)priv->net_stats.rx_bytes; |
| 4662 | |
| 4663 | //2 Try State |
| 4664 | if(priv->pshare->DM_SWAT_Table.try_flag == SWAW_STEP_DETERMINE) { |
| 4665 | //3 1. Seperately caculate TX and RX OK byte counter for ant A and B |
| 4666 | if(priv->pshare->DM_SWAT_Table.CurAntenna == Antenna_R) { |
| 4667 | priv->pshare->TXByteCnt_R += curTxOkCnt; |
| 4668 | priv->pshare->RXByteCnt_R += curRxOkCnt; |
| 4669 | } else { |
| 4670 | priv->pshare->TXByteCnt_L += curTxOkCnt; |
| 4671 | priv->pshare->RXByteCnt_L += curRxOkCnt; |
| 4672 | } |
| 4673 | |
| 4674 | //3 2. Change anntena for testing |
| 4675 | if(priv->pshare->DM_SWAT_Table.rssi_trying != 0) { |
| 4676 | nextAntenna = (priv->pshare->DM_SWAT_Table.CurAntenna ) ^ Antenna_MAX; |
| 4677 | priv->pshare->DM_SWAT_Table.rssi_trying--; |
| 4678 | } |
| 4679 | |
| 4680 | //2 Try State End: Determine the best antenna |
| 4681 | |
| 4682 | if(priv->pshare->DM_SWAT_Table.rssi_trying==0) { |
| 4683 | nextAntenna = priv->pshare->DM_SWAT_Table.CurAntenna; |
| 4684 | priv->pshare->DM_SWAT_Table.mapIndex = (priv->pshare->DM_SWAT_Table.mapIndex+1)%SELANT_MAP_SIZE; |
| 4685 | |
| 4686 | //3 TP Mode: Determine the best antenna by throuhgput |
| 4687 | if(priv->pshare->DM_SWAT_Table.TestMode == TP_MODE) { |
| 4688 | |
| 4689 | |
| 4690 | |
| 4691 | //3 (1) Saperately caculate total byte count for two antennas |
| 4692 | if(priv->pshare->DM_SWAT_Table.CurAntenna == Antenna_R) { |
| 4693 | CurByteCnt = (priv->pshare->TXByteCnt_R + (priv->pshare->RXByteCnt_R<<1)); |
| 4694 | PreByteCnt = (priv->pshare->TXByteCnt_L + (priv->pshare->RXByteCnt_L<<1)); |
| 4695 | } else { |
| 4696 | CurByteCnt = (priv->pshare->TXByteCnt_L + (priv->pshare->RXByteCnt_L<<1)); |
| 4697 | PreByteCnt = (priv->pshare->TXByteCnt_R + (priv->pshare->RXByteCnt_R<<1)); |
| 4698 | } |
| 4699 | |
| 4700 | //3 (2) Throughput Normalization |
| 4701 | if(priv->pshare->TrafficLoad == TRAFFIC_HIGH) |
| 4702 | CurByteCnt >>=3; |
| 4703 | else if(priv->pshare->TrafficLoad == TRAFFIC_LOW) |
| 4704 | CurByteCnt >>=1; |
| 4705 | |
| 4706 | if(priv->pshare->DM_SWAT_Table.CurAntenna == Antenna_R) { |
| 4707 | priv->pshare->DM_SWAT_Table.SelectAntennaMap[0][priv->pshare->DM_SWAT_Table.mapIndex] = PreByteCnt; |
| 4708 | priv->pshare->DM_SWAT_Table.SelectAntennaMap[1][priv->pshare->DM_SWAT_Table.mapIndex] = CurByteCnt; |
| 4709 | } else { |
| 4710 | priv->pshare->DM_SWAT_Table.SelectAntennaMap[0][priv->pshare->DM_SWAT_Table.mapIndex] = CurByteCnt; |
| 4711 | priv->pshare->DM_SWAT_Table.SelectAntennaMap[1][priv->pshare->DM_SWAT_Table.mapIndex] = PreByteCnt; |
| 4712 | } |
| 4713 | |
| 4714 | Score_R = Score_L=0; |
| 4715 | for (i= 0; i<SELANT_MAP_SIZE; i++) { |
| 4716 | Score_L += priv->pshare->DM_SWAT_Table.SelectAntennaMap[0][i]; |
| 4717 | Score_R += priv->pshare->DM_SWAT_Table.SelectAntennaMap[1][i]; |
| 4718 | } |
| 4719 | |
| 4720 | nextAntenna = (Score_L > Score_R) ? Antenna_L : Antenna_R; |
| 4721 | |
| 4722 | if(priv->pshare->rf_ft_var.ant_dump&8) |
| 4723 | panic_printk("Mode TP, select Ant%d, [Score1=%d,Score2=%d]\n", nextAntenna, Score_L, Score_R); |
| 4724 | |
| 4725 | } |
| 4726 | |
| 4727 | //3 RSSI Mode: Determine the best anntena by RSSI |
| 4728 | else if(priv->pshare->DM_SWAT_Table.TestMode == RSSI_MODE) { |
| 4729 | |
| 4730 | //2 Saperately caculate average RSSI for two antennas |
| 4731 | RSSI_L = RSSI_R = 0; |
| 4732 | |
| 4733 | if(priv->pshare->RSSI_cnt_R > 0) |
| 4734 | RSSI_R = priv->pshare->RSSI_sum_R/priv->pshare->RSSI_cnt_R; |
| 4735 | if(priv->pshare->RSSI_cnt_L > 0) |
| 4736 | RSSI_L = priv->pshare->RSSI_sum_L/priv->pshare->RSSI_cnt_L; |
| 4737 | |
| 4738 | if(RSSI_L && RSSI_R ) |
| 4739 | nextAntenna = (RSSI_L > RSSI_R) ? Antenna_L : Antenna_R; |
| 4740 | |
| 4741 | if(priv->pshare->rf_ft_var.ant_dump&8) |
| 4742 | panic_printk("Mode RSSI, RSSI_R=%d(%d), RSSI_L=%d(%d), Ant=%d\n", |
| 4743 | RSSI_R, priv->pshare->RSSI_cnt_R, RSSI_L, priv->pshare->RSSI_cnt_L, nextAntenna); |
| 4744 | |
| 4745 | } |
| 4746 | |
| 4747 | //3 Reset state |
| 4748 | resetSwAntDivVariable(priv); |
| 4749 | priv->pshare->DM_SWAT_Table.try_flag = SWAW_STEP_PEAK; |
| 4750 | priv->pshare->RSSI_test = FALSE; |
| 4751 | } |
| 4752 | } |
| 4753 | |
| 4754 | //1 Normal State |
| 4755 | else if(priv->pshare->DM_SWAT_Table.try_flag == SWAW_STEP_PEAK) { |
| 4756 | |
| 4757 | //3 Determine TP/RSSI mode by TRX OK count |
| 4758 | if((curRxOkCnt+curTxOkCnt) > TP_MODE_THD) { |
| 4759 | //2 Determine current traffic is high or low |
| 4760 | if((curTxOkCnt+curRxOkCnt) > TRAFFIC_THRESHOLD) |
| 4761 | priv->pshare->TrafficLoad = TRAFFIC_HIGH; |
| 4762 | else |
| 4763 | priv->pshare->TrafficLoad = TRAFFIC_LOW; |
| 4764 | |
| 4765 | priv->pshare->DM_SWAT_Table.rssi_trying = 10; |
| 4766 | priv->pshare->DM_SWAT_Table.TestMode = TP_MODE; |
| 4767 | } else { |
| 4768 | |
| 4769 | int idx = 0; |
| 4770 | struct stat_info* pEntry = findNextSTA(priv, &idx); |
| 4771 | priv->pshare->RSSI_target = NULL; |
| 4772 | while(pEntry) { |
| 4773 | if(pEntry && pEntry->expire_to) { |
| 4774 | if(!priv->pshare->RSSI_target) |
| 4775 | priv->pshare->RSSI_target = pEntry; |
| 4776 | else if( pEntry->rssi < priv->pshare->RSSI_target->rssi ) |
| 4777 | priv->pshare->RSSI_target = pEntry; |
| 4778 | } |
| 4779 | pEntry = findNextSTA(priv, &idx); |
| 4780 | }; |
| 4781 | |
| 4782 | priv->pshare->DM_SWAT_Table.rssi_trying = 6; |
| 4783 | priv->pshare->DM_SWAT_Table.TestMode = RSSI_MODE; |
| 4784 | |
| 4785 | if(priv->pshare->RSSI_target == NULL) { |
| 4786 | sw_ant_div_rest_after_link(priv); |
| 4787 | return; |
| 4788 | } |
| 4789 | |
| 4790 | //3 reset state |
| 4791 | memset(priv->pshare->DM_SWAT_Table.SelectAntennaMap, 0, sizeof(priv->pshare->DM_SWAT_Table.SelectAntennaMap)); |
| 4792 | } |
| 4793 | |
| 4794 | //3 Begin to enter Try State |
| 4795 | nextAntenna = (priv->pshare->DM_SWAT_Table.CurAntenna ) ^ Antenna_MAX; |
| 4796 | priv->pshare->DM_SWAT_Table.try_flag = SWAW_STEP_DETERMINE; |
| 4797 | priv->pshare->RSSI_test = TRUE; |
| 4798 | |
| 4799 | //3 Reset variables |
| 4800 | resetSwAntDivVariable(priv); |
| 4801 | } |
| 4802 | } |
| 4803 | |
| 4804 | //1 4.Change TRX antenna |
| 4805 | if(nextAntenna != priv->pshare->DM_SWAT_Table.CurAntenna) { |
| 4806 | #if defined(CONFIG_PCI_HCI) |
| 4807 | if (GET_HCI_TYPE(priv) == RTL_HCI_PCIE) { |
| 4808 | #ifdef GPIO_ANT_SWITCH |
| 4809 | phy_set_bb_reg(priv, GPIO_PIN_CTRL, 0x3000, nextAntenna); |
| 4810 | #else |
| 4811 | if (!priv->pshare->rf_ft_var.antSw_select) |
| 4812 | phy_set_bb_reg(priv, REG_FPGA0_XA_RF_INTERFACE_OE, 0x300, nextAntenna); |
| 4813 | else |
| 4814 | phy_set_bb_reg(priv, REG_FPGA0_XB_RF_INTERFACE_OE, 0x300, nextAntenna); |
| 4815 | #endif |
| 4816 | |
| 4817 | //1 5.Reset Statistics |
| 4818 | priv->pshare->DM_SWAT_Table.CurAntenna = nextAntenna; |
| 4819 | } |
| 4820 | #endif |
| 4821 | #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) |
| 4822 | if (GET_HCI_TYPE(priv) == RTL_HCI_USB || GET_HCI_TYPE(priv) == RTL_HCI_SDIO) { |
| 4823 | notify_antenna_switch(priv, nextAntenna); |
| 4824 | } |
| 4825 | #endif |
| 4826 | } |
| 4827 | |
| 4828 | //1 6.Set next timer |
| 4829 | |
| 4830 | if(priv->pshare->DM_SWAT_Table.rssi_trying == 0) { |
| 4831 | return; |
| 4832 | } |
| 4833 | |
| 4834 | if(priv->pshare->DM_SWAT_Table.TestMode == RSSI_MODE) { |
| 4835 | rtk_mod_timer(&priv->pshare->swAntennaSwitchTimer, jiffies + RTL_MILISECONDS_TO_JIFFIES(400)); // 400 ms |
| 4836 | } else if(priv->pshare->DM_SWAT_Table.TestMode == TP_MODE) { |
| 4837 | |
| 4838 | if(priv->pshare->TrafficLoad == TRAFFIC_HIGH) { |
| 4839 | if(priv->pshare->DM_SWAT_Table.rssi_trying%2 == 0) |
| 4840 | rtk_mod_timer(&priv->pshare->swAntennaSwitchTimer, jiffies + RTL_MILISECONDS_TO_JIFFIES(10)); // 10 ms |
| 4841 | else |
| 4842 | rtk_mod_timer(&priv->pshare->swAntennaSwitchTimer, jiffies + RTL_MILISECONDS_TO_JIFFIES(80)); // 80 ms |
| 4843 | |
| 4844 | } else if(priv->pshare->TrafficLoad == TRAFFIC_LOW) { |
| 4845 | if(priv->pshare->DM_SWAT_Table.rssi_trying%2 == 0) |
| 4846 | rtk_mod_timer(&priv->pshare->swAntennaSwitchTimer, jiffies + RTL_MILISECONDS_TO_JIFFIES(40)); // 40 ms |
| 4847 | else |
| 4848 | rtk_mod_timer(&priv->pshare->swAntennaSwitchTimer, jiffies + RTL_MILISECONDS_TO_JIFFIES(80)); // 80 ms |
| 4849 | } |
| 4850 | } |
| 4851 | |
| 4852 | } |
| 4853 | |
| 4854 | |
| 4855 | static __always_inline void dm_SW_AntennaSwitchCallback(unsigned long task_priv) |
| 4856 | { |
| 4857 | struct rtl8192cd_priv *priv = (struct rtl8192cd_priv*)task_priv; |
| 4858 | #ifndef SMP_SYNC |
| 4859 | unsigned long flags = 0; |
| 4860 | #endif |
| 4861 | if (!(priv->drv_state & DRV_STATE_OPEN)) |
| 4862 | return; |
| 4863 | |
| 4864 | SAVE_INT_AND_CLI(flags); |
| 4865 | dm_SW_AntennaSwitch(priv, SWAW_STEP_DETERMINE); |
| 4866 | RESTORE_INT(flags); |
| 4867 | } |
| 4868 | DEFINE_TIMER_CALLBACK(dm_SW_AntennaSwitchCallback); |
| 4869 | |
| 4870 | void init_swAntennaSwitchTimer(struct rtl8192cd_priv *priv) |
| 4871 | { |
| 4872 | rtk_timer_setup(&(priv->pshare->swAntennaSwitchTimer), dm_SW_AntennaSwitchCallback, (unsigned long)priv, 0); |
| 4873 | } |
| 4874 | |
| 4875 | // |
| 4876 | // 20100514 Luke/Joseph: |
| 4877 | // This function is used to gather the RSSI information for antenna testing. |
| 4878 | // It selects the RSSI of the peer STA that we want to know. |
| 4879 | // |
| 4880 | void dm_SWAW_RSSI_Check(struct rtl8192cd_priv *priv, struct rx_frinfo *pfrinfo) |
| 4881 | { |
| 4882 | struct stat_info* pEntry = NULL; |
| 4883 | pEntry = get_stainfo(priv, GetAddr2Ptr(get_pframe(pfrinfo))); |
| 4884 | |
| 4885 | if((priv->pshare->RSSI_target==NULL)||(priv->pshare->RSSI_target==pEntry)) { |
| 4886 | //1 RSSI for SW Antenna Switch |
| 4887 | if(priv->pshare->DM_SWAT_Table.CurAntenna == Antenna_R) |
| 4888 | { |
| 4889 | priv->pshare->RSSI_sum_R += pfrinfo->rf_info.rssi; |
| 4890 | priv->pshare->RSSI_cnt_R++; |
| 4891 | } else { |
| 4892 | priv->pshare->RSSI_sum_L += pfrinfo->rf_info.rssi; |
| 4893 | priv->pshare->RSSI_cnt_L++; |
| 4894 | } |
| 4895 | } |
| 4896 | } |
| 4897 | |
| 4898 | #ifndef HW_ANT_SWITCH |
| 4899 | |
| 4900 | int diversity_antenna_select(struct rtl8192cd_priv *priv, unsigned char *data) |
| 4901 | { |
| 4902 | int ant = _atoi(data, 16); |
| 4903 | // if(GET_CHIP_VER(priv) != VERSION_8188C) |
| 4904 | // return 0; |
| 4905 | |
| 4906 | #ifdef PCIE_POWER_SAVING |
| 4907 | PCIeWakeUp(priv, POWER_DOWN_T0); |
| 4908 | #endif |
| 4909 | if(ant==Antenna_L || ant==Antenna_R) { |
| 4910 | #ifdef GPIO_ANT_SWITCH |
| 4911 | phy_set_bb_reg(priv, GPIO_PIN_CTRL, 0x3000, ant); |
| 4912 | #else |
| 4913 | if (!priv->pshare->rf_ft_var.antSw_select) |
| 4914 | phy_set_bb_reg(priv, REG_FPGA0_XA_RF_INTERFACE_OE, 0x300, ant); |
| 4915 | else |
| 4916 | phy_set_bb_reg(priv, REG_FPGA0_XB_RF_INTERFACE_OE, 0x300, ant); |
| 4917 | #endif |
| 4918 | priv->pshare->DM_SWAT_Table.CurAntenna = ant; |
| 4919 | priv->pshare->rf_ft_var.antSw_enable = 0; |
| 4920 | sw_ant_div_rest_after_link(priv); |
| 4921 | memset(priv->pshare->DM_SWAT_Table.SelectAntennaMap, 0, sizeof(priv->pshare->DM_SWAT_Table.SelectAntennaMap)); |
| 4922 | return 1; |
| 4923 | } else { |
| 4924 | priv->pshare->rf_ft_var.antSw_enable = 1; |
| 4925 | priv->pshare->lastTxOkCnt = (unsigned long long)priv->net_stats.tx_bytes; |
| 4926 | priv->pshare->lastRxOkCnt = (unsigned long long)priv->net_stats.rx_bytes; |
| 4927 | |
| 4928 | return 0; |
| 4929 | } |
| 4930 | } |
| 4931 | #endif |
| 4932 | #endif |
| 4933 | #if defined(HW_ANT_SWITCH) |
| 4934 | |
| 4935 | void dm_HW_AntennaSwitchInit(struct rtl8192cd_priv *priv) |
| 4936 | { |
| 4937 | if(!priv->pshare->rf_ft_var.antHw_enable) |
| 4938 | return; |
| 4939 | |
| 4940 | if (!(ODMPTR->support_ability & ODM_BB_ANT_DIV)) |
| 4941 | return; |
| 4942 | |
| 4943 | #ifdef SW_ANT_SWITCH |
| 4944 | priv->pshare->rf_ft_var.antSw_enable =0; |
| 4945 | #endif |
| 4946 | |
| 4947 | // if (GET_CHIP_VER(priv) == VERSION_8188C) |
| 4948 | if(get_rf_mimo_mode(priv)== RF_1T1R) |
| 4949 | priv->pshare->rf_ft_var.antSw_select = 0; |
| 4950 | |
| 4951 | if ( !priv->pshare->rf_ft_var.antSw_select) { |
| 4952 | RTL_W32(REG_FPGA0_XAB_RF_PARAMETER, RTL_R32(REG_FPGA0_XAB_RF_PARAMETER) | BIT(13) ); //select ANTESEL from path A |
| 4953 | RTL_W32(REG_FPGA0_XAB_RF_INTERFACE_SW, RTL_R32(REG_FPGA0_XAB_RF_INTERFACE_SW) & ~(BIT(8)| BIT(9)) ); // ANTSEL as HW control |
| 4954 | RTL_W32(REG_FPGA0_XA_RF_INTERFACE_OE, (RTL_R32(REG_FPGA0_XA_RF_INTERFACE_OE) & ~(BIT(8)|BIT(9)))| 0x01<<8 ); // 0x01: left antenna, 0x02: right antenna |
| 4955 | RTL_W8(0xc50, RTL_R8(0xc50) | BIT(7)); // Enable Hardware antenna switch |
| 4956 | RTL_W32(0xc54, RTL_R32(0xc54) | BIT(23) ); // Decide final antenna by comparing 2 antennas' pwdb |
| 4957 | } else { |
| 4958 | RTL_W32(REG_FPGA0_XAB_RF_PARAMETER, RTL_R32(REG_FPGA0_XAB_RF_PARAMETER) & ~ BIT(13) ); //select ANTESEL from path B |
| 4959 | RTL_W32(REG_FPGA0_XAB_RF_INTERFACE_SW, RTL_R32(REG_FPGA0_XAB_RF_INTERFACE_SW) & ~(BIT(24)| BIT(25)) ); // ANTSEL as HW control |
| 4960 | RTL_W32(REG_FPGA0_XB_RF_INTERFACE_OE, (RTL_R32(REG_FPGA0_XB_RF_INTERFACE_OE) & ~(BIT(8)|BIT(9)))| 0x01<<8 ); // 0x01: left antenna, 0x02: right antenna |
| 4961 | #if defined(CONFIG_RTL_92C_SUPPORT) || defined(CONFIG_RTL_92D_SUPPORT) |
| 4962 | if ( |
| 4963 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 4964 | (GET_CHIP_VER(priv)==VERSION_8192C) || (GET_CHIP_VER(priv)==VERSION_8188C) |
| 4965 | #endif |
| 4966 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 4967 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 4968 | || |
| 4969 | #endif |
| 4970 | (GET_CHIP_VER(priv)==VERSION_8192D) |
| 4971 | #endif |
| 4972 | ) |
| 4973 | RTL_W8(0xc58, RTL_R8(0xc58) | BIT(7)); // Enable Hardware antenna switch |
| 4974 | #endif |
| 4975 | RTL_W32(0xc5C, RTL_R32(0xc5c) | BIT(23) ); // Decide final antenna by comparing 2 antennas' pwdb |
| 4976 | } |
| 4977 | |
| 4978 | priv->pshare->rf_ft_var.CurAntenna = 0; |
| 4979 | |
| 4980 | RTL_W32(LEDCFG, RTL_R32(LEDCFG) | BIT(23) ); //enable LED[1:0] pin as ANTSEL |
| 4981 | RTL_W16(0xca4, (RTL_R16(0xca4) & ~(0xfff))|0x0c0); // Pwdb threshold=12dB |
| 4982 | RTL_W32(0x874, RTL_R32(0x874) & ~ BIT(23) ); // No update ANTSEL during GNT_BT=1 |
| 4983 | RTL_W16(rFPGA0_TxInfo, (RTL_R16(rFPGA0_TxInfo)&0xf0ff) | BIT(8) ); // b11-b8=0001 |
| 4984 | RTL_W32(0x80c, RTL_R32(0x80c) | BIT(21) ); // assign antenna by tx desc |
| 4985 | |
| 4986 | // CCK setting |
| 4987 | RTL_W8(0xa01, RTL_R8(0xa01) | BIT(7)); // enable hw ant diversity |
| 4988 | RTL_W8(0xa0c, (RTL_R8(0xa0c) & 0xe0) | 0x0f ); // b4=0, b3:0 = 1111 32 sample |
| 4989 | RTL_W8(0xa11, RTL_R8(0xa11) | BIT(5)); // do not change default optional antenna |
| 4990 | RTL_W8(0xa14, (RTL_R8(0xa14) & 0xe0) | 0x08 ); // default : optional = 1:1 |
| 4991 | #ifdef GPIO_ANT_SWITCH |
| 4992 | phy_set_bb_reg(priv, rFPGA0_XCD_RFParameter, 0x40000000, 0x01); // enable ANTSEL |
| 4993 | #endif |
| 4994 | |
| 4995 | } |
| 4996 | |
| 4997 | void setRxIdleAnt(struct rtl8192cd_priv *priv, char Ant) |
| 4998 | { |
| 4999 | if(priv->pshare->rf_ft_var.CurAntenna != Ant) { |
| 5000 | if(Ant) { |
| 5001 | RTL_W32(0x858, 0x65a965a9); |
| 5002 | // RTL_W8(0x6d8, RTL_R8(0x6d8) | BIT(6) ); |
| 5003 | } |
| 5004 | else { |
| 5005 | RTL_W32(0x858, 0x569a569a); |
| 5006 | // RTL_W8(0x6d8, RTL_R8(0x6d8) & (~ BIT(6))); |
| 5007 | } |
| 5008 | priv->pshare->rf_ft_var.CurAntenna = Ant; |
| 5009 | } |
| 5010 | } |
| 5011 | |
| 5012 | void dm_STA_Ant_Select(struct rtl8192cd_priv *priv, struct stat_info *pstat) |
| 5013 | { |
| 5014 | int ScoreA=0, ScoreB=0, i, nextAnt= pstat->CurAntenna, idleAnt=priv->pshare->rf_ft_var.CurAntenna; |
| 5015 | |
| 5016 | if((priv->pshare->rf_ft_var.CurAntenna & 0x80) |
| 5017 | || ((pstat->hwRxAntSel[0] + pstat->hwRxAntSel[1])==0 && (pstat->cckPktCount[0] + pstat->cckPktCount[1])<10) ) |
| 5018 | return; |
| 5019 | |
| 5020 | for(i=0; i<2; i++) { |
| 5021 | if(pstat->cckPktCount[i]==0 && pstat->hwRxAntSel[i]==0) |
| 5022 | pstat->AntRSSI[i] = 0; |
| 5023 | } |
| 5024 | |
| 5025 | if(pstat->hwRxAntSel[0] || pstat->hwRxAntSel[1]) { |
| 5026 | ScoreA = pstat->hwRxAntSel[0]; |
| 5027 | ScoreB = pstat->hwRxAntSel[1]; |
| 5028 | |
| 5029 | if(ScoreA != ScoreB) { |
| 5030 | if(ScoreA > ScoreB) |
| 5031 | nextAnt = 0; |
| 5032 | else |
| 5033 | nextAnt = 1; |
| 5034 | } |
| 5035 | } else { |
| 5036 | ScoreA = pstat->cckPktCount[0]; |
| 5037 | ScoreB = pstat->cckPktCount[1]; |
| 5038 | |
| 5039 | if(ScoreA > 5*ScoreB) |
| 5040 | nextAnt = 0; |
| 5041 | else if(ScoreB > 5*ScoreA) |
| 5042 | nextAnt = 1; |
| 5043 | else if(ScoreA > ScoreB) |
| 5044 | nextAnt = 1; |
| 5045 | else if(ScoreB > ScoreA) |
| 5046 | nextAnt = 0; |
| 5047 | } |
| 5048 | |
| 5049 | pstat->CurAntenna = nextAnt; |
| 5050 | |
| 5051 | if(priv->pshare->rf_ft_var.ant_dump&2) { |
| 5052 | panic_printk("id=%d, OFDM/CCK: (%d, %d/%d, %d), RSSI:(%d, %d), ant=%d, RxIdle=%d\n", |
| 5053 | pstat->cmn_info.aid, |
| 5054 | pstat->hwRxAntSel[1], |
| 5055 | pstat->hwRxAntSel[0], |
| 5056 | pstat->cckPktCount[1], |
| 5057 | pstat->cckPktCount[0], |
| 5058 | pstat->AntRSSI[1], |
| 5059 | pstat->AntRSSI[0], |
| 5060 | (pstat->CurAntenna==0 ? 2: 1) |
| 5061 | ,((priv->pshare->rf_ft_var.CurAntenna&1)==0 ? 2 : 1) |
| 5062 | ); |
| 5063 | } |
| 5064 | |
| 5065 | if(pstat->AntRSSI[idleAnt]==0) |
| 5066 | pstat->AntRSSI[idleAnt] = pstat->AntRSSI[idleAnt^1]; |
| 5067 | |
| 5068 | // reset variables |
| 5069 | pstat->hwRxAntSel[1] = pstat->hwRxAntSel[0] =0; |
| 5070 | pstat->cckPktCount[1]= pstat->cckPktCount[0] =0; |
| 5071 | |
| 5072 | } |
| 5073 | |
| 5074 | void dm_HW_IdleAntennaSelect(struct rtl8192cd_priv *priv) |
| 5075 | { |
| 5076 | struct stat_info *pstat, *pstat_min=NULL; |
| 5077 | struct list_head *phead, *plist; |
| 5078 | int rssi_min= 0xff, i; |
| 5079 | #ifdef SMP_SYNC |
| 5080 | unsigned long flags = 0; |
| 5081 | #endif |
| 5082 | |
| 5083 | if(priv->pshare->rf_ft_var.CurAntenna & 0x80) |
| 5084 | return; |
| 5085 | |
| 5086 | phead = &priv->asoc_list; |
| 5087 | |
| 5088 | SMP_LOCK_ASOC_LIST(flags); |
| 5089 | |
| 5090 | plist = phead->next; |
| 5091 | while(plist != phead) { |
| 5092 | pstat = list_entry(plist, struct stat_info, asoc_list); |
| 5093 | plist = plist->next; |
| 5094 | |
| 5095 | if((pstat->expire_to) && (pstat->AntRSSI[0] || pstat->AntRSSI[1])) { |
| 5096 | int rssi = (pstat->AntRSSI[0] < pstat->AntRSSI[1]) ? pstat->AntRSSI[0] : pstat->AntRSSI[1]; |
| 5097 | if((!pstat_min) || ( rssi < rssi_min) ) { |
| 5098 | pstat_min = pstat; |
| 5099 | rssi_min = rssi; |
| 5100 | } |
| 5101 | } |
| 5102 | }; |
| 5103 | |
| 5104 | SMP_UNLOCK_ASOC_LIST(flags); |
| 5105 | |
| 5106 | if(pstat_min) |
| 5107 | setRxIdleAnt(priv, pstat_min->CurAntenna); |
| 5108 | |
| 5109 | |
| 5110 | #ifdef TX_SHORTCUT |
| 5111 | if (!priv->pmib->dot11OperationEntry.disable_txsc) { |
| 5112 | SMP_LOCK_ASOC_LIST(flags); |
| 5113 | |
| 5114 | plist = phead->next; |
| 5115 | while(plist != phead) { |
| 5116 | pstat = list_entry(plist, struct stat_info, asoc_list); |
| 5117 | plist = plist->next; |
| 5118 | |
| 5119 | if(pstat->expire_to) { |
| 5120 | for (i=0; i<MAX_TXSC_ENTRY; i++) { |
| 5121 | struct tx_desc *pdesc= &(pstat->tx_sc_ent[i].hwdesc1); |
| 5122 | pdesc->Dword2 &= set_desc(~ (BIT(24)|BIT(25))); |
| 5123 | if((pstat->CurAntenna^priv->pshare->rf_ft_var.CurAntenna)&1) |
| 5124 | pdesc->Dword2 |= set_desc(BIT(24)|BIT(25)); |
| 5125 | #ifdef CONFIG_PCI_HCI |
| 5126 | if (GET_HCI_TYPE(priv) == RTL_HCI_PCIE) { |
| 5127 | pdesc= &(pstat->tx_sc_ent[i].hwdesc2); |
| 5128 | pdesc->Dword2 &= set_desc(~ (BIT(24)|BIT(25))); |
| 5129 | if((pstat->CurAntenna^priv->pshare->rf_ft_var.CurAntenna)&1) |
| 5130 | pdesc->Dword2 |= set_desc(BIT(24)|BIT(25)); |
| 5131 | } |
| 5132 | #endif |
| 5133 | } |
| 5134 | } |
| 5135 | }; |
| 5136 | |
| 5137 | SMP_UNLOCK_ASOC_LIST(flags); |
| 5138 | } |
| 5139 | #endif |
| 5140 | |
| 5141 | } |
| 5142 | |
| 5143 | int diversity_antenna_select(struct rtl8192cd_priv *priv, unsigned char *data) |
| 5144 | { |
| 5145 | int ant = _atoi(data, 16); |
| 5146 | |
| 5147 | #ifdef PCIE_POWER_SAVING |
| 5148 | PCIeWakeUp(priv, POWER_DOWN_T0); |
| 5149 | #endif |
| 5150 | |
| 5151 | if (ant==Antenna_L || ant==Antenna_R) { |
| 5152 | |
| 5153 | #ifdef GPIO_ANT_SWITCH |
| 5154 | if(priv->pshare->rf_ft_var.antSw_enable) { |
| 5155 | phy_set_bb_reg(priv, GPIO_PIN_CTRL, 0x3000, ant); |
| 5156 | } else |
| 5157 | #endif |
| 5158 | { |
| 5159 | if ( !priv->pshare->rf_ft_var.antSw_select) { |
| 5160 | RTL_W32(REG_FPGA0_XAB_RF_INTERFACE_SW, RTL_R32(REG_FPGA0_XAB_RF_INTERFACE_SW) | BIT(8)| BIT(9) ); // ANTSEL A as SW control |
| 5161 | RTL_W8(0xc50, RTL_R8(0xc50) & (~ BIT(7))); // rx OFDM SW control |
| 5162 | phy_set_bb_reg(priv, REG_FPGA0_XA_RF_INTERFACE_OE, 0x300, ant); |
| 5163 | } else { |
| 5164 | RTL_W32(REG_FPGA0_XAB_RF_INTERFACE_SW, RTL_R32(REG_FPGA0_XAB_RF_INTERFACE_SW) | BIT(24)| BIT(25) ); // ANTSEL B as HW control |
| 5165 | phy_set_bb_reg(priv, REG_FPGA0_XB_RF_INTERFACE_OE, 0x300, ant); |
| 5166 | #if defined(CONFIG_RTL_92C_SUPPORT) || defined(CONFIG_RTL_92D_SUPPORT) |
| 5167 | if ( |
| 5168 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 5169 | (GET_CHIP_VER(priv)==VERSION_8192C) || (GET_CHIP_VER(priv)==VERSION_8188C) |
| 5170 | #endif |
| 5171 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 5172 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 5173 | || |
| 5174 | #endif |
| 5175 | (GET_CHIP_VER(priv)==VERSION_8192D) |
| 5176 | #endif |
| 5177 | ) |
| 5178 | RTL_W8(0xc58, RTL_R8(0xc58) & (~ BIT(7))); // rx OFDM SW control |
| 5179 | #endif |
| 5180 | } |
| 5181 | RTL_W8(0xa01, RTL_R8(0xa01) & (~ BIT(7))); // rx CCK SW control |
| 5182 | RTL_W32(0x80c, RTL_R32(0x80c) & (~ BIT(21))); // select ant by tx desc |
| 5183 | RTL_W32(0x858, 0x569a569a); |
| 5184 | } |
| 5185 | #ifdef HW_ANT_SWITCH |
| 5186 | if(HW_DIV_ENABLE) |
| 5187 | priv->pshare->rf_ft_var.antHw_enable = BIT(5); |
| 5188 | #endif |
| 5189 | priv->pshare->rf_ft_var.CurAntenna = (ant%2); |
| 5190 | #ifdef SW_ANT_SWITCH |
| 5191 | if(SW_DIV_ENABLE) |
| 5192 | priv->pshare->rf_ft_var.antSw_enable = BIT(5); |
| 5193 | priv->pshare->DM_SWAT_Table.CurAntenna = ant; |
| 5194 | priv->pshare->RSSI_test =0; |
| 5195 | #endif |
| 5196 | } |
| 5197 | else if(ant==0){ |
| 5198 | #ifdef GPIO_ANT_SWITCH |
| 5199 | if(priv->pshare->rf_ft_var.antHw_enable) |
| 5200 | #endif |
| 5201 | { |
| 5202 | if (!priv->pshare->rf_ft_var.antSw_select) { |
| 5203 | RTL_W32(REG_FPGA0_XAB_RF_INTERFACE_SW, RTL_R32(REG_FPGA0_XAB_RF_INTERFACE_SW) & ~(BIT(8)| BIT(9)) ); |
| 5204 | RTL_W8(0xc50, RTL_R8(0xc50) | BIT(7)); // OFDM HW control |
| 5205 | } else { |
| 5206 | RTL_W32(REG_FPGA0_XAB_RF_INTERFACE_SW, RTL_R32(REG_FPGA0_XAB_RF_INTERFACE_SW) & ~(BIT(24)| BIT(25)) ); |
| 5207 | #if defined(CONFIG_RTL_92C_SUPPORT) || defined(CONFIG_RTL_92D_SUPPORT) |
| 5208 | if ( |
| 5209 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 5210 | (GET_CHIP_VER(priv)==VERSION_8192C) || (GET_CHIP_VER(priv)==VERSION_8188C) |
| 5211 | #endif |
| 5212 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 5213 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 5214 | || |
| 5215 | #endif |
| 5216 | (GET_CHIP_VER(priv)==VERSION_8192D) |
| 5217 | #endif |
| 5218 | ) |
| 5219 | RTL_W8(0xc58, RTL_R8(0xc58) | BIT(7)); // OFDM HW control |
| 5220 | #endif |
| 5221 | } |
| 5222 | RTL_W8(0xa01, RTL_R8(0xa01) | BIT(7)); // CCK HW control |
| 5223 | RTL_W32(0x80c, RTL_R32(0x80c) | BIT(21) ); // by tx desc |
| 5224 | priv->pshare->rf_ft_var.CurAntenna = 0; |
| 5225 | RTL_W32(0x858, 0x569a569a); |
| 5226 | priv->pshare->rf_ft_var.antHw_enable = 1; |
| 5227 | #ifdef SW_ANT_SWITCH |
| 5228 | priv->pshare->rf_ft_var.antSw_enable = 0; |
| 5229 | priv->pshare->RSSI_test =0; |
| 5230 | #endif |
| 5231 | } |
| 5232 | #ifdef SW_ANT_SWITCH |
| 5233 | if(priv->pshare->rf_ft_var.antSw_enable) { |
| 5234 | dm_SW_AntennaSwitchInit(priv); |
| 5235 | RTL_W32(0x858, 0x569a569a); |
| 5236 | priv->pshare->lastTxOkCnt = (unsigned long long)priv->net_stats.tx_bytes; |
| 5237 | priv->pshare->lastRxOkCnt = (unsigned long long)priv->net_stats.rx_bytes; |
| 5238 | priv->pshare->rf_ft_var.antHw_enable = 0; |
| 5239 | priv->pshare->rf_ft_var.antSw_enable = 1; |
| 5240 | } |
| 5241 | #endif |
| 5242 | |
| 5243 | } |
| 5244 | #if defined(SW_ANT_SWITCH) && !defined(GPIO_ANT_SWITCH) |
| 5245 | else if(ant==3) { |
| 5246 | if(!priv->pshare->rf_ft_var.antSw_enable) { |
| 5247 | dm_SW_AntennaSwitchInit(priv); |
| 5248 | RTL_W32(0x858, 0x569a569a); |
| 5249 | priv->pshare->lastTxOkCnt = (unsigned long long)priv->net_stats.tx_bytes; |
| 5250 | priv->pshare->lastRxOkCnt = (unsigned long long)priv->net_stats.rx_bytes; |
| 5251 | } |
| 5252 | #ifdef CONFIG_RTL_88E_SUPPORT |
| 5253 | if (GET_CHIP_VER(priv)==VERSION_8188E) { |
| 5254 | RTL_W8(0xc50, RTL_R8(0xc50) & (~ BIT(7))); // rx OFDM SW control |
| 5255 | } else |
| 5256 | #endif |
| 5257 | { |
| 5258 | if ( !priv->pshare->rf_ft_var.antSw_select) |
| 5259 | RTL_W8(0xc50, RTL_R8(0xc50) & (~ BIT(7))); // rx OFDM SW control |
| 5260 | else |
| 5261 | RTL_W8(0xc58, RTL_R8(0xc58) & (~ BIT(7))); // rx OFDM SW control |
| 5262 | } |
| 5263 | |
| 5264 | RTL_W8(0xa01, RTL_R8(0xa01) & (~ BIT(7))); // rx CCK SW control |
| 5265 | RTL_W32(0x80c, RTL_R32(0x80c) & (~ BIT(21))); // select ant by tx desc |
| 5266 | priv->pshare->rf_ft_var.antHw_enable = 0; |
| 5267 | priv->pshare->rf_ft_var.antSw_enable = 1; |
| 5268 | |
| 5269 | } |
| 5270 | #endif |
| 5271 | |
| 5272 | return 1; |
| 5273 | } |
| 5274 | |
| 5275 | #endif |
| 5276 | |
| 5277 | //3 ============================================================ |
| 5278 | //3 Dynamic Noise Control |
| 5279 | //3 ============================================================ |
| 5280 | |
| 5281 | #if defined(CONFIG_RTL_92D_SUPPORT) && defined(CONFIG_RTL_NOISE_CONTROL) |
| 5282 | static __always_inline void dnc_timer(unsigned long task_priv) |
| 5283 | { |
| 5284 | struct rtl8192cd_priv *priv = (struct rtl8192cd_priv *)task_priv; |
| 5285 | struct stat_info *pstat = NULL; |
| 5286 | unsigned int set_timer = 0; |
| 5287 | unsigned long flags; |
| 5288 | |
| 5289 | if (!(priv->drv_state & DRV_STATE_OPEN)) |
| 5290 | return; |
| 5291 | |
| 5292 | if (rtk_timer_pending(&priv->dnc_timer)) |
| 5293 | rtk_del_timer_sync(&priv->dnc_timer); |
| 5294 | |
| 5295 | #ifdef PCIE_POWER_SAVING |
| 5296 | if ((priv->pwr_state == L2) || (priv->pwr_state == L1)) |
| 5297 | return; |
| 5298 | #endif |
| 5299 | |
| 5300 | if (priv->pmib->dot11RFEntry.phyBandSelect == PHY_BAND_5G) { |
| 5301 | //phy_set_bb_reg(priv, 0xb30, bMaskDWord, 0x00a00000); |
| 5302 | phy_set_bb_reg(priv, 0x870, bMaskDWord, 0x07600760); |
| 5303 | phy_set_bb_reg(priv, 0xc50, bMaskByte0, 0x20); |
| 5304 | phy_set_bb_reg(priv, 0xc58, bMaskByte0, 0x20); |
| 5305 | } |
| 5306 | } |
| 5307 | DEFINE_TIMER_CALLBACK(dnc_timer); |
| 5308 | |
| 5309 | void init_dnc_timer(struct rtl8192cd_priv *priv) |
| 5310 | { |
| 5311 | rtk_timer_setup(&(priv->dnc_timer), dnc_timer, (unsigned long)priv, 0); |
| 5312 | } |
| 5313 | #endif // defined(CONFIG_RTL_92D_SUPPORT) && defined(CONFIG_RTL_NOISE_CONTROL) |
| 5314 | |
| 5315 | |
| 5316 | //3 ============================================================ |
| 5317 | //3 Leaving STA check |
| 5318 | //3 ============================================================ |
| 5319 | #if 0 |
| 5320 | //#if defined(DETECT_STA_EXISTANCE) //&& (defined(CONFIG_RTL_92C_SUPPORT) || defined(CONFIG_RTL_92D_SUPPORT)) |
| 5321 | // Check for STA existance. If STA disappears, disconnect it. Added by Annie, 2010-08-10. |
| 5322 | void DetectSTAExistance(struct rtl8192cd_priv *priv, struct tx_rpt *report, struct stat_info *pstat) |
| 5323 | { |
| 5324 | unsigned char tmpbuf[16]; |
| 5325 | |
| 5326 | // Parameters |
| 5327 | const unsigned int maxTxFailCnt = 300; // MAX Tx fail packet count |
| 5328 | const unsigned int minTxFailCnt = 30; // MIN Tx fail packet count; this value should be less than maxTxFailCnt. |
| 5329 | const unsigned int txFailSecThr= 3; // threshold of Tx Fail Time (in second) |
| 5330 | |
| 5331 | // Temporarily change Retry Limit when TxFail. (tfrl: TxFailRetryLimit) |
| 5332 | const unsigned char TFRL = 7; // New Retry Limit value |
| 5333 | const unsigned char TFRL_FailCnt = 2; // Tx Fail Count threshold to set Retry Limit |
| 5334 | const unsigned char TFRL_SetTime = 2; // Time to set Retry Limit (in second) |
| 5335 | const unsigned char TFRL_RcvTime = 10; // Time to recover Retry Limit (in second) |
| 5336 | |
| 5337 | if(OPMODE & WIFI_STATION_STATE) |
| 5338 | return; |
| 5339 | |
| 5340 | if( report->txok != 0 ) |
| 5341 | { // Reset Counter |
| 5342 | pstat->tx_conti_fail_cnt = 0; |
| 5343 | pstat->tx_last_good_time = priv->up_time; |
| 5344 | pstat->leave = 0; |
| 5345 | } |
| 5346 | else if( report->txfail != 0 ) |
| 5347 | { |
| 5348 | pstat->tx_conti_fail_cnt += report->txfail; |
| 5349 | DEBUG_WARN( "detect: txfail=%d, tx_conti_fail_cnt=%d\n", report->txfail, pstat->tx_conti_fail_cnt ); |
| 5350 | |
| 5351 | if( CHIP_VER_92X_SERIES(priv) && (priv->up_time >= (pstat->tx_last_good_time+TFRL_SetTime)) && |
| 5352 | pstat->tx_conti_fail_cnt >= TFRL_FailCnt && |
| 5353 | #if defined(CONFIG_RTL8672) || defined (NOT_RTK_BSP) |
| 5354 | !pstat->ht_cap_len && // legacy rate only |
| 5355 | #endif |
| 5356 | !priv->pshare->bRLShortened ) |
| 5357 | { // Shorten retry limit, because AP spending too much time to send out g mode STA pending packets in HW queue. |
| 5358 | RTL_W16(RL, (TFRL&SRL_Mask)<<SRL_SHIFT|(TFRL&LRL_Mask)<<LRL_SHIFT); |
| 5359 | priv->pshare->bRLShortened = TRUE; |
| 5360 | DEBUG_WARN( "== Shorten RetryLimit to 0x%04X ==\n", RTL_R16(RL) ); |
| 5361 | } |
| 5362 | |
| 5363 | if( (pstat->tx_conti_fail_cnt >= maxTxFailCnt) || |
| 5364 | (pstat->tx_conti_fail_cnt >= minTxFailCnt && priv->up_time >= (pstat->tx_last_good_time+txFailSecThr) ) |
| 5365 | ) |
| 5366 | { // This STA is considered as disappeared, so delete it. |
| 5367 | DEBUG_WARN( "** tx_conti_fail_cnt=%d (min=%d,max=%d)\n", pstat->tx_conti_fail_cnt, minTxFailCnt, maxTxFailCnt); |
| 5368 | DEBUG_WARN( "** tx_last_good_time=%d, up_time=%d (Thr:%d)\n", (int)pstat->tx_last_good_time, (int)priv->up_time, txFailSecThr ); |
| 5369 | DEBUG_WARN( "AP is going to del_sta %02X:%02X:%02X:%02X:%02X:%02X\n", pstat->cmn_info.mac_addr[0],pstat->cmn_info.mac_addr[1],pstat->cmn_info.mac_addr[2],pstat->cmn_info.mac_addr[3],pstat->cmn_info.mac_addr[4],pstat->cmn_info.mac_addr[5] ); |
| 5370 | |
| 5371 | sprintf((char *)tmpbuf, "%02x%02x%02x%02x%02x%02x", pstat->cmn_info.mac_addr[0],pstat->cmn_info.mac_addr[1],pstat->cmn_info.mac_addr[2],pstat->cmn_info.mac_addr[3],pstat->cmn_info.mac_addr[4],pstat->cmn_info.mac_addr[5]); |
| 5372 | |
| 5373 | // del_sta(priv, tmpbuf); |
| 5374 | ++(pstat->leave); |
| 5375 | |
| 5376 | if(CHIP_VER_92X_SERIES(priv) { |
| 5377 | if (rtk_timer_pending(&priv->pshare->rl_recover_timer)) |
| 5378 | rtk_del_timer_sync (&priv->pshare->rl_recover_timer); |
| 5379 | rtk_mod_timer(&priv->pshare->rl_recover_timer, jiffies + EXPIRE_TO*TFRL_RcvTime); |
| 5380 | } |
| 5381 | |
| 5382 | // Reset Counter |
| 5383 | pstat->tx_conti_fail_cnt = 0; |
| 5384 | pstat->tx_last_good_time = priv->up_time; |
| 5385 | } |
| 5386 | } |
| 5387 | } |
| 5388 | |
| 5389 | // Timer callback function to recover hardware retry limit register. Added by Annie, 2010-08-10. |
| 5390 | #if defined(__KERNEL__) || defined(__OSK__) |
| 5391 | void RetryLimitRecovery(unsigned long task_priv) |
| 5392 | #elif defined(__ECOS) |
| 5393 | void RetryLimitRecovery(void *task_priv) |
| 5394 | #endif |
| 5395 | { |
| 5396 | struct rtl8192cd_priv *priv = (struct rtl8192cd_priv *)task_priv; |
| 5397 | if( priv->pshare->bRLShortened ) |
| 5398 | { |
| 5399 | RTL_W16(RL, priv->pshare->RL_setting); |
| 5400 | priv->pshare->bRLShortened = FALSE; |
| 5401 | DEBUG_WARN( "== Recover RetryLimit to 0x%04X ==\n", RTL_R16(RL) ); |
| 5402 | } |
| 5403 | } |
| 5404 | |
| 5405 | // Chack STA leaving status; per interface. Added by Annie, 2010-08-10. |
| 5406 | unsigned char NoLeavingSTA(struct rtl8192cd_priv *priv) |
| 5407 | { |
| 5408 | unsigned char bStaAllOK = TRUE; |
| 5409 | struct list_head *phead, *plist; |
| 5410 | struct stat_info *pstat; |
| 5411 | |
| 5412 | phead = &priv->asoc_list; |
| 5413 | if (!netif_running(priv->dev) || list_empty(phead)) |
| 5414 | return bStaAllOK; |
| 5415 | |
| 5416 | plist = phead->next; |
| 5417 | while (plist != phead) { |
| 5418 | pstat = list_entry(plist, struct stat_info, asoc_list); |
| 5419 | if( pstat->tx_conti_fail_cnt != 0 ) { |
| 5420 | bStaAllOK = FALSE; |
| 5421 | break; |
| 5422 | } |
| 5423 | plist = plist->next; |
| 5424 | } |
| 5425 | |
| 5426 | return bStaAllOK; |
| 5427 | } |
| 5428 | |
| 5429 | // Chack STA leaving status for all active interface and recover retry limit register value. Added by Annie, 2010-08-10. |
| 5430 | void LeavingSTA_RLCheck(struct rtl8192cd_priv *priv) |
| 5431 | { |
| 5432 | unsigned char bIfAllOK = TRUE; |
| 5433 | static int AllOKTimes = 0; |
| 5434 | #ifdef MBSSID |
| 5435 | int i; |
| 5436 | #endif |
| 5437 | // Parameter |
| 5438 | const unsigned char TFRL_RcvTime = 10; // Time to recover Retry Limit (in second) |
| 5439 | |
| 5440 | if( !NoLeavingSTA(priv) ) |
| 5441 | bIfAllOK = FALSE; |
| 5442 | |
| 5443 | #ifdef UNIVERSAL_REPEATER |
| 5444 | if (IS_ROOT_INTERFACE(priv) && GET_VXD_PRIV(priv) ) { |
| 5445 | if( !NoLeavingSTA(GET_VXD_PRIV(priv)) ) |
| 5446 | bIfAllOK = FALSE; |
| 5447 | } |
| 5448 | #endif |
| 5449 | |
| 5450 | #ifdef MBSSID |
| 5451 | if (IS_ROOT_INTERFACE(priv)) { |
| 5452 | if (GET_ROOT(priv)->pmib->miscEntry.vap_enable) { |
| 5453 | for (i=0; i<RTL8192CD_NUM_VWLAN; i++) { |
| 5454 | if (IS_DRV_OPEN(priv->pvap_priv[i])) { |
| 5455 | if( !NoLeavingSTA(priv->pvap_priv[i]) ) |
| 5456 | bIfAllOK = FALSE; |
| 5457 | } |
| 5458 | } |
| 5459 | } |
| 5460 | } |
| 5461 | #endif |
| 5462 | |
| 5463 | if( bIfAllOK ) { |
| 5464 | AllOKTimes ++; |
| 5465 | |
| 5466 | if( AllOKTimes >= TFRL_RcvTime ) |
| 5467 | #if defined(__KERNEL__) || defined(__OSK__) |
| 5468 | RetryLimitRecovery((unsigned long)priv); |
| 5469 | #elif defined(__ECOS) |
| 5470 | RetryLimitRecovery((void *)priv); |
| 5471 | #endif |
| 5472 | } |
| 5473 | else { |
| 5474 | AllOKTimes = 0; |
| 5475 | } |
| 5476 | } |
| 5477 | #endif |
| 5478 | |
| 5479 | |
| 5480 | |
| 5481 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 5482 | |
| 5483 | /* |
| 5484 | * PA Analog Pre-distortion Calibration R06 |
| 5485 | */ |
| 5486 | void APK_MAIN(struct rtl8192cd_priv *priv, unsigned int is2T) |
| 5487 | { |
| 5488 | unsigned int reg_d[PATH_NUM]; |
| 5489 | unsigned int tmpReg, index, offset, path, i=0, pathbound = PATH_NUM, apkbound=6; |
| 5490 | unsigned int BB_backup[APK_BB_REG_NUM]; |
| 5491 | unsigned int BB_REG[APK_BB_REG_NUM] = {0x904, 0xc04, 0x800, 0xc08, 0x874}; |
| 5492 | unsigned int BB_AP_MODE[APK_BB_REG_NUM] = {0x00000020, 0x00a05430, 0x02040000, 0x000800e4, 0x00204000}; |
| 5493 | unsigned int BB_normal_AP_MODE[APK_BB_REG_NUM] = {0x00000020, 0x00a05430, 0x02040000, 0x000800e4, 0x22204000}; |
| 5494 | unsigned int AFE_backup[APK_AFE_REG_NUM]; |
| 5495 | unsigned int AFE_REG[APK_AFE_REG_NUM] = { 0x85c, 0xe6c, 0xe70, 0xe74, 0xe78, 0xe7c, 0xe80, 0xe84, |
| 5496 | 0xe88, 0xe8c, 0xed0, 0xed4, 0xed8, 0xedc, 0xee0, 0xeec}; |
| 5497 | unsigned int MAC_backup[IQK_MAC_REG_NUM]; |
| 5498 | unsigned int MAC_REG[IQK_MAC_REG_NUM] = {0x522, 0x550, 0x551, 0x040}; |
| 5499 | unsigned int APK_RF_init_value[PATH_NUM][APK_BB_REG_NUM] = {{0x0852c, 0x1852c, 0x5852c, 0x1852c, 0x5852c}, |
| 5500 | {0x2852e, 0x0852e, 0x3852e, 0x0852e, 0x0852e}}; |
| 5501 | unsigned int APK_normal_RF_init_value[PATH_NUM][APK_BB_REG_NUM] = |
| 5502 | { {0x0852c, 0x0a52c, 0x3a52c, 0x5a52c, 0x5a52c}, //path settings equal to path b settings |
| 5503 | {0x0852c, 0x0a52c, 0x5a52c, 0x5a52c, 0x5a52c} }; |
| 5504 | |
| 5505 | unsigned int APK_RF_value_0[PATH_NUM][APK_BB_REG_NUM] = |
| 5506 | { {0x52019, 0x52014, 0x52013, 0x5200f, 0x5208d}, |
| 5507 | {0x5201a, 0x52019, 0x52016, 0x52033, 0x52050}}; |
| 5508 | |
| 5509 | unsigned int APK_normal_RF_value_0[PATH_NUM][APK_BB_REG_NUM] = |
| 5510 | { {0x52019, 0x52017, 0x52010, 0x5200d, 0x5206a}, //path settings equal to path b settings |
| 5511 | {0x52019, 0x52017, 0x52010, 0x5200d, 0x5206a} }; |
| 5512 | |
| 5513 | unsigned int AFE_on_off[PATH_NUM] = {0x04db25a4, 0x0b1b25a4}; //path A on path B off / path A off path B on |
| 5514 | unsigned int APK_offset[PATH_NUM] = {0xb68, 0xb6c}; |
| 5515 | unsigned int APK_normal_offset[PATH_NUM] = {0xb28, 0xb98}; |
| 5516 | unsigned int APK_value[PATH_NUM] = {0x92fc0000, 0x12fc0000}; |
| 5517 | unsigned int APK_normal_value[PATH_NUM] = {0x92680000, 0x12680000}; |
| 5518 | char APK_delta_mapping[APK_BB_REG_NUM][13] = {{-4, -3, -2, -2, -1, -1, 0, 1, 2, 3, 4, 5, 6}, |
| 5519 | {-4, -3, -2, -2, -1, -1, 0, 1, 2, 3, 4, 5, 6}, |
| 5520 | {-6, -4, -2, -2, -1, -1, 0, 1, 2, 3, 4, 5, 6}, |
| 5521 | {-1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6}, |
| 5522 | {-11, -9, -7, -5, -3, -1, 0, 0, 0, 0, 0, 0, 0}}; |
| 5523 | unsigned int APK_normal_setting_value_1[13] = |
| 5524 | { 0x01017018, 0xf7ed8f84, 0x1b1a1816, 0x2522201e, 0x322e2b28, |
| 5525 | 0x433f3a36, 0x5b544e49, 0x7b726a62, 0xa69a8f84, 0xdfcfc0b3, |
| 5526 | 0x12680000, 0x00880000, 0x00880000 }; |
| 5527 | unsigned int APK_normal_setting_value_2[16] = |
| 5528 | { 0x01c7021d, 0x01670183, 0x01000123, 0x00bf00e2, 0x008d00a3, |
| 5529 | 0x0068007b, 0x004d0059, 0x003a0042, 0x002b0031, 0x001f0025, |
| 5530 | 0x0017001b, 0x00110014, 0x000c000f, 0x0009000b, 0x00070008, |
| 5531 | 0x00050006 }; |
| 5532 | |
| 5533 | |
| 5534 | unsigned int APK_normal_RF_init_value_old[PATH_NUM][APK_BB_REG_NUM] = |
| 5535 | {{0x0852c, 0x5a52c, 0x0a52c, 0x5a52c, 0x4a52c}, //path settings equal to path b settings |
| 5536 | {0x0852c, 0x5a52c, 0x0a52c, 0x5a52c, 0x4a52c}}; |
| 5537 | unsigned int APK_normal_RF_value_0_old[PATH_NUM][APK_BB_REG_NUM] = |
| 5538 | {{0x52019, 0x52017, 0x52010, 0x5200d, 0x5200a}, //path settings equal to path b settings |
| 5539 | {0x52019, 0x52017, 0x52010, 0x5200d, 0x5200a}}; |
| 5540 | unsigned int APK_normal_setting_value_1_old[13] = |
| 5541 | {0x01017018, 0xf7ed8f84, 0x40372d20, 0x5b554e48, 0x6f6a6560, |
| 5542 | 0x807c7873, 0x8f8b8884, 0x9d999693, 0xa9a6a3a0, 0xb5b2afac, |
| 5543 | 0x12680000, 0x00880000, 0x00880000}; |
| 5544 | unsigned int APK_normal_setting_value_2_old[16] = |
| 5545 | {0x00810100, 0x00400056, 0x002b0032, 0x001f0024, 0x0019001c, |
| 5546 | 0x00150017, 0x00120013, 0x00100011, 0x000e000f, 0x000c000d, |
| 5547 | 0x000b000c, 0x000a000b, 0x0009000a, 0x00090009, 0x00080008, |
| 5548 | 0x00080008}; |
| 5549 | unsigned int AP_curve[PATH_NUM][APK_CURVE_REG_NUM]; |
| 5550 | |
| 5551 | unsigned int APK_result[PATH_NUM][APK_BB_REG_NUM]; //val_1_1a, val_1_2a, val_2a, val_3a, val_4a |
| 5552 | unsigned int ThermalValue = 0; |
| 5553 | int BB_offset, delta_V, delta_offset; |
| 5554 | int newVerAPK = (IS_UMC_A_CUT_88C(priv)) ? 1 : 0; |
| 5555 | unsigned int *pAPK_normal_setting_value_1 = APK_normal_setting_value_1, *pAPK_normal_setting_value_2 = APK_normal_setting_value_2 ; |
| 5556 | #ifdef HIGH_POWER_EXT_PA |
| 5557 | unsigned int tmp0x870=0, tmp0x860=0, tmp0x864=0; |
| 5558 | |
| 5559 | if(priv->pshare->rf_ft_var.use_ext_pa) |
| 5560 | newVerAPK = 1; |
| 5561 | #endif |
| 5562 | |
| 5563 | if(!newVerAPK) { |
| 5564 | apkbound = 12; |
| 5565 | pAPK_normal_setting_value_1 = APK_normal_setting_value_1_old; |
| 5566 | pAPK_normal_setting_value_2 = APK_normal_setting_value_2_old; |
| 5567 | } |
| 5568 | |
| 5569 | if(!is2T) |
| 5570 | pathbound = 1; |
| 5571 | |
| 5572 | for(index = 0; index < PATH_NUM; index ++) { |
| 5573 | APK_offset[index] = APK_normal_offset[index]; |
| 5574 | APK_value[index] = APK_normal_value[index]; |
| 5575 | AFE_on_off[index] = 0x6fdb25a4; |
| 5576 | } |
| 5577 | |
| 5578 | for(index = 0; index < APK_BB_REG_NUM; index ++) { |
| 5579 | for(path = 0; path < pathbound; path++) { |
| 5580 | if(newVerAPK) { |
| 5581 | APK_RF_init_value[path][index] = APK_normal_RF_init_value[path][index]; |
| 5582 | APK_RF_value_0[path][index] = APK_normal_RF_value_0[path][index]; |
| 5583 | } else { |
| 5584 | APK_RF_init_value[path][index] = APK_normal_RF_init_value_old[path][index]; |
| 5585 | APK_RF_value_0[path][index] = APK_normal_RF_value_0_old[path][index]; |
| 5586 | } |
| 5587 | |
| 5588 | } |
| 5589 | BB_AP_MODE[index] = BB_normal_AP_MODE[index]; |
| 5590 | } |
| 5591 | |
| 5592 | /* |
| 5593 | * save BB default value |
| 5594 | */ |
| 5595 | for(index = 1; index < APK_BB_REG_NUM ; index++) |
| 5596 | BB_backup[index] = phy_query_bb_reg(priv, BB_REG[index], bMaskDWord); |
| 5597 | |
| 5598 | #ifdef HIGH_POWER_EXT_PA |
| 5599 | if (priv->pshare->rf_ft_var.use_ext_pa) { |
| 5600 | tmp0x870 = phy_query_bb_reg(priv, 0x870, bMaskDWord); |
| 5601 | tmp0x860 = phy_query_bb_reg(priv, 0x860, bMaskDWord); |
| 5602 | tmp0x864 = phy_query_bb_reg(priv, 0x864, bMaskDWord); |
| 5603 | } |
| 5604 | #endif |
| 5605 | |
| 5606 | //save MAC default value |
| 5607 | _phy_save_mac_registers(priv, MAC_REG, MAC_backup); |
| 5608 | |
| 5609 | //save AFE default value |
| 5610 | _phy_save_adda_registers(priv, AFE_REG, AFE_backup, APK_AFE_REG_NUM); |
| 5611 | |
| 5612 | for(path = 0; path < pathbound; path++) { |
| 5613 | /* |
| 5614 | * save old AP curve |
| 5615 | */ |
| 5616 | if(path == RF_PATH_A) { |
| 5617 | /* |
| 5618 | * path A APK |
| 5619 | * load APK setting |
| 5620 | * path-A |
| 5621 | */ |
| 5622 | offset = 0xb00; |
| 5623 | for(index = 0; index < 11; index ++) { |
| 5624 | phy_set_bb_reg(priv, offset, bMaskDWord, pAPK_normal_setting_value_1[index]); |
| 5625 | offset += 0x04; |
| 5626 | } |
| 5627 | phy_set_bb_reg(priv, 0xb98, bMaskDWord, 0x12680000); |
| 5628 | |
| 5629 | offset = 0xb68; |
| 5630 | for(; index < 13; index ++) { |
| 5631 | phy_set_bb_reg(priv, offset, bMaskDWord, pAPK_normal_setting_value_1[index]); |
| 5632 | offset += 0x04; |
| 5633 | } |
| 5634 | |
| 5635 | /* |
| 5636 | * page-B1 |
| 5637 | */ |
| 5638 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0x400000); |
| 5639 | |
| 5640 | /* |
| 5641 | *path A |
| 5642 | */ |
| 5643 | offset = 0xb00; |
| 5644 | for(index = 0; index < 16; index++) { |
| 5645 | phy_set_bb_reg(priv, offset, bMaskDWord, pAPK_normal_setting_value_2[index]); |
| 5646 | offset += 0x04; |
| 5647 | } |
| 5648 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0); |
| 5649 | } else if(path == RF_PATH_B) { |
| 5650 | /* |
| 5651 | * path B APK |
| 5652 | * load APK setting |
| 5653 | * path-B |
| 5654 | */ |
| 5655 | offset = 0xb70; |
| 5656 | for(index = 0; index < 10; index ++) { |
| 5657 | phy_set_bb_reg(priv, offset, bMaskDWord, pAPK_normal_setting_value_1[index]); |
| 5658 | offset += 0x04; |
| 5659 | } |
| 5660 | phy_set_bb_reg(priv, 0xb28, bMaskDWord, 0x12680000); |
| 5661 | phy_set_bb_reg(priv, 0xb98, bMaskDWord, 0x12680000); |
| 5662 | |
| 5663 | offset = 0xb68; |
| 5664 | index = 11; |
| 5665 | for(; index < 13; index ++) { |
| 5666 | //offset 0xb68, 0xb6c |
| 5667 | phy_set_bb_reg(priv, offset, bMaskDWord, pAPK_normal_setting_value_1[index]); |
| 5668 | offset += 0x04; |
| 5669 | } |
| 5670 | |
| 5671 | /* |
| 5672 | * page-B1 |
| 5673 | */ |
| 5674 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0x400000); |
| 5675 | |
| 5676 | /* |
| 5677 | * path B |
| 5678 | */ |
| 5679 | offset = 0xb60; |
| 5680 | for(index = 0; index < 16; index++) { |
| 5681 | phy_set_bb_reg(priv, offset, bMaskDWord, pAPK_normal_setting_value_2[index]); |
| 5682 | offset += 0x04; |
| 5683 | } |
| 5684 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0); |
| 5685 | } |
| 5686 | |
| 5687 | if(!newVerAPK) { |
| 5688 | tmpReg = phy_query_rf_reg(priv, (unsigned int)path, 0x3, bMaskDWord, 1); |
| 5689 | |
| 5690 | AP_curve[path][0] = tmpReg & 0x1F; //[4:0] |
| 5691 | |
| 5692 | tmpReg = phy_query_rf_reg(priv, (unsigned int)path, 0x4, bMaskDWord, 1); |
| 5693 | AP_curve[path][1] = (tmpReg & 0xF8000) >> 15; //[19:15] |
| 5694 | AP_curve[path][2] = (tmpReg & 0x7C00) >> 10; //[14:10] |
| 5695 | AP_curve[path][3] = (tmpReg & 0x3E0) >> 5; //[9:5] |
| 5696 | } |
| 5697 | |
| 5698 | /* |
| 5699 | * save RF default value |
| 5700 | */ |
| 5701 | reg_d[path] = phy_query_rf_reg(priv, (unsigned int)path, 0xd, bMaskDWord, 1); |
| 5702 | |
| 5703 | /* |
| 5704 | * Path A AFE all on, path B AFE All off or vise versa |
| 5705 | */ |
| 5706 | for(index = 0; index < APK_AFE_REG_NUM ; index++) |
| 5707 | phy_set_bb_reg(priv, AFE_REG[index], bMaskDWord, AFE_on_off[path]); |
| 5708 | |
| 5709 | /* |
| 5710 | * BB to AP mode |
| 5711 | */ |
| 5712 | if(path == RF_PATH_A) { |
| 5713 | for(index = 1; index < APK_BB_REG_NUM ; index++) |
| 5714 | phy_set_bb_reg(priv, BB_REG[index], bMaskDWord, BB_AP_MODE[index]); |
| 5715 | } |
| 5716 | |
| 5717 | #ifdef HIGH_POWER_EXT_PA |
| 5718 | if (priv->pshare->rf_ft_var.use_ext_pa) { |
| 5719 | phy_set_bb_reg(priv, 0x870, BIT(10), 1); |
| 5720 | phy_set_bb_reg(priv, 0x870, BIT(26), 1); |
| 5721 | phy_set_bb_reg(priv, 0x860, BIT(10), 0); |
| 5722 | phy_set_bb_reg(priv, 0x864, BIT(10), 0); |
| 5723 | } |
| 5724 | #endif |
| 5725 | |
| 5726 | if(newVerAPK) { |
| 5727 | if(path == RF_PATH_A) { |
| 5728 | phy_set_bb_reg(priv, 0xe30 , bMaskDWord, 0x01008c00); |
| 5729 | phy_set_bb_reg(priv, 0xe34 , bMaskDWord, 0x01008c00); |
| 5730 | } else if(path == RF_PATH_B) { |
| 5731 | phy_set_bb_reg(priv, 0xe50 , bMaskDWord, 0x01008c00); |
| 5732 | phy_set_bb_reg(priv, 0xe54 , bMaskDWord, 0x01008c00); |
| 5733 | } |
| 5734 | } |
| 5735 | |
| 5736 | //MAC settings |
| 5737 | _phy_mac_setting_calibration(priv, MAC_REG, MAC_backup); |
| 5738 | |
| 5739 | |
| 5740 | if(path == RF_PATH_A) { |
| 5741 | //Path B to standby mode |
| 5742 | phy_set_rf_reg(priv, RF_PATH_B, 0x0, bMaskDWord, 0x10000); |
| 5743 | } else { |
| 5744 | //Path A to standby mode |
| 5745 | phy_set_rf_reg(priv, RF_PATH_A, 0x00, bMaskDWord, 0x10000); |
| 5746 | phy_set_rf_reg(priv, RF_PATH_A, 0x10, bMaskDWord, 0x1000f); |
| 5747 | phy_set_rf_reg(priv, RF_PATH_A, 0x11, bMaskDWord, 0x20103); |
| 5748 | } |
| 5749 | |
| 5750 | /* |
| 5751 | * Check Thermal value delta |
| 5752 | */ |
| 5753 | if (priv->pmib->dot11RFEntry.ther) { |
| 5754 | ThermalValue = phy_query_rf_reg(priv, RF_PATH_A, 0x24, 0x1f, 1) & 0xff; |
| 5755 | ThermalValue -= priv->pmib->dot11RFEntry.ther; |
| 5756 | } |
| 5757 | |
| 5758 | delta_offset = ((ThermalValue+14)/2); |
| 5759 | if(delta_offset < 0) |
| 5760 | delta_offset = 0; |
| 5761 | else if (delta_offset > 12) |
| 5762 | delta_offset = 12; |
| 5763 | |
| 5764 | //AP calibration |
| 5765 | for(index = 1; index < APK_BB_REG_NUM; index++) { |
| 5766 | tmpReg = APK_RF_init_value[path][index]; |
| 5767 | if (priv->pmib->dot11RFEntry.ther) { |
| 5768 | BB_offset = (tmpReg & 0xF0000) >> 16; |
| 5769 | |
| 5770 | if(!(tmpReg & BIT(15))) //sign bit 0 |
| 5771 | BB_offset = -BB_offset; |
| 5772 | delta_V = APK_delta_mapping[index][delta_offset]; |
| 5773 | BB_offset += delta_V; |
| 5774 | |
| 5775 | if(BB_offset < 0) { |
| 5776 | tmpReg = tmpReg & (~BIT(15)); |
| 5777 | BB_offset = -BB_offset; |
| 5778 | } else { |
| 5779 | tmpReg = tmpReg | BIT(15); |
| 5780 | } |
| 5781 | tmpReg = (tmpReg & 0xFFF0FFFF) | (BB_offset << 16); |
| 5782 | } |
| 5783 | |
| 5784 | if(newVerAPK) |
| 5785 | phy_set_rf_reg(priv, (unsigned int)path, 0xc, bMaskDWord, 0x8992e); |
| 5786 | else |
| 5787 | phy_set_rf_reg(priv, (unsigned int)path, 0xc, bMaskDWord, 0x8992f); |
| 5788 | |
| 5789 | phy_set_rf_reg(priv, (unsigned int)path, 0x0, bMaskDWord, APK_RF_value_0[path][index]); |
| 5790 | phy_set_rf_reg(priv, (unsigned int)path, 0xd, bMaskDWord, tmpReg); |
| 5791 | |
| 5792 | /* |
| 5793 | * PA11+PAD01111, one shot |
| 5794 | */ |
| 5795 | i = 0; |
| 5796 | do { |
| 5797 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0x800000); |
| 5798 | phy_set_bb_reg(priv, APK_offset[path], bMaskDWord, APK_value[0]); |
| 5799 | delay_ms(3); |
| 5800 | phy_set_bb_reg(priv, APK_offset[path], bMaskDWord, APK_value[1]); |
| 5801 | delay_ms(20); |
| 5802 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0); |
| 5803 | |
| 5804 | if(!newVerAPK) { |
| 5805 | tmpReg = phy_query_rf_reg(priv, (unsigned int)path, 0xb, bMaskDWord, 1); |
| 5806 | tmpReg = (tmpReg & 0x3E00) >> 9; |
| 5807 | } else { |
| 5808 | if(path == RF_PATH_A) |
| 5809 | tmpReg = phy_query_bb_reg(priv, 0xbd8, 0x03E00000); |
| 5810 | else |
| 5811 | tmpReg = phy_query_bb_reg(priv, 0xbd8, 0xF8000000); |
| 5812 | } |
| 5813 | i++; |
| 5814 | } while((tmpReg > apkbound) && i < 4); |
| 5815 | |
| 5816 | APK_result[path][index] = tmpReg; |
| 5817 | } |
| 5818 | } |
| 5819 | |
| 5820 | /* |
| 5821 | * reload MAC default value |
| 5822 | */ |
| 5823 | _phy_reload_mac_registers(priv, MAC_REG, MAC_backup); |
| 5824 | |
| 5825 | /* |
| 5826 | * reload BB default value |
| 5827 | */ |
| 5828 | for(index = 1; index < APK_BB_REG_NUM ; index++) |
| 5829 | phy_set_bb_reg(priv, BB_REG[index], bMaskDWord, BB_backup[index]); |
| 5830 | |
| 5831 | #ifdef HIGH_POWER_EXT_PA |
| 5832 | if (priv->pshare->rf_ft_var.use_ext_pa) { |
| 5833 | phy_set_bb_reg(priv, 0x870, bMaskDWord, tmp0x870); |
| 5834 | phy_set_bb_reg(priv, 0x860, bMaskDWord, tmp0x860); |
| 5835 | phy_set_bb_reg(priv, 0x864, bMaskDWord, tmp0x864); |
| 5836 | } |
| 5837 | #endif |
| 5838 | |
| 5839 | /* |
| 5840 | * reload AFE default value |
| 5841 | */ |
| 5842 | _phy_reload_adda_registers(priv, AFE_REG, AFE_backup, 16); |
| 5843 | |
| 5844 | |
| 5845 | /* |
| 5846 | * reload RF path default value |
| 5847 | */ |
| 5848 | for(path = 0; path < pathbound; path++) { |
| 5849 | phy_set_rf_reg(priv, (unsigned int)path, 0xd, bMaskDWord, reg_d[path]); |
| 5850 | if(path == RF_PATH_B) { |
| 5851 | phy_set_rf_reg(priv, RF_PATH_A, 0x10, bMaskDWord, 0x1000f); |
| 5852 | phy_set_rf_reg(priv, RF_PATH_A, 0x11, bMaskDWord, 0x20101); |
| 5853 | } |
| 5854 | |
| 5855 | if(newVerAPK) { |
| 5856 | if (APK_result[path][1] > 6) |
| 5857 | APK_result[path][1] = 6; |
| 5858 | } else { |
| 5859 | if(APK_result[path][1] < 1) |
| 5860 | APK_result[path][1] = 1; |
| 5861 | else if (APK_result[path][1] > 5) |
| 5862 | APK_result[path][1] = 5; |
| 5863 | |
| 5864 | if(APK_result[path][2] < 2) |
| 5865 | APK_result[path][2] = 2; |
| 5866 | else if (APK_result[path][2] > 6) |
| 5867 | APK_result[path][2] = 6; |
| 5868 | |
| 5869 | if(APK_result[path][3] < 2) |
| 5870 | APK_result[path][3] = 2; |
| 5871 | else if (APK_result[path][3] > 6) |
| 5872 | APK_result[path][3] = 6; |
| 5873 | |
| 5874 | if(APK_result[path][4] < 5) |
| 5875 | APK_result[path][4] = 5; |
| 5876 | else if (APK_result[path][4] > 9) |
| 5877 | APK_result[path][4] = 9; |
| 5878 | } |
| 5879 | } |
| 5880 | |
| 5881 | for(path = 0; path < pathbound; path++) { |
| 5882 | phy_set_rf_reg(priv, (unsigned int)path, 0x3, bMaskDWord, |
| 5883 | ((APK_result[path][1] << 15) | (APK_result[path][1] << 10) | (APK_result[path][1] << 5) | APK_result[path][1])); |
| 5884 | if(newVerAPK) { |
| 5885 | if(path == RF_PATH_A) |
| 5886 | phy_set_rf_reg(priv, (unsigned int)path, 0x4, bMaskDWord, |
| 5887 | ((APK_result[path][1] << 15) | (APK_result[path][1] << 10) | (0x00 << 5) | 0x05)); |
| 5888 | else |
| 5889 | phy_set_rf_reg(priv, (unsigned int)path, 0x4, bMaskDWord, |
| 5890 | ((APK_result[path][1] << 15) | (APK_result[path][1] << 10) | (0x02 << 5) | 0x05)); |
| 5891 | phy_set_rf_reg(priv, (unsigned int)path, 0xe, bMaskDWord, |
| 5892 | ((0x08 << 15) | (0x08 << 10) | (0x08 << 5) | 0x08)); |
| 5893 | } else { |
| 5894 | phy_set_rf_reg(priv, (unsigned int)path, 0x4, bMaskDWord, |
| 5895 | ((APK_result[path][1] << 15) | (APK_result[path][1] << 10) | (APK_result[path][2] << 5) | APK_result[path][3])); |
| 5896 | phy_set_rf_reg(priv, (unsigned int)path, 0xe, bMaskDWord, |
| 5897 | ((APK_result[path][4] << 15) | (APK_result[path][4] << 10) | (APK_result[path][4] << 5) | APK_result[path][4])); |
| 5898 | } |
| 5899 | } |
| 5900 | } |
| 5901 | |
| 5902 | |
| 5903 | |
| 5904 | /* |
| 5905 | return FALSE => do IQK again |
| 5906 | */ |
| 5907 | char _PHY_SimularityCompare(struct rtl8192cd_priv *priv, int result[][8], unsigned char c1, unsigned char c2) |
| 5908 | { |
| 5909 | unsigned int i, j, diff, SimularityBitMap, bound = 0; |
| 5910 | unsigned char final_candidate[2] = {0xFF, 0xFF}; //for path A and path B |
| 5911 | char bResult = TRUE, is2T = (GET_CHIP_VER(priv) == VERSION_8192C ? 1 : 0); |
| 5912 | |
| 5913 | bound = (is2T) ? 8 : 4; |
| 5914 | SimularityBitMap = 0; |
| 5915 | |
| 5916 | for( i = 0; i < bound; i++ ) { |
| 5917 | diff = (result[c1][i] > result[c2][i]) ? (result[c1][i] - result[c2][i]) : (result[c2][i] - result[c1][i]); |
| 5918 | if (diff > MAX_TOLERANCE) { |
| 5919 | if((i == 2 || i == 6) && !SimularityBitMap) { |
| 5920 | if( result[c1][i]+ result[c1][i+1] == 0) |
| 5921 | final_candidate[(i>>2)] = c2; |
| 5922 | else if (result[c2][i]+result[c2][i+1] == 0) |
| 5923 | final_candidate[(i>>2)] = c1; |
| 5924 | else |
| 5925 | SimularityBitMap |= (1<<i); |
| 5926 | } |
| 5927 | else |
| 5928 | SimularityBitMap |= (1<<i); |
| 5929 | } |
| 5930 | } |
| 5931 | |
| 5932 | if ( SimularityBitMap == 0) { |
| 5933 | for( i = 0; i < (bound>>2); i++ ) { |
| 5934 | if(final_candidate[i] != 0xFF) { |
| 5935 | for( j = (i<<2); j < ((i+1)<<2)-2; j++) |
| 5936 | result[3][j] = result[final_candidate[i]][j]; |
| 5937 | bResult = FALSE; |
| 5938 | } |
| 5939 | } |
| 5940 | return bResult; |
| 5941 | } |
| 5942 | else if (!(SimularityBitMap & 0x03)) { //path A TX OK |
| 5943 | for(i = 0; i < 2; i++) |
| 5944 | result[3][i] = result[c1][i]; |
| 5945 | return FALSE; |
| 5946 | } |
| 5947 | else if (!(SimularityBitMap & 0x0c)) { //path A RX OK |
| 5948 | for(i = 2; i < 4; i++) |
| 5949 | result[3][i] = result[c1][i]; |
| 5950 | return FALSE; |
| 5951 | } |
| 5952 | else if (!(SimularityBitMap & 0x30) && is2T) { //path B TX OK |
| 5953 | for(i = 4; i < 6; i++) |
| 5954 | result[3][i] = result[c1][i]; |
| 5955 | return FALSE; |
| 5956 | } |
| 5957 | else if (!(SimularityBitMap & 0xc0) && is2T) { //path B RX OK |
| 5958 | for(i = 6; i < 8; i++) |
| 5959 | result[3][i] = result[c1][i]; |
| 5960 | return FALSE; |
| 5961 | } |
| 5962 | else |
| 5963 | return FALSE; |
| 5964 | |
| 5965 | } |
| 5966 | |
| 5967 | |
| 5968 | //bit0 = 1 => Tx OK, bit1 = 1 => Rx OK |
| 5969 | unsigned char _PHY_PathA_IQK(struct rtl8192cd_priv *priv, char configPathB) |
| 5970 | { |
| 5971 | unsigned int reg_eac, reg_e94, reg_e9c, reg_ea4; |
| 5972 | unsigned char result = 0x00; |
| 5973 | |
| 5974 | |
| 5975 | // RTPRINT(FINIT, INIT_IQK, ("Path-A IQK setting!\n")); |
| 5976 | #if defined(HIGH_POWER_EXT_PA) && defined(CONFIG_RTL_92C_SUPPORT) |
| 5977 | if (priv->pshare->rf_ft_var.use_ext_pa){ |
| 5978 | |
| 5979 | //path-A IQK setting |
| 5980 | phy_set_bb_reg(priv, 0xe30, bMaskDWord, 0x18008c1f); |
| 5981 | phy_set_bb_reg(priv, 0xe34, bMaskDWord, 0x18008c1f); |
| 5982 | phy_set_bb_reg(priv, 0xe38, bMaskDWord, 0x82140102); |
| 5983 | phy_set_bb_reg(priv, 0xe3c, bMaskDWord, 0x28160804); |
| 5984 | |
| 5985 | //path-B IQK setting |
| 5986 | if(configPathB) { |
| 5987 | phy_set_bb_reg(priv, 0xe50, bMaskDWord, 0x18008c22); |
| 5988 | phy_set_bb_reg(priv, 0xe54, bMaskDWord, 0x18008c22); |
| 5989 | phy_set_bb_reg(priv, 0xe58, bMaskDWord, 0x82140102); |
| 5990 | phy_set_bb_reg(priv, 0xe5c, bMaskDWord, 0x28160804); |
| 5991 | } |
| 5992 | }else |
| 5993 | #endif |
| 5994 | { |
| 5995 | //path-A IQK setting |
| 5996 | phy_set_bb_reg(priv, 0xe30, bMaskDWord, 0x10008c1f); |
| 5997 | phy_set_bb_reg(priv, 0xe34, bMaskDWord, 0x10008c1f); |
| 5998 | phy_set_bb_reg(priv, 0xe38, bMaskDWord, 0x82140102); |
| 5999 | phy_set_bb_reg(priv, 0xe3c, bMaskDWord, ((configPathB |IS_UMC_B_CUT_88C(priv)) ? 0x28160202 : 0x28160502)); |
| 6000 | |
| 6001 | //path-B IQK setting |
| 6002 | if(configPathB) { |
| 6003 | phy_set_bb_reg(priv, 0xe50, bMaskDWord, 0x10008c22); |
| 6004 | phy_set_bb_reg(priv, 0xe54, bMaskDWord, 0x10008c22); |
| 6005 | phy_set_bb_reg(priv, 0xe58, bMaskDWord, 0x82140102); |
| 6006 | phy_set_bb_reg(priv, 0xe5c, bMaskDWord, 0x28160202); |
| 6007 | } |
| 6008 | } |
| 6009 | |
| 6010 | |
| 6011 | |
| 6012 | //LO calibration setting |
| 6013 | phy_set_bb_reg(priv, 0xe4c, bMaskDWord, 0x001028d1); |
| 6014 | |
| 6015 | //One shot, path A LOK & IQK |
| 6016 | phy_set_bb_reg(priv, 0xe48, bMaskDWord, 0xf9000000); |
| 6017 | phy_set_bb_reg(priv, 0xe48, bMaskDWord, 0xf8000000); |
| 6018 | |
| 6019 | // delay x ms |
| 6020 | delay_ms(IQK_DELAY_TIME); |
| 6021 | |
| 6022 | // Check failed |
| 6023 | reg_eac = phy_query_bb_reg(priv, 0xeac, bMaskDWord); |
| 6024 | reg_e94 = phy_query_bb_reg(priv, 0xe94, bMaskDWord); |
| 6025 | reg_e9c= phy_query_bb_reg(priv, 0xe9c, bMaskDWord); |
| 6026 | reg_ea4= phy_query_bb_reg(priv, 0xea4, bMaskDWord); |
| 6027 | |
| 6028 | if(!(reg_eac & BIT(28)) && |
| 6029 | (((reg_e94 & 0x03FF0000)>>16) != 0x142) && |
| 6030 | (((reg_e9c & 0x03FF0000)>>16) != 0x42) ) |
| 6031 | result |= 0x01; |
| 6032 | else //if Tx not OK, ignore Rx |
| 6033 | return result; |
| 6034 | |
| 6035 | if(!(reg_eac & BIT(27)) && //if Tx is OK, check whether Rx is OK |
| 6036 | (((reg_ea4 & 0x03FF0000)>>16) != 0x132) && |
| 6037 | (((reg_eac & 0x03FF0000)>>16) != 0x36)) |
| 6038 | result |= 0x02; |
| 6039 | else { |
| 6040 | // RTPRINT(FINIT, INIT_IQK, ("Path A Rx IQK fail!!\n")); |
| 6041 | } |
| 6042 | |
| 6043 | return result; |
| 6044 | } |
| 6045 | |
| 6046 | //bit0 = 1 => Tx OK, bit1 = 1 => Rx OK |
| 6047 | unsigned char _PHY_PathB_IQK(struct rtl8192cd_priv *priv) |
| 6048 | { |
| 6049 | unsigned int reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc; |
| 6050 | unsigned char result = 0x00; |
| 6051 | #if 0 |
| 6052 | //path-B IQK setting |
| 6053 | RTPRINT(FINIT, INIT_IQK, ("Path-B IQK setting!\n")); |
| 6054 | phy_set_bb_reg(pAdapter, 0xe50, bMaskDWord, 0x10008c22); |
| 6055 | phy_set_bb_reg(pAdapter, 0xe54, bMaskDWord, 0x10008c22); |
| 6056 | phy_set_bb_reg(pAdapter, 0xe58, bMaskDWord, 0x82140102); |
| 6057 | phy_set_bb_reg(pAdapter, 0xe5c, bMaskDWord, 0x28160202); |
| 6058 | |
| 6059 | //LO calibration setting |
| 6060 | RTPRINT(FINIT, INIT_IQK, ("LO calibration setting!\n")); |
| 6061 | phy_set_bb_reg(pAdapter, 0xe4c, bMaskDWord, 0x001028d1); |
| 6062 | #endif |
| 6063 | //One shot, path B LOK & IQK |
| 6064 | // RTPRINT(FINIT, INIT_IQK, ("One shot, path A LOK & IQK!\n")); |
| 6065 | phy_set_bb_reg(priv, 0xe60, bMaskDWord, 0x00000002); |
| 6066 | phy_set_bb_reg(priv, 0xe60, bMaskDWord, 0x00000000); |
| 6067 | |
| 6068 | // delay x ms |
| 6069 | delay_ms(IQK_DELAY_TIME); |
| 6070 | |
| 6071 | // Check failed |
| 6072 | reg_eac = phy_query_bb_reg(priv, 0xeac, bMaskDWord); |
| 6073 | reg_eb4 = phy_query_bb_reg(priv, 0xeb4, bMaskDWord); |
| 6074 | reg_ebc= phy_query_bb_reg(priv, 0xebc, bMaskDWord); |
| 6075 | reg_ec4= phy_query_bb_reg(priv, 0xec4, bMaskDWord); |
| 6076 | reg_ecc= phy_query_bb_reg(priv, 0xecc, bMaskDWord); |
| 6077 | |
| 6078 | if(!(reg_eac & BIT(31)) && |
| 6079 | (((reg_eb4 & 0x03FF0000)>>16) != 0x142) && |
| 6080 | (((reg_ebc & 0x03FF0000)>>16) != 0x42)) |
| 6081 | result |= 0x01; |
| 6082 | else |
| 6083 | return result; |
| 6084 | |
| 6085 | if(!(reg_eac & BIT(30)) && |
| 6086 | (((reg_ec4 & 0x03FF0000)>>16) != 0x132) && |
| 6087 | (((reg_ecc & 0x03FF0000)>>16) != 0x36)) |
| 6088 | result |= 0x02; |
| 6089 | else { |
| 6090 | // RTPRINT(FINIT, INIT_IQK, ("Path B Rx IQK fail!!\n")); |
| 6091 | } |
| 6092 | |
| 6093 | return result; |
| 6094 | |
| 6095 | } |
| 6096 | |
| 6097 | void _phy_path_a_fill_iqk_matrix(struct rtl8192cd_priv *priv, char bIQKOK, int result[][8], unsigned char final_candidate, char bTxOnly) |
| 6098 | { |
| 6099 | int oldval_0, X, TX0_A, reg; |
| 6100 | int Y, TX0_C; |
| 6101 | |
| 6102 | if(final_candidate == 0xFF) |
| 6103 | return; |
| 6104 | |
| 6105 | else if(bIQKOK) { |
| 6106 | oldval_0 = (phy_query_bb_reg(priv, REG_OFDM_0_XA_TX_IQ_IMBALANCE, bMaskDWord) >> 22) & 0x3FF; |
| 6107 | |
| 6108 | X = result[final_candidate][0]; |
| 6109 | if ((X & 0x00000200) != 0) |
| 6110 | X = X | 0xFFFFFC00; |
| 6111 | TX0_A = (X * oldval_0) >> 8; |
| 6112 | phy_set_bb_reg(priv, REG_OFDM_0_XA_TX_IQ_IMBALANCE, 0x3FF, TX0_A); |
| 6113 | phy_set_bb_reg(priv, REG_OFDM_0_ECCA_THRESHOLD, BIT(31), ((X* oldval_0>>7) & 0x1)); |
| 6114 | |
| 6115 | Y = result[final_candidate][1]; |
| 6116 | if ((Y & 0x00000200) != 0) |
| 6117 | Y = Y | 0xFFFFFC00; |
| 6118 | TX0_C = (Y * oldval_0) >> 8; |
| 6119 | phy_set_bb_reg(priv, REG_OFDM_0_XC_TX_AFE, 0xF0000000, ((TX0_C&0x3C0)>>6)); |
| 6120 | phy_set_bb_reg(priv, REG_OFDM_0_XA_TX_IQ_IMBALANCE, 0x003F0000, (TX0_C&0x3F)); |
| 6121 | phy_set_bb_reg(priv, REG_OFDM_0_ECCA_THRESHOLD, BIT(29), ((Y* oldval_0>>7) & 0x1)); |
| 6122 | |
| 6123 | if(bTxOnly) { |
| 6124 | // RTPRINT(FINIT, INIT_IQK, ("_phy_path_a_fill_iqk_matrix only Tx OK\n")); |
| 6125 | return; |
| 6126 | } |
| 6127 | |
| 6128 | reg = result[final_candidate][2]; |
| 6129 | phy_set_bb_reg(priv, REG_OFDM_0_XA_RX_IQ_IMBALANCE, 0x3FF, reg); |
| 6130 | |
| 6131 | reg = result[final_candidate][3] & 0x3F; |
| 6132 | phy_set_bb_reg(priv, REG_OFDM_0_XA_RX_IQ_IMBALANCE, 0xFC00, reg); |
| 6133 | |
| 6134 | reg = (result[final_candidate][3] >> 6) & 0xF; |
| 6135 | phy_set_bb_reg(priv, 0xca0, 0xF0000000, reg); |
| 6136 | } |
| 6137 | } |
| 6138 | |
| 6139 | |
| 6140 | void _phy_path_b_fill_iqk_matrix(struct rtl8192cd_priv *priv, char bIQKOK, int result[][8], unsigned char final_candidate, char bTxOnly) |
| 6141 | { |
| 6142 | int oldval_1, X, TX1_A, reg; |
| 6143 | int Y, TX1_C; |
| 6144 | |
| 6145 | //RTPRINT(FINIT, INIT_IQK, ("Path B IQ Calibration %s !\n",(bIQKOK)?"Success":"Failed")); |
| 6146 | |
| 6147 | if(final_candidate == 0xFF) |
| 6148 | return; |
| 6149 | |
| 6150 | else if(bIQKOK) |
| 6151 | { |
| 6152 | oldval_1 = (phy_query_bb_reg(priv, REG_OFDM_0_XB_TX_IQ_IMBALANCE, bMaskDWord) >> 22) & 0x3FF; |
| 6153 | |
| 6154 | X = result[final_candidate][4]; |
| 6155 | if ((X & 0x00000200) != 0) |
| 6156 | X = X | 0xFFFFFC00; |
| 6157 | TX1_A = (X * oldval_1) >> 8; |
| 6158 | phy_set_bb_reg(priv, REG_OFDM_0_XB_TX_IQ_IMBALANCE, 0x3FF, TX1_A); |
| 6159 | phy_set_bb_reg(priv, REG_OFDM_0_ECCA_THRESHOLD, BIT(27), ((X* oldval_1>>7) & 0x1)); |
| 6160 | |
| 6161 | Y = result[final_candidate][5]; |
| 6162 | if ((Y & 0x00000200) != 0) |
| 6163 | Y = Y | 0xFFFFFC00; |
| 6164 | TX1_C = (Y * oldval_1) >> 8; |
| 6165 | phy_set_bb_reg(priv, REG_OFDM_0_XD_TX_AFE, 0xF0000000, ((TX1_C&0x3C0)>>6)); |
| 6166 | phy_set_bb_reg(priv, REG_OFDM_0_XB_TX_IQ_IMBALANCE, 0x003F0000, (TX1_C&0x3F)); |
| 6167 | phy_set_bb_reg(priv, REG_OFDM_0_ECCA_THRESHOLD, BIT(25), ((Y* oldval_1>>7) & 0x1)); |
| 6168 | |
| 6169 | if(bTxOnly) |
| 6170 | return; |
| 6171 | |
| 6172 | reg = result[final_candidate][6]; |
| 6173 | phy_set_bb_reg(priv, REG_OFDM_0_XB_RX_IQ_IMBALANCE, 0x3FF, reg); |
| 6174 | |
| 6175 | reg = result[final_candidate][7] & 0x3F; |
| 6176 | phy_set_bb_reg(priv, REG_OFDM_0_XB_RX_IQ_IMBALANCE, 0xFC00, reg); |
| 6177 | |
| 6178 | reg = (result[final_candidate][7] >> 6) & 0xF; |
| 6179 | phy_set_bb_reg(priv, REG_OFDM_0_AGC_RSSI_TABLE, 0x0000F000, reg); |
| 6180 | } |
| 6181 | } |
| 6182 | |
| 6183 | void _PHY_PathAStandBy_8192C(struct rtl8192cd_priv *priv) |
| 6184 | { |
| 6185 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0); |
| 6186 | phy_set_bb_reg(priv, 0x840, bMaskDWord, 0x00010000); |
| 6187 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0x808000); |
| 6188 | } |
| 6189 | |
| 6190 | void _PHY_IQCalibrate(struct rtl8192cd_priv *priv, int result[][8], unsigned char t, char is2T) |
| 6191 | { |
| 6192 | unsigned int i; |
| 6193 | unsigned char path_aok, path_bok; |
| 6194 | unsigned int ADDA_REG[IQK_ADDA_REG_NUM] = { 0x85c, 0xe6c, 0xe70, 0xe74, |
| 6195 | 0xe78, 0xe7c, 0xe80, 0xe84, |
| 6196 | 0xe88, 0xe8c, 0xed0, 0xed4, |
| 6197 | 0xed8, 0xedc, 0xee0, 0xeec }; |
| 6198 | unsigned int IQK_MAC_REG[IQK_MAC_REG_NUM] = {0x522, 0x550, 0x551, 0x040}; |
| 6199 | |
| 6200 | char isNormal = IS_TEST_CHIP(priv) ? 0 : 1; |
| 6201 | unsigned int retryCount = 2; |
| 6202 | |
| 6203 | #ifdef MP_TEST |
| 6204 | if(priv->pshare->rf_ft_var.mp_specific) |
| 6205 | retryCount = 9; |
| 6206 | #endif |
| 6207 | |
| 6208 | if(t==0) { |
| 6209 | // Save ADDA parameters, turn Path A ADDA on |
| 6210 | _phy_save_adda_registers(priv, ADDA_REG, priv->pshare->ADDA_backup, APK_AFE_REG_NUM); |
| 6211 | _phy_save_mac_registers(priv, IQK_MAC_REG, priv->pshare->IQK_MAC_backup); |
| 6212 | } |
| 6213 | |
| 6214 | _phy_path_adda_on(priv, ADDA_REG, TRUE, is2T); |
| 6215 | |
| 6216 | if(t==0) { |
| 6217 | // Store 0xC04, 0xC08, 0x874 vale |
| 6218 | priv->pshare->RegC04 = phy_query_bb_reg(priv, 0xc04, bMaskDWord); |
| 6219 | priv->pshare->RegC08 = phy_query_bb_reg(priv, 0xc08, bMaskDWord); |
| 6220 | priv->pshare->Reg874 = phy_query_bb_reg(priv, 0x874, bMaskDWord); |
| 6221 | } |
| 6222 | |
| 6223 | //MAC settings |
| 6224 | _phy_mac_setting_calibration(priv, IQK_MAC_REG, priv->pshare->IQK_MAC_backup); |
| 6225 | |
| 6226 | //phy_set_bb_reg(priv, 0x800, bMaskDWord, (phy_query_bb_reg(priv, 0x800, bMaskDWord)& ~ BIT(24))); |
| 6227 | phy_set_bb_reg(priv, 0xa04, bMaskDWord, (0x0f000000 | (phy_query_bb_reg(priv, 0xa04, bMaskDWord))) ); |
| 6228 | phy_set_bb_reg(priv, 0xc04, bMaskDWord, 0x03a05600); |
| 6229 | phy_set_bb_reg(priv, 0xc08, bMaskDWord, 0x000800e4); |
| 6230 | phy_set_bb_reg(priv, 0x874, bMaskDWord, 0x22204000); |
| 6231 | |
| 6232 | phy_set_bb_reg(priv, 0x870, BIT(10), 1); |
| 6233 | phy_set_bb_reg(priv, 0x870, BIT(26), 1); |
| 6234 | phy_set_bb_reg(priv, 0x860, BIT(10), 0); |
| 6235 | phy_set_bb_reg(priv, 0x864, BIT(10), 0); |
| 6236 | |
| 6237 | #if defined(HIGH_POWER_EXT_PA) && defined(CONFIG_RTL_92C_SUPPORT) |
| 6238 | //Allen TRSW to TX for external PA |
| 6239 | phy_set_bb_reg(priv, 0x870, 0x60, 3); |
| 6240 | phy_set_bb_reg(priv, 0x870, 0x600000, 3); |
| 6241 | phy_set_bb_reg(priv, 0x860, 0x60, 1); |
| 6242 | phy_set_bb_reg(priv, 0x864, 0x60, 1); |
| 6243 | #endif |
| 6244 | |
| 6245 | if(is2T) { |
| 6246 | phy_set_bb_reg(priv, 0x840, bMaskDWord, 0x00010000); |
| 6247 | phy_set_bb_reg(priv, 0x844, bMaskDWord, 0x00010000); |
| 6248 | } |
| 6249 | |
| 6250 | //Page B init |
| 6251 | if(isNormal) |
| 6252 | phy_set_bb_reg(priv, 0xb68, bMaskDWord, 0x00080000); |
| 6253 | else |
| 6254 | phy_set_bb_reg(priv, 0xb68, bMaskDWord, 0x0f600000); |
| 6255 | |
| 6256 | if(is2T) { |
| 6257 | if(isNormal) |
| 6258 | phy_set_bb_reg(priv, 0xb6c, bMaskDWord, 0x00080000); |
| 6259 | else |
| 6260 | phy_set_bb_reg(priv, 0xb6c, bMaskDWord, 0x0f600000); |
| 6261 | } |
| 6262 | |
| 6263 | // IQ calibration setting |
| 6264 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0x808000); |
| 6265 | phy_set_bb_reg(priv, 0xe40, bMaskDWord, 0x01007c00); |
| 6266 | phy_set_bb_reg(priv, 0xe44, bMaskDWord, 0x01004800); |
| 6267 | |
| 6268 | for(i = 0 ; i < retryCount ; i++){ |
| 6269 | path_aok = _PHY_PathA_IQK(priv, is2T); |
| 6270 | if(path_aok == 0x03){ |
| 6271 | result[t][0] = (phy_query_bb_reg(priv, 0xe94, bMaskDWord)&0x3FF0000)>>16; |
| 6272 | result[t][1] = (phy_query_bb_reg(priv, 0xe9c, bMaskDWord)&0x3FF0000)>>16; |
| 6273 | result[t][2] = (phy_query_bb_reg(priv, 0xea4, bMaskDWord)&0x3FF0000)>>16; |
| 6274 | result[t][3] = (phy_query_bb_reg(priv, 0xeac, bMaskDWord)&0x3FF0000)>>16; |
| 6275 | break; |
| 6276 | } |
| 6277 | else if (i == (retryCount-1) && path_aok == 0x01) //Tx IQK OK |
| 6278 | { |
| 6279 | result[t][0] = (phy_query_bb_reg(priv, 0xe94, bMaskDWord)&0x3FF0000)>>16; |
| 6280 | result[t][1] = (phy_query_bb_reg(priv, 0xe9c, bMaskDWord)&0x3FF0000)>>16; |
| 6281 | } |
| 6282 | } |
| 6283 | |
| 6284 | if(0x00 == path_aok){ |
| 6285 | // RTPRINT(FINIT, INIT_IQK, ("Path A IQK failed!!\n")); |
| 6286 | } |
| 6287 | |
| 6288 | if(is2T){ |
| 6289 | _PHY_PathAStandBy_8192C(priv); |
| 6290 | |
| 6291 | // Turn Path B ADDA on |
| 6292 | _phy_path_adda_on(priv, ADDA_REG, FALSE, is2T); |
| 6293 | |
| 6294 | for(i = 0 ; i < retryCount ; i++){ |
| 6295 | path_bok = _PHY_PathB_IQK(priv); |
| 6296 | if(path_bok == 0x03){ |
| 6297 | // RTPRINT(FINIT, INIT_IQK, ("Path B IQK Success!!\n")); |
| 6298 | result[t][4] = (phy_query_bb_reg(priv, 0xeb4, bMaskDWord)&0x3FF0000)>>16; |
| 6299 | result[t][5] = (phy_query_bb_reg(priv, 0xebc, bMaskDWord)&0x3FF0000)>>16; |
| 6300 | result[t][6] = (phy_query_bb_reg(priv, 0xec4, bMaskDWord)&0x3FF0000)>>16; |
| 6301 | result[t][7] = (phy_query_bb_reg(priv, 0xecc, bMaskDWord)&0x3FF0000)>>16; |
| 6302 | break; |
| 6303 | } |
| 6304 | else if (i == (retryCount - 1) && path_bok == 0x01) //Tx IQK OK |
| 6305 | { |
| 6306 | // RTPRINT(FINIT, INIT_IQK, ("Path B Only Tx IQK Success!!\n")); |
| 6307 | result[t][4] = (phy_query_bb_reg(priv, 0xeb4, bMaskDWord)&0x3FF0000)>>16; |
| 6308 | result[t][5] = (phy_query_bb_reg(priv, 0xebc, bMaskDWord)&0x3FF0000)>>16; |
| 6309 | } |
| 6310 | } |
| 6311 | |
| 6312 | if(0x00 == path_bok){ |
| 6313 | // RTPRINT(FINIT, INIT_IQK, ("Path B IQK failed!!\n")); |
| 6314 | } |
| 6315 | } |
| 6316 | |
| 6317 | //Back to BB mode, load original value |
| 6318 | // RTPRINT(FINIT, INIT_IQK, ("IQK:Back to BB mode, load original value!\n")); |
| 6319 | phy_set_bb_reg(priv, 0xc04, bMaskDWord, priv->pshare->RegC04); |
| 6320 | phy_set_bb_reg(priv, 0x874, bMaskDWord, priv->pshare->Reg874); |
| 6321 | phy_set_bb_reg(priv, 0xc08, bMaskDWord, priv->pshare->RegC08); |
| 6322 | |
| 6323 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0); |
| 6324 | |
| 6325 | // Restore RX initial gain |
| 6326 | phy_set_bb_reg(priv, 0x840, bMaskDWord, 0x00032ed3); |
| 6327 | |
| 6328 | if(is2T) |
| 6329 | phy_set_bb_reg(priv, 0x844, bMaskDWord, 0x00032ed3); |
| 6330 | |
| 6331 | if(t!=0) { |
| 6332 | // Reload ADDA power saving parameters |
| 6333 | _phy_reload_adda_registers(priv, ADDA_REG, priv->pshare->ADDA_backup, 16); |
| 6334 | |
| 6335 | // Reload MAC parameters |
| 6336 | _phy_reload_mac_registers(priv, IQK_MAC_REG, priv->pshare->IQK_MAC_backup); |
| 6337 | } |
| 6338 | } |
| 6339 | |
| 6340 | |
| 6341 | void PHY_IQCalibrate_92C(struct rtl8192cd_priv *priv) |
| 6342 | { |
| 6343 | int result[4][8]; //last is final result |
| 6344 | unsigned char i, final_candidate; |
| 6345 | char bPathAOK, bPathBOK; |
| 6346 | int RegE94, RegE9C, RegEA4, RegEAC, RegEB4, RegEBC, RegEC4, RegECC, RegTmp = 0; |
| 6347 | char is12simular, is13simular, is23simular; |
| 6348 | unsigned int temp_870, temp_860, temp_864, temp_a04; |
| 6349 | |
| 6350 | #ifdef MP_TEST |
| 6351 | if (!priv->pshare->rf_ft_var.mp_specific) |
| 6352 | #endif |
| 6353 | { |
| 6354 | if (priv->pshare->iqk_2g_done) |
| 6355 | return; |
| 6356 | priv->pshare->iqk_2g_done = 1; |
| 6357 | } |
| 6358 | |
| 6359 | priv->pshare->IQK_total_cnt++; |
| 6360 | |
| 6361 | temp_870 = phy_query_bb_reg(priv, 0x870, bMaskDWord); |
| 6362 | temp_860 = phy_query_bb_reg(priv, 0x860, bMaskDWord); |
| 6363 | temp_864 = phy_query_bb_reg(priv, 0x864, bMaskDWord); |
| 6364 | //temp_800 = phy_query_bb_reg(priv, 0x800, bMaskDWord); |
| 6365 | temp_a04 = phy_query_bb_reg(priv, 0xa04, bMaskDWord); |
| 6366 | |
| 6367 | memset(result, 0, sizeof(result)); |
| 6368 | |
| 6369 | final_candidate = 0xff; |
| 6370 | bPathAOK = FALSE; |
| 6371 | bPathBOK = FALSE; |
| 6372 | is12simular = FALSE; |
| 6373 | is23simular = FALSE; |
| 6374 | is13simular = FALSE; |
| 6375 | |
| 6376 | for (i=0; i<3; i++) { |
| 6377 | _PHY_IQCalibrate(priv, result, i, (GET_CHIP_VER(priv) == VERSION_8192C ? 1 : 0)); |
| 6378 | |
| 6379 | if(i == 1) { |
| 6380 | is12simular = _PHY_SimularityCompare(priv, result, 0, 1); |
| 6381 | if(is12simular) { |
| 6382 | final_candidate = 0; |
| 6383 | break; |
| 6384 | } |
| 6385 | } |
| 6386 | |
| 6387 | if(i == 2) { |
| 6388 | is13simular = _PHY_SimularityCompare(priv, result, 0, 2); |
| 6389 | if(is13simular) { |
| 6390 | final_candidate = 0; |
| 6391 | break; |
| 6392 | } |
| 6393 | |
| 6394 | is23simular = _PHY_SimularityCompare(priv, result, 1, 2); |
| 6395 | if(is23simular) |
| 6396 | final_candidate = 1; |
| 6397 | else |
| 6398 | { |
| 6399 | for(i = 0; i < 8; i++) |
| 6400 | RegTmp += result[3][i]; |
| 6401 | |
| 6402 | if(RegTmp != 0) |
| 6403 | final_candidate = 3; |
| 6404 | else |
| 6405 | final_candidate = 0xFF; |
| 6406 | } |
| 6407 | } |
| 6408 | } |
| 6409 | |
| 6410 | |
| 6411 | RTL_W32(0x870, temp_870); |
| 6412 | RTL_W32(0x860, temp_860); |
| 6413 | RTL_W32(0x864, temp_864); |
| 6414 | //RTL_W32(0x800, temp_800); |
| 6415 | RTL_W32(0xa04, temp_a04); |
| 6416 | |
| 6417 | //load 0xe30 IQC default value |
| 6418 | if(GET_CHIP_VER(priv) == VERSION_8188C) { |
| 6419 | RTL_W32(0xe30, 0x01008c00); |
| 6420 | RTL_W32(0xe34, 0x01008c00); |
| 6421 | } |
| 6422 | |
| 6423 | for (i=0; i<4; i++) { |
| 6424 | RegE94 = result[i][0]; |
| 6425 | RegE9C = result[i][1]; |
| 6426 | RegEA4 = result[i][2]; |
| 6427 | RegEAC = result[i][3]; |
| 6428 | RegEB4 = result[i][4]; |
| 6429 | RegEBC = result[i][5]; |
| 6430 | RegEC4 = result[i][6]; |
| 6431 | RegECC = result[i][7]; |
| 6432 | DEBUG_INFO("IQK: RegE94=%x RegE9C=%x RegEA4=%x RegEAC=%x RegEB4=%x RegEBC=%x RegEC4=%x RegECC=%x\n ", RegE94, RegE9C, RegEA4, RegEAC, RegEB4, RegEBC, RegEC4, RegECC); |
| 6433 | } |
| 6434 | |
| 6435 | if(final_candidate != 0xff) { |
| 6436 | priv->pshare->rege94 = RegE94 = result[final_candidate][0]; |
| 6437 | priv->pshare->rege9c = RegE9C = result[final_candidate][1]; |
| 6438 | RegEA4 = result[final_candidate][2]; |
| 6439 | RegEAC = result[final_candidate][3]; |
| 6440 | priv->pshare->regeb4 = RegEB4 = result[final_candidate][4]; |
| 6441 | priv->pshare->regebc = RegEBC = result[final_candidate][5]; |
| 6442 | RegEC4 = result[final_candidate][6]; |
| 6443 | RegECC = result[final_candidate][7]; |
| 6444 | DEBUG_INFO ("IQK: final_candidate is %x\n",final_candidate); |
| 6445 | DEBUG_INFO ("IQK: RegE94=%x RegE9C=%x RegEA4=%x RegEAC=%x RegEB4=%x RegEBC=%x RegEC4=%x RegECC=%x\n ", RegE94, RegE9C, RegEA4, RegEAC, RegEB4, RegEBC, RegEC4, RegECC); |
| 6446 | bPathAOK = bPathBOK = TRUE; |
| 6447 | } |
| 6448 | else { |
| 6449 | priv->pshare->rege94 = priv->pshare->regeb4 = 0x100; //X default value |
| 6450 | priv->pshare->rege9c = priv->pshare->regebc = 0x0; //Y default value |
| 6451 | priv->pshare->IQK_fail_cnt++; |
| 6452 | } |
| 6453 | |
| 6454 | if((RegE94 != 0)/*&&(RegEA4 != 0)*/) |
| 6455 | _phy_path_a_fill_iqk_matrix(priv, bPathAOK, result, final_candidate, (RegEA4 == 0)? 1 :0); |
| 6456 | if(GET_CHIP_VER(priv) == VERSION_8192C){ |
| 6457 | if((RegEB4 != 0)/*&&(RegEC4 != 0)*/) |
| 6458 | _phy_path_b_fill_iqk_matrix(priv, bPathBOK, result, final_candidate, (RegEC4 == 0)? 1 :0); |
| 6459 | } |
| 6460 | } |
| 6461 | |
| 6462 | #endif |
| 6463 | |
| 6464 | |
| 6465 | // 92d IQK |
| 6466 | #ifdef CONFIG_RTL_92D_SUPPORT |
| 6467 | void IQK_92D_5G_n(struct rtl8192cd_priv *priv) |
| 6468 | { |
| 6469 | unsigned int temp_a04, temp_c04, temp_874, temp_c08, temp_870, |
| 6470 | temp_860, temp_864, temp_88c, temp_c50, temp_c58, temp_b30, |
| 6471 | switch2PI=0, X, reg; //oldval_0, oldval_1, TX0_A, TX1_A; |
| 6472 | u8 temp_522, temp_550, temp_551; |
| 6473 | unsigned int cal_num=0, cal_retry=0, ADDA_backup[IQK_ADDA_REG_NUM]; |
| 6474 | int Y, result[8][3], result_final[8]={0,0,0,0,0,0,0,0}; //TX0_C, TX1_C; |
| 6475 | |
| 6476 | unsigned int i, RX0REG0xe40[3], RX0REG0xe40_final=0, REG0xe40, REG0xe94, REG0xe9c, delay_count; |
| 6477 | unsigned int REG0xeac, RX1REG0xe40[3], RX1REG0xe40_final=0, REG0xeb4, REG0xea4,REG0xec4; |
| 6478 | unsigned char TX0IQKOK = FALSE, TX1IQKOK = FALSE; |
| 6479 | unsigned int TX_X0, TX_Y0, TX_X1, TX_Y1, RX_X0, RX_Y0, RX_X1, RX_Y1; |
| 6480 | unsigned int ADDA_REG[IQK_ADDA_REG_NUM] = {0x85c, 0xe6c, 0xe70, 0xe74, 0xe78, 0xe7c, 0xe80, 0xe84, |
| 6481 | 0xe88, 0xe8c, 0xed0, 0xed4, 0xed8, 0xedc, 0xee0, 0xeec}; |
| 6482 | #ifdef CONFIG_RTL_92D_DMDP |
| 6483 | if (priv->pmib->dot11RFEntry.macPhyMode == DUALMAC_DUALPHY) |
| 6484 | return IQK_92D_5G_phy0_n(priv); |
| 6485 | #endif |
| 6486 | |
| 6487 | //always do IQK for MP mode |
| 6488 | #ifdef MP_TEST |
| 6489 | if (!priv->pshare->rf_ft_var.mp_specific) |
| 6490 | #endif |
| 6491 | { |
| 6492 | if (priv->pmib->dot11RFEntry.macPhyMode == SINGLEMAC_SINGLEPHY) { |
| 6493 | if (priv->pshare->iqk_5g_done) |
| 6494 | return; |
| 6495 | priv->pshare->iqk_5g_done = 1; |
| 6496 | } |
| 6497 | } |
| 6498 | |
| 6499 | printk(">> %s \n",__FUNCTION__); |
| 6500 | |
| 6501 | watchdog_kick(); |
| 6502 | |
| 6503 | /* |
| 6504 | * Save MAC default value |
| 6505 | */ |
| 6506 | temp_522 = RTL_R8(0x522); |
| 6507 | temp_550 = RTL_R8(0x550); |
| 6508 | temp_551 = RTL_R8(0x551); |
| 6509 | |
| 6510 | /* |
| 6511 | * Save BB Parameter |
| 6512 | */ |
| 6513 | temp_a04 = RTL_R32(0xa04);//RTL_R32(0x800); |
| 6514 | temp_c04 = RTL_R32(0xc04); |
| 6515 | temp_874 = RTL_R32(0x874); |
| 6516 | temp_c08 = RTL_R32(0xc08); |
| 6517 | temp_870 = RTL_R32(0x870); |
| 6518 | temp_860 = RTL_R32(0x860); |
| 6519 | temp_864 = RTL_R32(0x864); |
| 6520 | temp_88c = RTL_R32(0x88c); |
| 6521 | temp_c50 = RTL_R32(0xc50); // 01/11/2011 update |
| 6522 | temp_c58 = RTL_R32(0xc58); // 01/11/2011 update |
| 6523 | temp_b30 = RTL_R32(0xb30); // 03/03/2011 update |
| 6524 | |
| 6525 | /* |
| 6526 | * Save AFE Parameters |
| 6527 | */ |
| 6528 | for( i = 0 ; i < IQK_ADDA_REG_NUM ; i++) |
| 6529 | ADDA_backup[i] = RTL_R32(ADDA_REG[i]); |
| 6530 | |
| 6531 | /* |
| 6532 | * ============== |
| 6533 | * Path-A TX/RX IQK |
| 6534 | * ============== |
| 6535 | */ |
| 6536 | while (cal_num < 3) { |
| 6537 | /* |
| 6538 | * Path-A AFE all on |
| 6539 | */ |
| 6540 | for( i = 0 ; i < IQK_ADDA_REG_NUM ; i++) |
| 6541 | RTL_W32(ADDA_REG[i], 0x04db25a4); |
| 6542 | |
| 6543 | /* |
| 6544 | * MAC register setting |
| 6545 | */ |
| 6546 | RTL_W8(0x522, 0x3f); |
| 6547 | RTL_W8(0x550, RTL_R8(0x550)& (~BIT(3))); |
| 6548 | RTL_W8(0x551, RTL_R8(0x551)& (~BIT(3))); |
| 6549 | |
| 6550 | /* |
| 6551 | * IQK must be done in PI mode |
| 6552 | */ |
| 6553 | if (!phy_query_bb_reg(priv, 0x820, BIT(8)) || !phy_query_bb_reg(priv, 0x828, BIT(8))) { |
| 6554 | phy_set_bb_reg(priv, 0x820, bMaskDWord, 0x01000100); |
| 6555 | phy_set_bb_reg(priv, 0x828, bMaskDWord, 0x01000100); |
| 6556 | switch2PI++; |
| 6557 | } |
| 6558 | |
| 6559 | /* |
| 6560 | * BB setting |
| 6561 | */ |
| 6562 | //phy_set_bb_reg(priv, 0x800, BIT(24), 0); |
| 6563 | phy_set_bb_reg(priv, 0xa04, bMaskDWord, (0x0f000000 | temp_a04) ); |
| 6564 | phy_set_bb_reg(priv, 0xc04, bMaskDWord, 0x03a05600); |
| 6565 | phy_set_bb_reg(priv, 0xc08, bMaskDWord, 0x000800e4); |
| 6566 | phy_set_bb_reg(priv, 0x874, bMaskDWord, 0x22208000); |
| 6567 | phy_set_bb_reg(priv, 0x88c, BIT(23)|BIT(22)|BIT(21)|BIT(20), 0xf); |
| 6568 | phy_set_bb_reg(priv, 0xb30, bMaskDWord, 0x00a00000); // 03/03/2011 update |
| 6569 | |
| 6570 | /* |
| 6571 | * AP or IQK |
| 6572 | */ |
| 6573 | //phy_set_bb_reg(priv, 0xb68, bMaskDWord, 0x0f600000); |
| 6574 | //phy_set_bb_reg(priv, 0xb6c, bMaskDWord, 0x0f600000); |
| 6575 | |
| 6576 | // IQK-R03 2011/02/16 update |
| 6577 | |
| 6578 | //path A AP setting for IQK |
| 6579 | phy_set_bb_reg(priv, 0xb00, bMaskDWord, 0); |
| 6580 | phy_set_bb_reg(priv, 0xb68, bMaskDWord, 0x20000000); |
| 6581 | //path B AP setting for IQK |
| 6582 | phy_set_bb_reg(priv, 0xb70, bMaskDWord, 0); |
| 6583 | phy_set_bb_reg(priv, 0xb6c, bMaskDWord, 0x20000000); |
| 6584 | |
| 6585 | /* |
| 6586 | * IQK global setting |
| 6587 | */ |
| 6588 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0x808000); |
| 6589 | phy_set_bb_reg(priv, 0xe40, bMaskDWord, 0x10007c00); |
| 6590 | phy_set_bb_reg(priv, 0xe44, bMaskDWord, 0x01004800); |
| 6591 | |
| 6592 | /* |
| 6593 | * path-A IQK setting |
| 6594 | */ |
| 6595 | phy_set_bb_reg(priv, 0xe30, bMaskDWord, 0x18008c1f); |
| 6596 | phy_set_bb_reg(priv, 0xe34, bMaskDWord, 0x18008c1f); |
| 6597 | phy_set_bb_reg(priv, 0xe38, bMaskDWord, 0x82140307); // 01/11/2011 update |
| 6598 | #ifdef USB_POWER_SUPPORT |
| 6599 | phy_set_bb_reg(priv, 0xe3c, bMaskDWord, 0x68160c66); |
| 6600 | #else |
| 6601 | phy_set_bb_reg(priv, 0xe3c, bMaskDWord, 0x68160960); // 01/11/2011 update |
| 6602 | #endif |
| 6603 | |
| 6604 | /* |
| 6605 | * path-B IQK setting |
| 6606 | */ |
| 6607 | phy_set_bb_reg(priv, 0xe50, bMaskDWord, 0x18008c2f); |
| 6608 | phy_set_bb_reg(priv, 0xe54, bMaskDWord, 0x18008c2f); |
| 6609 | phy_set_bb_reg(priv, 0xe58, bMaskDWord, 0x82110000); |
| 6610 | phy_set_bb_reg(priv, 0xe5c, bMaskDWord, 0x68110000); |
| 6611 | |
| 6612 | /* |
| 6613 | * LO calibration setting |
| 6614 | */ |
| 6615 | phy_set_bb_reg(priv, 0xe4c, bMaskDWord, 0x00462911); |
| 6616 | |
| 6617 | #ifdef USB_POWER_SUPPORT |
| 6618 | // path-A TRSW setting |
| 6619 | phy_set_bb_reg(priv, 0x870, BIT(6)|BIT(5), 3); |
| 6620 | phy_set_bb_reg(priv, 0x860, BIT(6)|BIT(5), 3); |
| 6621 | #else |
| 6622 | /* |
| 6623 | * path-A PA on |
| 6624 | */ |
| 6625 | /* |
| 6626 | phy_set_bb_reg(priv, 0x870, BIT(11)|BIT(10), 3); |
| 6627 | phy_set_bb_reg(priv, 0x870, BIT(6)|BIT(5), 3); |
| 6628 | phy_set_bb_reg(priv, 0x860, BIT(11)|BIT(10), 3); |
| 6629 | */ |
| 6630 | phy_set_bb_reg(priv, 0x870, bMaskDWord, 0x07000f60); // 01/11/2011 update |
| 6631 | phy_set_bb_reg(priv, 0x860, bMaskDWord, 0x66e60e30); // 01/11/2011 update |
| 6632 | #endif |
| 6633 | /* |
| 6634 | * One shot, path A LOK & IQK |
| 6635 | */ |
| 6636 | phy_set_bb_reg(priv, 0xe48, bMaskDWord, 0xf9000000); |
| 6637 | phy_set_bb_reg(priv, 0xe48, bMaskDWord, 0xf8000000); |
| 6638 | |
| 6639 | /* |
| 6640 | * Delay 10 ms |
| 6641 | */ |
| 6642 | delay_ms(10); |
| 6643 | |
| 6644 | delay_count = 0; |
| 6645 | while (1){ |
| 6646 | REG0xeac = phy_query_bb_reg(priv, 0xeac, bMaskDWord); |
| 6647 | if ((REG0xeac&BIT(26))||(delay_count>20)){ |
| 6648 | break; |
| 6649 | }else { |
| 6650 | delay_ms(1); |
| 6651 | delay_count++; |
| 6652 | } |
| 6653 | } |
| 6654 | /* |
| 6655 | * Check_TX_IQK_A_result |
| 6656 | */ |
| 6657 | REG0xe40 = phy_query_bb_reg(priv, 0xe40, bMaskDWord); |
| 6658 | REG0xe94 = phy_query_bb_reg(priv, 0xe94, bMaskDWord); |
| 6659 | if(((REG0xeac&BIT(28)) == 0) && (((REG0xe94&0x3FF0000)>>16)!=0x142)) { |
| 6660 | TX0IQKOK = TRUE; |
| 6661 | REG0xe9c = phy_query_bb_reg(priv, 0xe9c, bMaskDWord); |
| 6662 | TX_X0 = (phy_query_bb_reg(priv, 0xe94, bMaskDWord)&0x3FF0000)>>16; |
| 6663 | TX_Y0 = (phy_query_bb_reg(priv, 0xe9c, bMaskDWord)&0x3FF0000)>>16; |
| 6664 | RX0REG0xe40[cal_num] = (REG0xe40 & 0xfc00fc00) | (TX_X0<<16) | TX_Y0; |
| 6665 | DEBUG_INFO("TX_X0 %08x TX_Y0 %08x RX0REG0xe40 %08x\n", TX_X0, TX_Y0, RX0REG0xe40[cal_num]); |
| 6666 | result[0][cal_num] = TX_X0; |
| 6667 | result[1][cal_num] = TX_Y0; |
| 6668 | } else { |
| 6669 | TX0IQKOK = FALSE; |
| 6670 | if (++cal_retry >= 10) { |
| 6671 | printk("%s Path-A Tx/Rx Check\n",__FUNCTION__); |
| 6672 | break; |
| 6673 | } |
| 6674 | } |
| 6675 | |
| 6676 | /* |
| 6677 | * Check_RX_IQK_A_result |
| 6678 | */ |
| 6679 | if(TX0IQKOK == TRUE) { |
| 6680 | REG0xeac = phy_query_bb_reg(priv, 0xeac, bMaskDWord); |
| 6681 | REG0xea4 = phy_query_bb_reg(priv, 0xea4, bMaskDWord); |
| 6682 | if(((REG0xeac&BIT(27)) == 0) && (((REG0xea4&0x3FF0000)>>16)!=0x132)) { |
| 6683 | RX_X0 = (phy_query_bb_reg(priv, 0xea4, bMaskDWord)&0x3FF0000)>>16; |
| 6684 | RX_Y0 = (phy_query_bb_reg(priv, 0xeac, bMaskDWord)&0x3FF0000)>>16; |
| 6685 | DEBUG_INFO("RX_X0 %08x RX_Y0 %08x\n", RX_X0, RX_Y0); |
| 6686 | result[2][cal_num] = RX_X0; |
| 6687 | result[3][cal_num] = RX_Y0; |
| 6688 | cal_num++; |
| 6689 | } else { |
| 6690 | phy_set_bb_reg(priv, 0xc14, bMaskDWord, 0x40000100); |
| 6691 | phy_set_bb_reg(priv, 0xe34, bMaskDWord, 0x19008c00); |
| 6692 | if (++cal_retry >= 10) { |
| 6693 | printk("%s Path-A Tx/Rx Check\n",__FUNCTION__); |
| 6694 | break; |
| 6695 | } |
| 6696 | } |
| 6697 | } |
| 6698 | } |
| 6699 | |
| 6700 | if (cal_num == 3) { |
| 6701 | result_final[0] = get_mean_of_2_close_value(result[0]); |
| 6702 | result_final[1] = get_mean_of_2_close_value(result[1]); |
| 6703 | result_final[2] = get_mean_of_2_close_value(result[2]); |
| 6704 | result_final[3] = get_mean_of_2_close_value(result[3]); |
| 6705 | RX0REG0xe40_final = 0x80000000 | get_mean_of_2_close_value(RX0REG0xe40); |
| 6706 | |
| 6707 | priv->pshare->RegE94=result_final[0]; |
| 6708 | priv->pshare->RegE9C=result_final[1]; |
| 6709 | } else { |
| 6710 | priv->pshare->RegE94=0x100; |
| 6711 | priv->pshare->RegE9C=0x00; |
| 6712 | } |
| 6713 | |
| 6714 | /* |
| 6715 | * Path-A PA off |
| 6716 | */ |
| 6717 | phy_set_bb_reg(priv, 0x870, bMaskDWord, temp_870); |
| 6718 | phy_set_bb_reg(priv, 0x860, bMaskDWord, temp_860); |
| 6719 | |
| 6720 | |
| 6721 | /* |
| 6722 | * ============== |
| 6723 | * Path-B TX/RX IQK |
| 6724 | * ============== |
| 6725 | */ |
| 6726 | cal_num = cal_retry = 0; |
| 6727 | while (cal_num < 3) { |
| 6728 | /* |
| 6729 | * Path-B AFE all on |
| 6730 | */ |
| 6731 | for( i = 0 ; i < IQK_ADDA_REG_NUM ; i++) |
| 6732 | phy_set_bb_reg(priv, ADDA_REG[i], bMaskDWord, 0x0b1b25a4); |
| 6733 | |
| 6734 | /* |
| 6735 | * path-A IQK setting |
| 6736 | */ |
| 6737 | phy_set_bb_reg(priv, 0xe30, bMaskDWord, 0x18008c1f); |
| 6738 | phy_set_bb_reg(priv, 0xe34, bMaskDWord, 0x18008c1f); |
| 6739 | phy_set_bb_reg(priv, 0xe38, bMaskDWord, 0x82110000); |
| 6740 | phy_set_bb_reg(priv, 0xe3c, bMaskDWord, 0x68110000); |
| 6741 | |
| 6742 | /* |
| 6743 | * path-B IQK setting |
| 6744 | */ |
| 6745 | phy_set_bb_reg(priv, 0xe50, bMaskDWord, 0x18008c22); |
| 6746 | phy_set_bb_reg(priv, 0xe54, bMaskDWord, 0x18008c22); |
| 6747 | phy_set_bb_reg(priv, 0xe58, bMaskDWord, 0x82140307); // 01/11/2011 update |
| 6748 | |
| 6749 | // 01/11/2011 update |
| 6750 | #ifdef USB_POWER_SUPPORT |
| 6751 | phy_set_bb_reg(priv, 0xe5c, bMaskDWord, 0x68160c66); |
| 6752 | #else |
| 6753 | phy_set_bb_reg(priv, 0xe5c, bMaskDWord, 0x68160960); // 01/11/2011 update |
| 6754 | #endif |
| 6755 | |
| 6756 | /* |
| 6757 | * LO calibration setting |
| 6758 | */ |
| 6759 | phy_set_bb_reg(priv, 0xe4c, bMaskDWord, 0x00462911); |
| 6760 | |
| 6761 | #ifdef USB_POWER_SUPPORT |
| 6762 | phy_set_bb_reg(priv, 0x870, BIT(22)|BIT(21), 3); |
| 6763 | phy_set_bb_reg(priv, 0x864, BIT(6)|BIT(5), 3); |
| 6764 | #else |
| 6765 | /* |
| 6766 | * path-B PA on |
| 6767 | */ |
| 6768 | /* |
| 6769 | phy_set_bb_reg(priv, 0x870, BIT(27)|BIT(26), 3); |
| 6770 | phy_set_bb_reg(priv, 0x870, BIT(22)|BIT(21), 3); |
| 6771 | phy_set_bb_reg(priv, 0x864, BIT(11)|BIT(10), 3); |
| 6772 | */ |
| 6773 | phy_set_bb_reg(priv, 0x870, bMaskDWord, 0x0f600700); |
| 6774 | phy_set_bb_reg(priv, 0x864, bMaskDWord, 0x061f0d30); |
| 6775 | #endif |
| 6776 | |
| 6777 | /* |
| 6778 | * One shot, path A LOK & IQK |
| 6779 | */ |
| 6780 | phy_set_bb_reg(priv, 0xe60, bMaskDWord, 0x00000002); |
| 6781 | phy_set_bb_reg(priv, 0xe60, bMaskDWord, 0x00000000); |
| 6782 | |
| 6783 | /* |
| 6784 | * Delay 10 ms |
| 6785 | */ |
| 6786 | delay_ms(10); |
| 6787 | |
| 6788 | delay_count = 0; |
| 6789 | while (1){ |
| 6790 | REG0xeac = phy_query_bb_reg(priv, 0xeac, bMaskDWord); |
| 6791 | if ((REG0xeac&BIT(29))||(delay_count>20)){ |
| 6792 | break; |
| 6793 | }else { |
| 6794 | delay_ms(1); |
| 6795 | delay_count++; |
| 6796 | } |
| 6797 | } |
| 6798 | /* |
| 6799 | * Check_TX_IQK_B_result |
| 6800 | */ |
| 6801 | REG0xe40 = phy_query_bb_reg(priv, 0xe40, bMaskDWord); |
| 6802 | REG0xeac = phy_query_bb_reg(priv, 0xeac, bMaskDWord); |
| 6803 | REG0xeb4 = phy_query_bb_reg(priv, 0xeb4, bMaskDWord); |
| 6804 | if(((REG0xeac&BIT(31)) == 0) && ((REG0xeb4&0x3FF0000)!=0x142)) { |
| 6805 | TX1IQKOK = TRUE; |
| 6806 | TX_X1 = (phy_query_bb_reg(priv, 0xeb4, bMaskDWord)&0x3FF0000)>>16; |
| 6807 | TX_Y1 = (phy_query_bb_reg(priv, 0xebc, bMaskDWord)&0x3FF0000)>>16; |
| 6808 | RX1REG0xe40[cal_num] = (REG0xe40 & 0xfc00fc00) | (TX_X1<<16) | TX_Y1; |
| 6809 | DEBUG_INFO("TX_X1 %08x TX_Y1 %08x RX1REG0xe40 %08x\n", TX_X1, TX_Y1, RX1REG0xe40[cal_num]); |
| 6810 | result[4][cal_num] = TX_X1; |
| 6811 | result[5][cal_num] = TX_Y1; |
| 6812 | } else { |
| 6813 | TX1IQKOK = FALSE; |
| 6814 | if (++cal_retry >= 10) { |
| 6815 | printk("%s Path-B Tx/Rx Check\n",__FUNCTION__); |
| 6816 | break; |
| 6817 | } |
| 6818 | } |
| 6819 | |
| 6820 | /* |
| 6821 | * Check_RX_IQK_B_result |
| 6822 | */ |
| 6823 | if(TX1IQKOK == TRUE) { |
| 6824 | REG0xeac = phy_query_bb_reg(priv, 0xeac, bMaskDWord); |
| 6825 | REG0xec4 = phy_query_bb_reg(priv, 0xec4, bMaskDWord); |
| 6826 | if(((REG0xeac&BIT(30)) == 0) && (((REG0xec4&0x3FF0000)>>16)!=0x132)) { |
| 6827 | RX_X1 = (phy_query_bb_reg(priv, 0xec4, bMaskDWord)&0x3FF0000)>>16; |
| 6828 | RX_Y1 = (phy_query_bb_reg(priv, 0xecc, bMaskDWord)&0x3FF0000)>>16; |
| 6829 | DEBUG_INFO("RX_X1 %08x RX_Y1 %08x\n", RX_X1, RX_Y1); |
| 6830 | result[6][cal_num] = RX_X1; |
| 6831 | result[7][cal_num] = RX_Y1; |
| 6832 | cal_num++; |
| 6833 | } else { |
| 6834 | phy_set_bb_reg(priv, 0xc1c, bMaskDWord, 0x40000100); |
| 6835 | phy_set_bb_reg(priv, 0xe54, bMaskDWord, 0x19008c00); |
| 6836 | if (++cal_retry >= 10) { |
| 6837 | printk("%s Path-B Tx/Rx Check\n",__FUNCTION__); |
| 6838 | break; |
| 6839 | } |
| 6840 | } |
| 6841 | } |
| 6842 | } |
| 6843 | |
| 6844 | if (cal_num == 3) { |
| 6845 | result_final[4] = get_mean_of_2_close_value(result[4]); |
| 6846 | result_final[5] = get_mean_of_2_close_value(result[5]); |
| 6847 | result_final[6] = get_mean_of_2_close_value(result[6]); |
| 6848 | result_final[7] = get_mean_of_2_close_value(result[7]); |
| 6849 | RX1REG0xe40_final = 0x80000000 | get_mean_of_2_close_value(RX1REG0xe40); |
| 6850 | |
| 6851 | priv->pshare->RegEB4=result_final[4]; |
| 6852 | priv->pshare->RegEBC=result_final[5]; |
| 6853 | } else { |
| 6854 | priv->pshare->RegEB4=0x100; |
| 6855 | priv->pshare->RegEBC=0x00; |
| 6856 | } |
| 6857 | |
| 6858 | /* |
| 6859 | * Fill IQK result for Path A |
| 6860 | */ |
| 6861 | if (result_final[0]) { |
| 6862 | /* |
| 6863 | oldval_0 = (phy_query_bb_reg(priv, 0xc80, bMaskDWord) >> 22) & 0x3FF; |
| 6864 | X = result_final[0]; |
| 6865 | if ((X & 0x00000200) != 0) |
| 6866 | X = X | 0xFFFFFC00; |
| 6867 | TX0_A = (X * oldval_0) >> 8; |
| 6868 | phy_set_bb_reg(priv, 0xc80, 0x3FF, TX0_A); |
| 6869 | phy_set_bb_reg(priv, 0xc4c, BIT(24), ((X* oldval_0>>7) & 0x1)); |
| 6870 | |
| 6871 | Y = result_final[1]; |
| 6872 | if ((Y & 0x00000200) != 0) |
| 6873 | Y = Y | 0xFFFFFC00; |
| 6874 | TX0_C = (Y * oldval_0) >> 8; |
| 6875 | phy_set_bb_reg(priv, 0xc94, 0xF0000000, ((TX0_C&0x3C0)>>6)); |
| 6876 | phy_set_bb_reg(priv, 0xc80, 0x003F0000, (TX0_C&0x3F)); |
| 6877 | phy_set_bb_reg(priv, 0xc4c, BIT(26), ((Y* oldval_0>>7) & 0x1)); |
| 6878 | */ |
| 6879 | |
| 6880 | // IQK-R03 2011/02/16 update |
| 6881 | X = result_final[0]; |
| 6882 | Y = result_final[1]; |
| 6883 | //printk("X=%x Y=%x\n",X,Y); |
| 6884 | //Path-A OFDM_A |
| 6885 | phy_set_bb_reg(priv, 0xe30, 0x03FF0000, X); |
| 6886 | phy_set_bb_reg(priv, 0xc4c, BIT(24), 0); |
| 6887 | //Path-A OFDM_C |
| 6888 | phy_set_bb_reg(priv, 0xe30, 0x000003FF, Y); |
| 6889 | phy_set_bb_reg(priv, 0xc4c, BIT(26), 0); |
| 6890 | |
| 6891 | if(result_final[2]) { |
| 6892 | reg = result_final[2]; |
| 6893 | phy_set_bb_reg(priv, 0xc14, 0x3FF, reg); |
| 6894 | reg = result_final[3] & 0x3F; |
| 6895 | phy_set_bb_reg(priv, 0xc14, 0xFC00, reg); |
| 6896 | |
| 6897 | reg = (result_final[3] >> 6) & 0xF; |
| 6898 | phy_set_bb_reg(priv, 0xca0, 0xF0000000, reg); |
| 6899 | |
| 6900 | phy_set_bb_reg(priv, 0xe34, 0x03FF0000, result_final[2]); // X |
| 6901 | phy_set_bb_reg(priv, 0xe34, 0x3FF, result_final[3]); //Y |
| 6902 | } |
| 6903 | } |
| 6904 | |
| 6905 | /* |
| 6906 | * Fill IQK result for Path B |
| 6907 | */ |
| 6908 | if (result_final[4]) { |
| 6909 | /* |
| 6910 | oldval_1 = (phy_query_bb_reg(priv, 0xc88, bMaskDWord) >> 22) & 0x3FF; |
| 6911 | |
| 6912 | X = result_final[4]; |
| 6913 | if ((X & 0x00000200) != 0) |
| 6914 | X = X | 0xFFFFFC00; |
| 6915 | TX1_A = (X * oldval_1) >> 8; |
| 6916 | phy_set_bb_reg(priv, 0xc88, 0x3FF, TX1_A); |
| 6917 | phy_set_bb_reg(priv, 0xc4c, BIT(28), ((X* oldval_1>>7) & 0x1)); |
| 6918 | |
| 6919 | Y = result_final[5]; |
| 6920 | if ((Y & 0x00000200) != 0) |
| 6921 | Y = Y | 0xFFFFFC00; |
| 6922 | TX1_C = (Y * oldval_1) >> 8; |
| 6923 | phy_set_bb_reg(priv, 0xc9c, 0xF0000000, ((TX1_C&0x3C0)>>6)); |
| 6924 | phy_set_bb_reg(priv, 0xc88, 0x003F0000, (TX1_C&0x3F)); |
| 6925 | phy_set_bb_reg(priv, 0xc4c, BIT(30), ((Y* oldval_1>>7) & 0x1)); |
| 6926 | */ |
| 6927 | |
| 6928 | // IQK-R03 2011/02/16 update |
| 6929 | X = result_final[4]; |
| 6930 | Y = result_final[5]; |
| 6931 | //printk("X=%x Y=%x\n",X,Y); |
| 6932 | //Path-A OFDM_A |
| 6933 | phy_set_bb_reg(priv, 0xe50, 0x03FF0000, X); |
| 6934 | phy_set_bb_reg(priv, 0xc4c, BIT(28), 0); |
| 6935 | //Path-A OFDM_C |
| 6936 | phy_set_bb_reg(priv, 0xe50, 0x000003FF, Y); |
| 6937 | phy_set_bb_reg(priv, 0xc4c, BIT(30), 0); |
| 6938 | |
| 6939 | if(result_final[6]) { |
| 6940 | reg = result_final[6]; |
| 6941 | phy_set_bb_reg(priv, 0xc1c, 0x3FF, reg); |
| 6942 | |
| 6943 | reg = result_final[7] & 0x3F; |
| 6944 | phy_set_bb_reg(priv, 0xc1c, 0xFC00, reg); |
| 6945 | |
| 6946 | reg = (result_final[7] >> 6) & 0xF; |
| 6947 | phy_set_bb_reg(priv, 0xc78, 0x0000F000, reg); |
| 6948 | |
| 6949 | phy_set_bb_reg(priv, 0xe54, 0x03FF0000, result_final[6]); // X |
| 6950 | phy_set_bb_reg(priv, 0xe54, 0x3FF, result_final[7]); //Y |
| 6951 | } |
| 6952 | } |
| 6953 | |
| 6954 | /* |
| 6955 | * Path B PA off |
| 6956 | */ |
| 6957 | phy_set_bb_reg(priv, 0x870, bMaskDWord, temp_870); |
| 6958 | phy_set_bb_reg(priv, 0x864, bMaskDWord, temp_864); |
| 6959 | |
| 6960 | /* |
| 6961 | * Exit IQK mode |
| 6962 | */ |
| 6963 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0); |
| 6964 | phy_set_bb_reg(priv, 0xc04, bMaskDWord, temp_c04); |
| 6965 | phy_set_bb_reg(priv, 0xc08, bMaskDWord, temp_c08); |
| 6966 | phy_set_bb_reg(priv, 0x874, bMaskDWord, temp_874); |
| 6967 | //phy_set_bb_reg(priv, 0x800, bMaskDWord, temp_800); |
| 6968 | phy_set_bb_reg(priv, 0xa04, bMaskDWord, temp_a04); |
| 6969 | phy_set_bb_reg(priv, 0x88c, bMaskDWord, temp_88c); |
| 6970 | phy_set_bb_reg(priv, 0xb30, bMaskDWord, temp_b30); // 03/03/2011 update |
| 6971 | //phy_set_bb_reg(priv, 0x840, bMaskDWord, 0x00032fff); // 01/11/2011 update |
| 6972 | //phy_set_bb_reg(priv, 0x844, bMaskDWord, 0x00032fff); // 01/11/2011 update |
| 6973 | |
| 6974 | // IQK-R03 2011/02/16 update |
| 6975 | //path A IQ path to DP block |
| 6976 | phy_set_bb_reg(priv, 0xb00, bMaskDWord, 0x010170b8); |
| 6977 | //path B IQ path to DP block |
| 6978 | phy_set_bb_reg(priv, 0xb70, bMaskDWord, 0x010170b8); |
| 6979 | |
| 6980 | //path AB to initial gain |
| 6981 | phy_set_bb_reg(priv, 0xc50, bMaskDWord, 0x50); // 01/11/2011 update |
| 6982 | phy_set_bb_reg(priv, 0xc50, bMaskDWord, temp_c50); // 01/11/2011 update |
| 6983 | phy_set_bb_reg(priv, 0xc58, bMaskDWord, 0x50); // 01/11/2011 update |
| 6984 | phy_set_bb_reg(priv, 0xc58, bMaskDWord, temp_c58); // 01/11/2011 update |
| 6985 | |
| 6986 | |
| 6987 | /* |
| 6988 | * Reload MAC default value |
| 6989 | */ |
| 6990 | RTL_W8(0x550, temp_550); |
| 6991 | RTL_W8(0x551, temp_551); |
| 6992 | RTL_W8(0x522, temp_522); |
| 6993 | |
| 6994 | /* |
| 6995 | * Switch back to SI if needed, after IQK |
| 6996 | */ |
| 6997 | if (switch2PI) { |
| 6998 | phy_set_bb_reg(priv, 0x820, bMaskDWord, 0x01000000); |
| 6999 | phy_set_bb_reg(priv, 0x828, bMaskDWord, 0x01000000); |
| 7000 | } |
| 7001 | |
| 7002 | /* |
| 7003 | * Reload ADDA power saving parameters |
| 7004 | */ |
| 7005 | for(i = 0 ; i < IQK_ADDA_REG_NUM ; i++) |
| 7006 | phy_set_bb_reg(priv, ADDA_REG[i], bMaskDWord, ADDA_backup[i]); |
| 7007 | |
| 7008 | |
| 7009 | #if 0 //def CLIENT_MODE |
| 7010 | clnt_save_IQK_res(priv); |
| 7011 | #endif |
| 7012 | |
| 7013 | if (!TX0IQKOK && !TX1IQKOK) |
| 7014 | priv->pshare->IQK_fail_cnt++; |
| 7015 | } |
| 7016 | |
| 7017 | |
| 7018 | void IQK_92D_2G(struct rtl8192cd_priv *priv) |
| 7019 | { |
| 7020 | unsigned int cal_num=0, cal_retry=0, Oldval=0, temp_c04=0, temp_c08=0, temp_874=0, temp_eac; |
| 7021 | unsigned int cal_e94, cal_e9c, cal_ea4, cal_eac, cal_eb4, cal_ebc, cal_ec4, cal_ecc; |
| 7022 | unsigned int X, Y, val_e94[3], val_e9c[3], val_ea4[3], val_eac[3], val_eb4[3], val_ebc[3], val_ec4[3], val_ecc[3]; |
| 7023 | unsigned int ADDA_REG[IQK_ADDA_REG_NUM] = {0x85c, 0xe6c, 0xe70, 0xe74, 0xe78, 0xe7c, 0xe80, 0xe84, |
| 7024 | 0xe88, 0xe8c, 0xed0, 0xed4, 0xed8, 0xedc, 0xee0, 0xeec}; |
| 7025 | unsigned int ADDA_backup[IQK_ADDA_REG_NUM], i; |
| 7026 | u8 temp_522, temp_550, temp_551; |
| 7027 | u32 temp_040, temp_a04, temp_870, temp_860, temp_864, temp_88c; |
| 7028 | u8 switch2PI = 0; |
| 7029 | unsigned char IQKOK = 0; |
| 7030 | |
| 7031 | #ifdef CONFIG_RTL_92D_DMDP |
| 7032 | if (priv->pmib->dot11RFEntry.macPhyMode == DUALMAC_DUALPHY) |
| 7033 | return IQK_92D_2G_phy1(priv); |
| 7034 | #endif |
| 7035 | |
| 7036 | //always do IQK for MP mode |
| 7037 | #ifdef MP_TEST |
| 7038 | if (!priv->pshare->rf_ft_var.mp_specific) |
| 7039 | #endif |
| 7040 | { |
| 7041 | if (priv->pmib->dot11RFEntry.macPhyMode == SINGLEMAC_SINGLEPHY) { |
| 7042 | if (priv->pshare->iqk_2g_done) |
| 7043 | return; |
| 7044 | priv->pshare->iqk_2g_done = 1; |
| 7045 | } |
| 7046 | } |
| 7047 | |
| 7048 | printk(">> %s \n",__FUNCTION__); |
| 7049 | |
| 7050 | // Save ADDA power saving parameters |
| 7051 | for( i = 0 ; i < IQK_ADDA_REG_NUM ; i++) |
| 7052 | ADDA_backup[i] = RTL_R32(ADDA_REG[i]); |
| 7053 | |
| 7054 | /* |
| 7055 | * Save MAC default value |
| 7056 | */ |
| 7057 | temp_522 = RTL_R8(0x522); |
| 7058 | temp_550 = RTL_R8(0x550); |
| 7059 | temp_551 = RTL_R8(0x551); |
| 7060 | temp_040 = RTL_R32(0x40); |
| 7061 | |
| 7062 | // Save BB default |
| 7063 | temp_a04 = RTL_R32(0xa04);//RTL_R32(0x800); |
| 7064 | temp_870 = RTL_R32(0x870); |
| 7065 | temp_860 = RTL_R32(0x860); |
| 7066 | temp_864 = RTL_R32(0x864); |
| 7067 | temp_88c = RTL_R32(0x88c); |
| 7068 | |
| 7069 | // Path-A ADDA all on |
| 7070 | for( i = 0 ; i < IQK_ADDA_REG_NUM ; i++) |
| 7071 | RTL_W32(ADDA_REG[i], 0x04db25a4); |
| 7072 | |
| 7073 | // IQ&LO calibration Setting |
| 7074 | //IQK must be done in PI mode |
| 7075 | if (!phy_query_bb_reg(priv, 0x820, BIT(8)) || !phy_query_bb_reg(priv, 0x828, BIT(8))) { |
| 7076 | phy_set_bb_reg(priv, 0x820, bMaskDWord, 0x01000100); |
| 7077 | phy_set_bb_reg(priv, 0x828, bMaskDWord, 0x01000100); |
| 7078 | switch2PI++; |
| 7079 | } |
| 7080 | |
| 7081 | //MAC register setting |
| 7082 | RTL_W8(0x522, 0x3f); |
| 7083 | RTL_W8(0x550, RTL_R8(0x550)& (~BIT(3))); |
| 7084 | RTL_W8(0x551, RTL_R8(0x551)& (~BIT(3))); |
| 7085 | RTL_W32(0x40, 0); |
| 7086 | |
| 7087 | //BB setting |
| 7088 | temp_c04 = RTL_R32(0xc04); |
| 7089 | temp_c08 = RTL_R32(0xc08); |
| 7090 | temp_874 = RTL_R32(0x874); |
| 7091 | //phy_set_bb_reg(priv,0x800,BIT(24),0); |
| 7092 | phy_set_bb_reg(priv, 0xa04, bMaskDWord, (0x0f000000 | temp_a04) ); |
| 7093 | RTL_W32(0xc04, 0x03a05600); |
| 7094 | RTL_W32(0xc08, 0x000800e4); |
| 7095 | RTL_W32(0x874, 0x22204000); |
| 7096 | |
| 7097 | phy_set_bb_reg(priv, 0x870, BIT(10), 1); |
| 7098 | phy_set_bb_reg(priv, 0x870, BIT(26), 1); |
| 7099 | phy_set_bb_reg(priv, 0x860, BIT(10), 0); |
| 7100 | phy_set_bb_reg(priv, 0x864, BIT(10), 0); |
| 7101 | |
| 7102 | phy_set_bb_reg(priv,0x88c,0x00f00000,0xf); |
| 7103 | RTL_W32(0x840, 0x00010000); |
| 7104 | RTL_W32(0x844, 0x00010000); |
| 7105 | |
| 7106 | //AP or IQK |
| 7107 | RTL_W32(0xb68 , 0x0f600000); |
| 7108 | RTL_W32(0xb6c , 0x0f600000); |
| 7109 | |
| 7110 | // IQK setting |
| 7111 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0x808000); |
| 7112 | RTL_W32(0xe40, 0x01007c00); |
| 7113 | RTL_W32(0xe44, 0x01004800); |
| 7114 | // path-A IQK setting |
| 7115 | RTL_W32(0xe30, 0x10008c1f); |
| 7116 | RTL_W32(0xe34, 0x10008c1f); |
| 7117 | RTL_W32(0xe38, 0x82140102); |
| 7118 | RTL_W32(0xe3c, 0x28160206); |
| 7119 | // path-B IQK setting |
| 7120 | RTL_W32(0xe50, 0x10008c22); |
| 7121 | RTL_W32(0xe54, 0x10008c22); |
| 7122 | RTL_W32(0xe58, 0x82140102); |
| 7123 | RTL_W32(0xe5c, 0x28160206); |
| 7124 | // LO calibration setting |
| 7125 | RTL_W32(0xe4c, 0x00462911); |
| 7126 | |
| 7127 | // delay to ensure Path-A IQK success |
| 7128 | delay_ms(10); |
| 7129 | |
| 7130 | // step 4: One shot, path A LOK & IQK |
| 7131 | while (cal_num < 3) { |
| 7132 | // One shot, path A LOK & IQK |
| 7133 | RTL_W32(0xe48, 0xf9000000); |
| 7134 | RTL_W32(0xe48, 0xf8000000); |
| 7135 | // delay 1ms |
| 7136 | delay_ms(1); |
| 7137 | |
| 7138 | // check fail bit and check abnormal condition, then fill BB IQ matrix |
| 7139 | cal_e94 = (RTL_R32(0xe94) >> 16) & 0x3ff; |
| 7140 | cal_e9c = (RTL_R32(0xe9c) >> 16) & 0x3ff; |
| 7141 | cal_ea4 = (RTL_R32(0xea4) >> 16) & 0x3ff; |
| 7142 | temp_eac = RTL_R32(0xeac); |
| 7143 | cal_eac = (temp_eac >> 16) & 0x3ff; |
| 7144 | if (!(temp_eac & BIT(28)) && !(temp_eac & BIT(27)) && |
| 7145 | (cal_e94 != 0x142) && (cal_e9c != 0x42) && |
| 7146 | (cal_ea4 != 0x132) && (cal_eac != 0x36)) { |
| 7147 | val_e94[cal_num] = cal_e94; |
| 7148 | val_e9c[cal_num] = cal_e9c; |
| 7149 | val_ea4[cal_num] = cal_ea4; |
| 7150 | val_eac[cal_num] = cal_eac; |
| 7151 | cal_num++; |
| 7152 | } else { |
| 7153 | if (++cal_retry >= 10) { |
| 7154 | printk("%s Path-A Check\n",__FUNCTION__); |
| 7155 | break; |
| 7156 | } |
| 7157 | } |
| 7158 | } |
| 7159 | |
| 7160 | if (cal_num == 3) { |
| 7161 | cal_e94 = get_mean_of_2_close_value(val_e94); |
| 7162 | cal_e9c = get_mean_of_2_close_value(val_e9c); |
| 7163 | cal_ea4 = get_mean_of_2_close_value(val_ea4); |
| 7164 | cal_eac = get_mean_of_2_close_value(val_eac); |
| 7165 | |
| 7166 | priv->pshare->RegE94=cal_e94; |
| 7167 | priv->pshare->RegE9C=cal_e9c; |
| 7168 | |
| 7169 | Oldval = (RTL_R32(0xc80) >> 22) & 0x3ff; |
| 7170 | |
| 7171 | X = cal_e94; |
| 7172 | phy_set_bb_reg(priv, 0xc80, 0x3ff, (X * Oldval)>>8); |
| 7173 | phy_set_bb_reg(priv, 0xc4c, BIT(24), ((X * Oldval) >> 7) & 0x1); |
| 7174 | |
| 7175 | Y = cal_e9c; |
| 7176 | if ((Y & 0x00000200) != 0) |
| 7177 | Y = Y | 0xFFFFFC00; |
| 7178 | phy_set_bb_reg(priv, 0xc94, 0xf0000000, (((Y * Oldval) >> 8) >> 6) & 0xf); |
| 7179 | phy_set_bb_reg(priv, 0xc80, 0x003f0000, ((Y * Oldval) >> 8) & 0x3f); |
| 7180 | phy_set_bb_reg(priv, 0xc4c, BIT(26), ((Y * Oldval) >> 7) & 0x1); |
| 7181 | |
| 7182 | phy_set_bb_reg(priv, 0xc14, 0x3ff, cal_ea4); |
| 7183 | |
| 7184 | phy_set_bb_reg(priv, 0xc14, 0xfc00, cal_eac & 0x3f); |
| 7185 | |
| 7186 | phy_set_bb_reg(priv, 0xca0, 0xf0000000, (cal_eac >> 6) & 0xf); |
| 7187 | }else { |
| 7188 | IQKOK++; |
| 7189 | priv->pshare->RegE94=0x100; |
| 7190 | priv->pshare->RegE9C=0x00; |
| 7191 | } |
| 7192 | |
| 7193 | // step 5: Path-A standby mode |
| 7194 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0); |
| 7195 | RTL_W32(0x840, 0x00010000); |
| 7196 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0x808000); |
| 7197 | |
| 7198 | // step 6: Path-B ADDA all on |
| 7199 | for( i = 0 ; i < IQK_ADDA_REG_NUM ; i++) |
| 7200 | RTL_W32(ADDA_REG[i], 0x0b1b25a4); |
| 7201 | |
| 7202 | // step 7: One shot, path B LOK & IQK |
| 7203 | cal_num = 0; |
| 7204 | cal_retry = 0; |
| 7205 | while (cal_num < 3) { |
| 7206 | // One shot, path B LOK & IQK |
| 7207 | RTL_W32(0xe60, 2); |
| 7208 | RTL_W32(0xe60, 0); |
| 7209 | // delay 1ms |
| 7210 | delay_ms(1); |
| 7211 | |
| 7212 | // check fail bit and check abnormal condition, then fill BB IQ matrix |
| 7213 | cal_eb4 = (RTL_R32(0xeb4) >> 16) & 0x3ff; |
| 7214 | cal_ebc = (RTL_R32(0xebc) >> 16) & 0x3ff; |
| 7215 | cal_ec4 = (RTL_R32(0xec4) >> 16) & 0x3ff; |
| 7216 | cal_ecc = (RTL_R32(0xecc) >> 16) & 0x3ff; |
| 7217 | temp_eac = RTL_R32(0xeac); |
| 7218 | if (!(temp_eac & BIT(31)) && !(temp_eac & BIT(30)) && |
| 7219 | (cal_eb4 != 0x142) && (cal_ebc != 0x42) && |
| 7220 | (cal_ec4 != 0x132) && (cal_ecc != 0x36)) { |
| 7221 | val_eb4[cal_num] = cal_eb4; |
| 7222 | val_ebc[cal_num] = cal_ebc; |
| 7223 | val_ec4[cal_num] = cal_ec4; |
| 7224 | val_ecc[cal_num] = cal_ecc; |
| 7225 | cal_num++; |
| 7226 | } else { |
| 7227 | if (++cal_retry >= 10) { |
| 7228 | printk("%s Path-B Check\n",__FUNCTION__); |
| 7229 | break; |
| 7230 | } |
| 7231 | } |
| 7232 | } |
| 7233 | |
| 7234 | if (cal_num == 3) { |
| 7235 | cal_eb4 = get_mean_of_2_close_value(val_eb4); |
| 7236 | cal_ebc = get_mean_of_2_close_value(val_ebc); |
| 7237 | cal_ec4 = get_mean_of_2_close_value(val_ec4); |
| 7238 | cal_ecc = get_mean_of_2_close_value(val_ecc); |
| 7239 | |
| 7240 | priv->pshare->RegEB4=cal_eb4; |
| 7241 | priv->pshare->RegEBC=cal_ebc; |
| 7242 | |
| 7243 | Oldval = (RTL_R32(0xc88) >> 22) & 0x3ff; |
| 7244 | |
| 7245 | X = cal_eb4; |
| 7246 | phy_set_bb_reg(priv, 0xc88, 0x3ff, (X * Oldval) >> 8 ); |
| 7247 | phy_set_bb_reg(priv, 0xc4c, BIT(28), ((X * Oldval) >> 7) & 0x1); |
| 7248 | |
| 7249 | Y = cal_ebc; |
| 7250 | if ((Y & 0x00000200) != 0) |
| 7251 | Y = Y | 0xFFFFFC00; |
| 7252 | phy_set_bb_reg(priv, 0xc9c, 0xf0000000, (((Y * Oldval) >> 8 ) >> 6) & 0xf); |
| 7253 | phy_set_bb_reg(priv, 0xc88, 0x003f0000, ((Y * Oldval) >> 8 ) & 0x3f); |
| 7254 | phy_set_bb_reg(priv, 0xc4c, BIT(30), ((Y * Oldval) >> 7) & 0x1); |
| 7255 | |
| 7256 | phy_set_bb_reg(priv, 0xc1c, 0x3ff, cal_ec4); |
| 7257 | |
| 7258 | phy_set_bb_reg(priv, 0xc1c, 0xfc00, cal_ecc & 0x3f); |
| 7259 | |
| 7260 | phy_set_bb_reg(priv, 0xc78, 0xf000, (cal_ecc >> 6) & 0xf); |
| 7261 | }else { |
| 7262 | IQKOK++; |
| 7263 | priv->pshare->RegEB4=0x100; |
| 7264 | priv->pshare->RegEBC=0x00; |
| 7265 | } |
| 7266 | |
| 7267 | // step 8: back to BB mode, load original values |
| 7268 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0); |
| 7269 | RTL_W32(0xc04, temp_c04); |
| 7270 | RTL_W32(0xc08, temp_c08); |
| 7271 | RTL_W32(0x874, temp_874); |
| 7272 | //RTL_W32(0x800, temp_800); |
| 7273 | RTL_W32(0xa04, temp_a04); |
| 7274 | RTL_W32(0x88c, temp_88c); |
| 7275 | RTL_W32(0x840, 0x32fff); |
| 7276 | RTL_W32(0x844, 0x32fff); |
| 7277 | RTL_W32(0x870, temp_870); |
| 7278 | RTL_W32(0x860, temp_860); |
| 7279 | RTL_W32(0x864, temp_864); |
| 7280 | |
| 7281 | /* |
| 7282 | * Switch back to SI if needed, after IQK |
| 7283 | */ |
| 7284 | if (switch2PI) { |
| 7285 | phy_set_bb_reg(priv, 0x820, bMaskDWord, 0x01000000); |
| 7286 | phy_set_bb_reg(priv, 0x828, bMaskDWord, 0x01000000); |
| 7287 | } |
| 7288 | |
| 7289 | watchdog_kick(); |
| 7290 | |
| 7291 | /* |
| 7292 | * Reload ADDA power saving parameters |
| 7293 | */ |
| 7294 | for(i = 0 ; i < IQK_ADDA_REG_NUM ; i++) |
| 7295 | phy_set_bb_reg(priv, ADDA_REG[i], bMaskDWord, ADDA_backup[i]); |
| 7296 | |
| 7297 | /* |
| 7298 | * Reload MAC default value |
| 7299 | */ |
| 7300 | RTL_W8(0x550, temp_550); |
| 7301 | RTL_W8(0x551, temp_551); |
| 7302 | RTL_W32(0x40, temp_040); |
| 7303 | RTL_W8(0x522, temp_522); |
| 7304 | |
| 7305 | |
| 7306 | #if 0 //def CLIENT_MODE |
| 7307 | clnt_save_IQK_res(priv); |
| 7308 | #endif |
| 7309 | if (!IQKOK) |
| 7310 | priv->pshare->IQK_fail_cnt++; |
| 7311 | } |
| 7312 | #ifdef CONFIG_RTL_92D_DMDP |
| 7313 | |
| 7314 | void IQK_92D_2G_phy1(struct rtl8192cd_priv *priv) |
| 7315 | { |
| 7316 | unsigned int cal_num=0, cal_retry=0, Oldval=0, temp_c04=0, temp_c08=0, temp_874=0, temp_eac; |
| 7317 | unsigned int cal_e94, cal_e9c, cal_ea4, cal_eac; |
| 7318 | unsigned int X, Y, val_e94[3], val_e9c[3], val_ea4[3], val_eac[3]; |
| 7319 | unsigned int ADDA_REG[IQK_ADDA_REG_NUM] = {0x85c, 0xe6c, 0xe70, 0xe74, 0xe78, 0xe7c, 0xe80, 0xe84, |
| 7320 | 0xe88, 0xe8c, 0xed0, 0xed4, 0xed8, 0xedc, 0xee0, 0xeec}; |
| 7321 | unsigned int ADDA_backup[IQK_ADDA_REG_NUM], i; |
| 7322 | u8 temp_522, temp_550, temp_551; |
| 7323 | u32 temp_040, temp_870, temp_860, temp_864, temp_a04, temp_88c; |
| 7324 | u8 switch2PI = 0; |
| 7325 | unsigned char IQKOK = 0; |
| 7326 | |
| 7327 | #ifdef MP_TEST |
| 7328 | if (!priv->pshare->rf_ft_var.mp_specific) |
| 7329 | #endif |
| 7330 | { |
| 7331 | if (priv->pshare->iqk_2g_done) |
| 7332 | return; |
| 7333 | priv->pshare->iqk_2g_done = 1; |
| 7334 | } |
| 7335 | |
| 7336 | printk(">> %s \n",__FUNCTION__); |
| 7337 | |
| 7338 | // Save ADDA power saving parameters |
| 7339 | for( i = 0 ; i < IQK_ADDA_REG_NUM ; i++) |
| 7340 | ADDA_backup[i] = RTL_R32(ADDA_REG[i]); |
| 7341 | |
| 7342 | /* |
| 7343 | * Save MAC default value |
| 7344 | */ |
| 7345 | temp_522 = RTL_R8(0x522); |
| 7346 | temp_550 = RTL_R8(0x550); |
| 7347 | temp_551 = RTL_R8(0x551); |
| 7348 | temp_040 = RTL_R32(0x40); |
| 7349 | |
| 7350 | // Save BB default |
| 7351 | temp_a04 = RTL_R32(0xa04);//RTL_R32(0x800); |
| 7352 | temp_870 = RTL_R32(0x870); |
| 7353 | temp_860 = RTL_R32(0x860); |
| 7354 | temp_864 = RTL_R32(0x864); |
| 7355 | temp_88c = RTL_R32(0x88c); |
| 7356 | |
| 7357 | // Path-A ADDA all on |
| 7358 | for( i = 0 ; i < IQK_ADDA_REG_NUM ; i++) { |
| 7359 | #ifdef NON_INTR_ANTDIV |
| 7360 | if (DMDP_PHY_QueryBBReg(0, 0xb30,BIT(27))) |
| 7361 | RTL_W32(ADDA_REG[i], 0x04db25a4); |
| 7362 | else |
| 7363 | #endif |
| 7364 | RTL_W32(ADDA_REG[i], 0x0b1b25a4); |
| 7365 | } |
| 7366 | |
| 7367 | |
| 7368 | // IQ&LO calibration Setting |
| 7369 | |
| 7370 | /* |
| 7371 | * IQK must be done in PI mode |
| 7372 | */ |
| 7373 | if (!phy_query_bb_reg(priv, 0x820, BIT(8)) || !phy_query_bb_reg(priv, 0x828, BIT(8))) { |
| 7374 | phy_set_bb_reg(priv, 0x820, bMaskDWord, 0x01000100); |
| 7375 | phy_set_bb_reg(priv, 0x828, bMaskDWord, 0x01000100); |
| 7376 | switch2PI++; |
| 7377 | } |
| 7378 | |
| 7379 | //MAC register setting |
| 7380 | RTL_W8(0x522, 0x3f); |
| 7381 | RTL_W8(0x550, RTL_R8(0x550)& (~BIT(3))); |
| 7382 | RTL_W8(0x551, RTL_R8(0x551)& (~BIT(3))); |
| 7383 | RTL_W32(0x40, 0); |
| 7384 | |
| 7385 | //BB setting |
| 7386 | temp_c04 = RTL_R32(0xc04); |
| 7387 | temp_c08 = RTL_R32(0xc08); |
| 7388 | temp_874 = RTL_R32(0x874); |
| 7389 | //phy_set_bb_reg(priv, 0x800, BIT(24), 0); |
| 7390 | phy_set_bb_reg(priv, 0xa04, bMaskDWord, (0x0f000000 | temp_a04) ); |
| 7391 | RTL_W32(0xc04, 0x03a05600); |
| 7392 | RTL_W32(0xc08, 0x000800e4); |
| 7393 | RTL_W32(0x874, 0x22204000); |
| 7394 | |
| 7395 | phy_set_bb_reg(priv, 0x870, BIT(10), 1); |
| 7396 | phy_set_bb_reg(priv, 0x870, BIT(26), 1); |
| 7397 | phy_set_bb_reg(priv, 0x860, BIT(10), 0); |
| 7398 | phy_set_bb_reg(priv, 0x864, BIT(10), 0); |
| 7399 | |
| 7400 | phy_set_bb_reg(priv,0x88c,0x00f00000,0xf); |
| 7401 | |
| 7402 | RTL_W32(0x840, 0x00010000); |
| 7403 | |
| 7404 | //AP or IQK |
| 7405 | RTL_W32(0xb68 , 0x0f600000); |
| 7406 | RTL_W32(0xb6c , 0x0f600000); |
| 7407 | |
| 7408 | // IQK setting |
| 7409 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0x808000); |
| 7410 | RTL_W32(0xe40, 0x01007c00); |
| 7411 | RTL_W32(0xe44, 0x01004800); |
| 7412 | |
| 7413 | // path-A IQK setting |
| 7414 | RTL_W32(0xe30, 0x10008c22); |
| 7415 | RTL_W32(0xe34, 0x10008c22); |
| 7416 | RTL_W32(0xe38, 0x82140102); |
| 7417 | RTL_W32(0xe3c, 0x28160206); |
| 7418 | |
| 7419 | // LO calibration setting |
| 7420 | RTL_W32(0xe4c, 0x00462911); |
| 7421 | |
| 7422 | // delay to ensure Path-A IQK success |
| 7423 | delay_ms(10); |
| 7424 | |
| 7425 | // step 4: One shot, path A LOK & IQK |
| 7426 | while (cal_num < 3) { |
| 7427 | // One shot, path A LOK & IQK |
| 7428 | RTL_W32(0xe48, 0xf9000000); |
| 7429 | RTL_W32(0xe48, 0xf8000000); |
| 7430 | // delay 1ms |
| 7431 | delay_ms(1); |
| 7432 | |
| 7433 | // check fail bit and check abnormal condition, then fill BB IQ matrix |
| 7434 | cal_e94 = (RTL_R32(0xe94) >> 16) & 0x3ff; |
| 7435 | cal_e9c = (RTL_R32(0xe9c) >> 16) & 0x3ff; |
| 7436 | cal_ea4 = (RTL_R32(0xea4) >> 16) & 0x3ff; |
| 7437 | temp_eac = RTL_R32(0xeac); |
| 7438 | cal_eac = (temp_eac >> 16) & 0x3ff; |
| 7439 | if (!(temp_eac & BIT(28)) && !(temp_eac & BIT(27)) && |
| 7440 | (cal_e94 != 0x142) && (cal_e9c != 0x42) && |
| 7441 | (cal_ea4 != 0x132) && (cal_eac != 0x36)) { |
| 7442 | val_e94[cal_num] = cal_e94; |
| 7443 | val_e9c[cal_num] = cal_e9c; |
| 7444 | val_ea4[cal_num] = cal_ea4; |
| 7445 | val_eac[cal_num] = cal_eac; |
| 7446 | cal_num++; |
| 7447 | } else { |
| 7448 | if (++cal_retry >= 10) { |
| 7449 | printk("%s Path-A Check\n",__FUNCTION__); |
| 7450 | break; |
| 7451 | } |
| 7452 | } |
| 7453 | } |
| 7454 | |
| 7455 | if (cal_num == 3) { |
| 7456 | cal_e94 = get_mean_of_2_close_value(val_e94); |
| 7457 | cal_e9c = get_mean_of_2_close_value(val_e9c); |
| 7458 | cal_ea4 = get_mean_of_2_close_value(val_ea4); |
| 7459 | cal_eac = get_mean_of_2_close_value(val_eac); |
| 7460 | |
| 7461 | priv->pshare->RegE94=cal_e94; |
| 7462 | priv->pshare->RegE9C=cal_e9c; |
| 7463 | |
| 7464 | Oldval = (RTL_R32(0xc80) >> 22) & 0x3ff; |
| 7465 | |
| 7466 | X = cal_e94; |
| 7467 | phy_set_bb_reg(priv, 0xc80, 0x3ff, (X * Oldval) >> 8); |
| 7468 | phy_set_bb_reg(priv, 0xc4c, BIT(24), ((X * Oldval) >> 7) & 0x1); |
| 7469 | |
| 7470 | Y = cal_e9c; |
| 7471 | if ((Y & 0x00000200) != 0) |
| 7472 | Y = Y | 0xFFFFFC00; |
| 7473 | phy_set_bb_reg(priv, 0xc94, 0xf0000000, (((Y * Oldval) >> 8) >> 6) & 0xf); |
| 7474 | phy_set_bb_reg(priv, 0xc80, 0x003f0000, ((Y * Oldval) >> 8) & 0x3f); |
| 7475 | phy_set_bb_reg(priv, 0xc4c, BIT(26), ((Y * Oldval) >> 7) & 0x1); |
| 7476 | |
| 7477 | phy_set_bb_reg(priv, 0xc14, 0x3ff, cal_ea4); |
| 7478 | |
| 7479 | phy_set_bb_reg(priv, 0xc14, 0xfc00, cal_eac & 0x3f); |
| 7480 | |
| 7481 | phy_set_bb_reg(priv, 0xca0, 0xf0000000, (cal_eac >> 6) & 0xf); |
| 7482 | }else { |
| 7483 | IQKOK++; |
| 7484 | priv->pshare->RegE94=0x100; |
| 7485 | priv->pshare->RegE9C=0x00; |
| 7486 | } |
| 7487 | |
| 7488 | // back to BB mode, load original values |
| 7489 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0); |
| 7490 | RTL_W32(0xc04, temp_c04); |
| 7491 | RTL_W32(0xc08, temp_c08); |
| 7492 | RTL_W32(0x874, temp_874); |
| 7493 | //RTL_W32(0x800, temp_800); |
| 7494 | RTL_W32(0xa04, temp_a04); |
| 7495 | |
| 7496 | RTL_W32(0x88c, temp_88c); |
| 7497 | RTL_W32(0x840, 0x32fff); |
| 7498 | RTL_W32(0x870, temp_870); |
| 7499 | RTL_W32(0x860, temp_860); |
| 7500 | RTL_W32(0x864, temp_864); |
| 7501 | |
| 7502 | // return to SI mode |
| 7503 | if (switch2PI) { |
| 7504 | RTL_W32(0x820, 0x01000000); |
| 7505 | RTL_W32(0x828, 0x01000000); |
| 7506 | } |
| 7507 | |
| 7508 | watchdog_kick(); |
| 7509 | |
| 7510 | /* |
| 7511 | * Reload ADDA power saving parameters |
| 7512 | */ |
| 7513 | for(i = 0 ; i < IQK_ADDA_REG_NUM ; i++) |
| 7514 | phy_set_bb_reg(priv, ADDA_REG[i], bMaskDWord, ADDA_backup[i]); |
| 7515 | |
| 7516 | /* |
| 7517 | * Reload MAC default value |
| 7518 | */ |
| 7519 | RTL_W8(0x550, temp_550); |
| 7520 | RTL_W8(0x551, temp_551); |
| 7521 | RTL_W32(0x40, temp_040); |
| 7522 | RTL_W8(0x522, temp_522); |
| 7523 | |
| 7524 | if (!IQKOK) |
| 7525 | priv->pshare->IQK_fail_cnt++; |
| 7526 | } |
| 7527 | |
| 7528 | |
| 7529 | void IQK_92D_5G_phy0_n(struct rtl8192cd_priv *priv) |
| 7530 | { |
| 7531 | unsigned int temp_a04, temp_c04, temp_874, temp_c08, temp_870, temp_860, temp_88c, temp_c50, temp_b30, |
| 7532 | switch2PI=0, X, reg; //, oldval_0, TX0_A; |
| 7533 | u8 temp_522, temp_550, temp_551; |
| 7534 | unsigned int cal_num=0, cal_retry=0, ADDA_backup[IQK_ADDA_REG_NUM]; |
| 7535 | int Y, result[8][3], result_final[8]={0,0,0,0,0,0,0,0}; //, TX0_C; |
| 7536 | |
| 7537 | unsigned int i, RX0REG0xe40[3], RX0REG0xe40_final=0, REG0xe40, REG0xe94, REG0xe9c, delay_count; |
| 7538 | unsigned int REG0xeac, REG0xea4; |
| 7539 | unsigned char TX0IQKOK = FALSE; |
| 7540 | unsigned int TX_X0, TX_Y0, RX_X0, RX_Y0; |
| 7541 | unsigned int ADDA_REG[IQK_ADDA_REG_NUM] = {0x85c, 0xe6c, 0xe70, 0xe74, 0xe78, 0xe7c, 0xe80, 0xe84, |
| 7542 | 0xe88, 0xe8c, 0xed0, 0xed4, 0xed8, 0xedc, 0xee0, 0xeec}; |
| 7543 | |
| 7544 | #ifdef MP_TEST |
| 7545 | if (!priv->pshare->rf_ft_var.mp_specific) |
| 7546 | #endif |
| 7547 | { |
| 7548 | if (priv->pshare->iqk_5g_done) |
| 7549 | return; |
| 7550 | priv->pshare->iqk_5g_done = 1; |
| 7551 | } |
| 7552 | |
| 7553 | printk(">> %s \n",__FUNCTION__); |
| 7554 | |
| 7555 | watchdog_kick(); |
| 7556 | |
| 7557 | /* |
| 7558 | * Save MAC default value |
| 7559 | */ |
| 7560 | temp_522 = RTL_R8(0x522); |
| 7561 | temp_550 = RTL_R8(0x550); |
| 7562 | temp_551 = RTL_R8(0x551); |
| 7563 | |
| 7564 | /* |
| 7565 | * Save BB Parameter |
| 7566 | */ |
| 7567 | temp_a04 = RTL_R32(0xa04);//RTL_R32(0x800); |
| 7568 | temp_c04 = RTL_R32(0xc04); |
| 7569 | temp_874 = RTL_R32(0x874); |
| 7570 | temp_c08 = RTL_R32(0xc08); |
| 7571 | temp_870 = RTL_R32(0x870); |
| 7572 | temp_860 = RTL_R32(0x860); |
| 7573 | temp_88c = RTL_R32(0x88c); |
| 7574 | temp_c50 = RTL_R32(0xc50); |
| 7575 | temp_b30 = RTL_R32(0xb30); // 03/03/2011 update |
| 7576 | |
| 7577 | /* |
| 7578 | * Save AFE Parameters |
| 7579 | */ |
| 7580 | for( i = 0 ; i < IQK_ADDA_REG_NUM ; i++) |
| 7581 | ADDA_backup[i] = RTL_R32(ADDA_REG[i]); |
| 7582 | |
| 7583 | /* |
| 7584 | * ============== |
| 7585 | * Path-A TX/RX IQK |
| 7586 | * ============== |
| 7587 | */ |
| 7588 | while (cal_num < 3) { |
| 7589 | /* |
| 7590 | * Path-A AFE all on |
| 7591 | */ |
| 7592 | for( i = 0 ; i < IQK_ADDA_REG_NUM ; i++) { |
| 7593 | #ifdef NON_INTR_ANTDIV |
| 7594 | if (DMDP_PHY_QueryBBReg(0, 0xb30,BIT(27))) |
| 7595 | RTL_W32(ADDA_REG[i], 0x0b1b25a4); |
| 7596 | else |
| 7597 | #endif |
| 7598 | RTL_W32(ADDA_REG[i], 0x04db25a4); |
| 7599 | } |
| 7600 | |
| 7601 | /* |
| 7602 | * MAC register setting |
| 7603 | */ |
| 7604 | RTL_W8(0x522, 0x3f); |
| 7605 | RTL_W8(0x550, RTL_R8(0x550)& (~BIT(3))); |
| 7606 | RTL_W8(0x551, RTL_R8(0x551)& (~BIT(3))); |
| 7607 | |
| 7608 | /* |
| 7609 | * IQK must be done in PI mode |
| 7610 | */ |
| 7611 | if (!phy_query_bb_reg(priv, 0x820, BIT(8)) || !phy_query_bb_reg(priv, 0x828, BIT(8))) { |
| 7612 | phy_set_bb_reg(priv, 0x820, bMaskDWord, 0x01000100); |
| 7613 | phy_set_bb_reg(priv, 0x828, bMaskDWord, 0x01000100); |
| 7614 | switch2PI++; |
| 7615 | } |
| 7616 | |
| 7617 | /* |
| 7618 | * BB setting |
| 7619 | */ |
| 7620 | //phy_set_bb_reg(priv, 0x800, BIT(24), 0); |
| 7621 | phy_set_bb_reg(priv, 0xa04, bMaskDWord, (0x0f000000 | temp_a04) ); |
| 7622 | phy_set_bb_reg(priv, 0xc04, bMaskDWord, 0x03a05600); |
| 7623 | phy_set_bb_reg(priv, 0xc08, bMaskDWord, 0x000800e4); |
| 7624 | phy_set_bb_reg(priv, 0x874, bMaskDWord, 0x22208000); |
| 7625 | phy_set_bb_reg(priv, 0x88c, BIT(23)|BIT(22)|BIT(21)|BIT(20), 0xf); |
| 7626 | phy_set_bb_reg(priv, 0xb30, bMaskDWord, 0x00a00000); // 03/03/2011 update |
| 7627 | |
| 7628 | /* |
| 7629 | * AP or IQK |
| 7630 | */ |
| 7631 | //phy_set_bb_reg(priv, 0xb68, bMaskDWord, 0x0f600000); |
| 7632 | //phy_set_bb_reg(priv, 0xb6c, bMaskDWord, 0x0f600000); |
| 7633 | |
| 7634 | // IQK-R03 2011/02/16 update |
| 7635 | phy_set_bb_reg(priv, 0xb00, bMaskDWord, 0); |
| 7636 | phy_set_bb_reg(priv, 0xb68, bMaskDWord, 0x20000000); |
| 7637 | |
| 7638 | /* |
| 7639 | * IQK global setting |
| 7640 | */ |
| 7641 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0x808000); |
| 7642 | phy_set_bb_reg(priv, 0xe40, bMaskDWord, 0x10007c00); |
| 7643 | phy_set_bb_reg(priv, 0xe44, bMaskDWord, 0x01004800); |
| 7644 | |
| 7645 | /* |
| 7646 | * path-A IQK setting |
| 7647 | */ |
| 7648 | phy_set_bb_reg(priv, 0xe30, bMaskDWord, 0x18008c1f); |
| 7649 | phy_set_bb_reg(priv, 0xe34, bMaskDWord, 0x18008c1f); |
| 7650 | phy_set_bb_reg(priv, 0xe38, bMaskDWord, 0x82140307); // 01/11/2011 update |
| 7651 | |
| 7652 | #ifdef USB_POWER_SUPPORT |
| 7653 | phy_set_bb_reg(priv, 0xe3c, bMaskDWord, 0x68160c66); |
| 7654 | #else |
| 7655 | phy_set_bb_reg(priv, 0xe3c, bMaskDWord, 0x68160960); // 01/11/2011 update |
| 7656 | #endif |
| 7657 | /* |
| 7658 | * LO calibration setting |
| 7659 | */ |
| 7660 | phy_set_bb_reg(priv, 0xe4c, bMaskDWord, 0x00462911); |
| 7661 | |
| 7662 | #ifdef USB_POWER_SUPPORT |
| 7663 | // PHY0 TRSW seting |
| 7664 | phy_set_bb_reg(priv, 0x870, BIT(6)|BIT(5), 3); |
| 7665 | phy_set_bb_reg(priv, 0x860, BIT(6)|BIT(5), 3); |
| 7666 | #else |
| 7667 | /* |
| 7668 | * path-A PA on |
| 7669 | */ |
| 7670 | /* |
| 7671 | phy_set_bb_reg(priv, 0x870, BIT(11)|BIT(10), 3); |
| 7672 | phy_set_bb_reg(priv, 0x870, BIT(6)|BIT(5), 3); |
| 7673 | phy_set_bb_reg(priv, 0x860, BIT(11)|BIT(10), 3); |
| 7674 | */ |
| 7675 | phy_set_bb_reg(priv, 0x870, bMaskDWord, 0x07000f60); // 01/11/2011 update |
| 7676 | phy_set_bb_reg(priv, 0x860, bMaskDWord, 0x66e60e30); // 01/11/2011 update |
| 7677 | #endif |
| 7678 | /* |
| 7679 | * One shot, path A LOK & IQK |
| 7680 | */ |
| 7681 | phy_set_bb_reg(priv, 0xe48, bMaskDWord, 0xf9000000); |
| 7682 | phy_set_bb_reg(priv, 0xe48, bMaskDWord, 0xf8000000); |
| 7683 | |
| 7684 | /* |
| 7685 | * Delay 10 ms |
| 7686 | */ |
| 7687 | delay_ms(10); |
| 7688 | |
| 7689 | delay_count = 0; |
| 7690 | while (1){ |
| 7691 | REG0xeac = phy_query_bb_reg(priv, 0xeac, bMaskDWord); |
| 7692 | if ((REG0xeac&BIT(26))||(delay_count>20)){ |
| 7693 | break; |
| 7694 | }else { |
| 7695 | delay_ms(1); |
| 7696 | delay_count++; |
| 7697 | } |
| 7698 | } |
| 7699 | |
| 7700 | /* |
| 7701 | * Check_TX_IQK_A_result |
| 7702 | */ |
| 7703 | REG0xe40 = phy_query_bb_reg(priv, 0xe40, bMaskDWord); |
| 7704 | REG0xeac = phy_query_bb_reg(priv, 0xeac, bMaskDWord); |
| 7705 | REG0xe94 = phy_query_bb_reg(priv, 0xe94, bMaskDWord); |
| 7706 | if(((REG0xeac&BIT(28)) == 0) && (((REG0xe94&0x3FF0000)>>16)!=0x142)) { |
| 7707 | TX0IQKOK = TRUE; |
| 7708 | REG0xe9c = phy_query_bb_reg(priv, 0xe9c, bMaskDWord); |
| 7709 | TX_X0 = (phy_query_bb_reg(priv, 0xe94, bMaskDWord)&0x3FF0000)>>16; |
| 7710 | TX_Y0 = (phy_query_bb_reg(priv, 0xe9c, bMaskDWord)&0x3FF0000)>>16; |
| 7711 | RX0REG0xe40[cal_num] = (REG0xe40 & 0xfc00fc00) | (TX_X0<<16) | TX_Y0; |
| 7712 | DEBUG_INFO("TX_X0 %08x TX_Y0 %08x RX0REG0xe40 %08x\n", TX_X0, TX_Y0, RX0REG0xe40[cal_num]); |
| 7713 | result[0][cal_num] = TX_X0; |
| 7714 | result[1][cal_num] = TX_Y0; |
| 7715 | } else { |
| 7716 | TX0IQKOK = FALSE; |
| 7717 | if (++cal_retry >= 10) { |
| 7718 | printk("%s Path-A Tx/Rx Check\n",__FUNCTION__); |
| 7719 | break; |
| 7720 | } |
| 7721 | } |
| 7722 | |
| 7723 | /* |
| 7724 | * Check_RX_IQK_A_result |
| 7725 | */ |
| 7726 | if(TX0IQKOK == TRUE) { |
| 7727 | REG0xeac = phy_query_bb_reg(priv, 0xeac, bMaskDWord); |
| 7728 | REG0xea4 = phy_query_bb_reg(priv, 0xea4, bMaskDWord); |
| 7729 | if(((REG0xeac&BIT(27)) == 0) && (((REG0xea4&0x3FF0000)>>16)!=0x132)) { |
| 7730 | RX_X0 = (phy_query_bb_reg(priv, 0xea4, bMaskDWord)&0x3FF0000)>>16; |
| 7731 | RX_Y0 = (phy_query_bb_reg(priv, 0xeac, bMaskDWord)&0x3FF0000)>>16; |
| 7732 | DEBUG_INFO("RX_X0 %08x RX_Y0 %08x\n", RX_X0, RX_Y0); |
| 7733 | result[2][cal_num] = RX_X0; |
| 7734 | result[3][cal_num] = RX_Y0; |
| 7735 | cal_num++; |
| 7736 | } else { |
| 7737 | phy_set_bb_reg(priv, 0xc14, bMaskDWord, 0x40000100); |
| 7738 | phy_set_bb_reg(priv, 0xe34, bMaskDWord, 0x19008c00); |
| 7739 | if (++cal_retry >= 10) { |
| 7740 | printk("%s Path-A Tx/Rx Check\n",__FUNCTION__); |
| 7741 | break; |
| 7742 | } |
| 7743 | } |
| 7744 | } |
| 7745 | } |
| 7746 | |
| 7747 | if (cal_num == 3) { |
| 7748 | result_final[0] = get_mean_of_2_close_value(result[0]); |
| 7749 | result_final[1] = get_mean_of_2_close_value(result[1]); |
| 7750 | result_final[2] = get_mean_of_2_close_value(result[2]); |
| 7751 | result_final[3] = get_mean_of_2_close_value(result[3]); |
| 7752 | RX0REG0xe40_final = 0x80000000 | get_mean_of_2_close_value(RX0REG0xe40); |
| 7753 | |
| 7754 | priv->pshare->RegE94=result_final[0]; |
| 7755 | priv->pshare->RegE9C=result_final[1]; |
| 7756 | } else { |
| 7757 | priv->pshare->RegE94=0x100; |
| 7758 | priv->pshare->RegE9C=0x00; |
| 7759 | } |
| 7760 | |
| 7761 | /* |
| 7762 | * Fill IQK result for Path A |
| 7763 | */ |
| 7764 | if (result_final[0]) { |
| 7765 | /* |
| 7766 | oldval_0 = (phy_query_bb_reg(priv, 0xc80, bMaskDWord) >> 22) & 0x3FF; |
| 7767 | X = result_final[0]; |
| 7768 | if ((X & 0x00000200) != 0) |
| 7769 | X = X | 0xFFFFFC00; |
| 7770 | TX0_A = (X * oldval_0) >> 8; |
| 7771 | phy_set_bb_reg(priv, 0xc80, 0x3FF, TX0_A); |
| 7772 | phy_set_bb_reg(priv, 0xc4c, BIT(24), ((X* oldval_0>>7) & 0x1)); |
| 7773 | |
| 7774 | Y = result_final[1]; |
| 7775 | if ((Y & 0x00000200) != 0) |
| 7776 | Y = Y | 0xFFFFFC00; |
| 7777 | TX0_C = (Y * oldval_0) >> 8; |
| 7778 | phy_set_bb_reg(priv, 0xc94, 0xF0000000, ((TX0_C&0x3C0)>>6)); |
| 7779 | phy_set_bb_reg(priv, 0xc80, 0x003F0000, (TX0_C&0x3F)); |
| 7780 | phy_set_bb_reg(priv, 0xc4c, BIT(26), ((Y* oldval_0>>7) & 0x1)); |
| 7781 | */ |
| 7782 | |
| 7783 | // IQK-R03 2011/02/16 update |
| 7784 | X = result_final[0]; |
| 7785 | Y = result_final[1]; |
| 7786 | //printk("X=%x Y=%x\n",X,Y); |
| 7787 | //Path-A OFDM_A |
| 7788 | phy_set_bb_reg(priv, 0xe30, 0x03FF0000, X); |
| 7789 | phy_set_bb_reg(priv, 0xc4c, BIT(24), 0); |
| 7790 | //Path-A OFDM_C |
| 7791 | phy_set_bb_reg(priv, 0xe30, 0x000003FF, Y); |
| 7792 | phy_set_bb_reg(priv, 0xc4c, BIT(26), 0); |
| 7793 | |
| 7794 | |
| 7795 | if(result_final[2]) { |
| 7796 | reg = result_final[2]; |
| 7797 | phy_set_bb_reg(priv, 0xc14, 0x3FF, reg); |
| 7798 | |
| 7799 | reg = result_final[3] & 0x3F; |
| 7800 | phy_set_bb_reg(priv, 0xc14, 0xFC00, reg); |
| 7801 | |
| 7802 | reg = (result_final[3] >> 6) & 0xF; |
| 7803 | phy_set_bb_reg(priv, 0xca0, 0xF0000000, reg); |
| 7804 | |
| 7805 | phy_set_bb_reg(priv, 0xe34, 0x03FF0000, result_final[2]); // X |
| 7806 | phy_set_bb_reg(priv, 0xe34, 0x3FF, result_final[3]); //Y |
| 7807 | } |
| 7808 | } |
| 7809 | |
| 7810 | /* |
| 7811 | * Path-A PA off |
| 7812 | */ |
| 7813 | phy_set_bb_reg(priv, 0x870, bMaskDWord, temp_870); |
| 7814 | phy_set_bb_reg(priv, 0x860, bMaskDWord, temp_860); |
| 7815 | |
| 7816 | /* |
| 7817 | * Exit IQK mode |
| 7818 | */ |
| 7819 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0); |
| 7820 | phy_set_bb_reg(priv, 0xc04, bMaskDWord, temp_c04); |
| 7821 | phy_set_bb_reg(priv, 0xc08, bMaskDWord, temp_c08); |
| 7822 | phy_set_bb_reg(priv, 0x874, bMaskDWord, temp_874); |
| 7823 | //phy_set_bb_reg(priv, 0x800, bMaskDWord, temp_800); |
| 7824 | phy_set_bb_reg(priv, 0xa04, bMaskDWord, temp_a04); |
| 7825 | phy_set_bb_reg(priv, 0x88c, bMaskDWord, temp_88c); |
| 7826 | phy_set_bb_reg(priv, 0xb30, bMaskDWord, temp_b30); // 03/03/2011 update |
| 7827 | //phy_set_bb_reg(priv, 0x840, bMaskDWord, 0x00032fff); // 01/11/2011 update |
| 7828 | |
| 7829 | //PHY0 IQ path to DP block |
| 7830 | phy_set_bb_reg(priv, 0xb00, bMaskDWord, 0x010170b8); |
| 7831 | |
| 7832 | phy_set_bb_reg(priv, 0xc50, bMaskDWord, 0x50); |
| 7833 | phy_set_bb_reg(priv, 0xc50, bMaskDWord, temp_c50); |
| 7834 | |
| 7835 | /* |
| 7836 | * Reload MAC default value |
| 7837 | */ |
| 7838 | RTL_W8(0x550, temp_550); |
| 7839 | RTL_W8(0x551, temp_551); |
| 7840 | RTL_W8(0x522, temp_522); |
| 7841 | |
| 7842 | /* |
| 7843 | * Switch back to SI if needed, after IQK |
| 7844 | */ |
| 7845 | if (switch2PI) { |
| 7846 | phy_set_bb_reg(priv, 0x820, bMaskDWord, 0x01000000); |
| 7847 | phy_set_bb_reg(priv, 0x828, bMaskDWord, 0x01000000); |
| 7848 | } |
| 7849 | |
| 7850 | /* |
| 7851 | * Reload ADDA power saving parameters |
| 7852 | */ |
| 7853 | for(i = 0 ; i < IQK_ADDA_REG_NUM ; i++) |
| 7854 | phy_set_bb_reg(priv, ADDA_REG[i], bMaskDWord, ADDA_backup[i]); |
| 7855 | |
| 7856 | if (!TX0IQKOK) |
| 7857 | priv->pshare->IQK_fail_cnt++; |
| 7858 | } |
| 7859 | #endif |
| 7860 | |
| 7861 | #ifdef SW_LCK_92D |
| 7862 | |
| 7863 | #define TARGET_CHNL_NUM_5G 221 |
| 7864 | #define TARGET_CHNL_NUM_2G 14 |
| 7865 | #define CV_CURVE_CNT 64 |
| 7866 | |
| 7867 | unsigned int CurveIndex_5G[TARGET_CHNL_NUM_5G]={0}; |
| 7868 | unsigned int CurveIndex_2G[TARGET_CHNL_NUM_2G]={0}; |
| 7869 | |
| 7870 | static unsigned int TargetChnl_5G[TARGET_CHNL_NUM_5G] = { |
| 7871 | 25141, 25116, 25091, 25066, 25041, |
| 7872 | 25016, 24991, 24966, 24941, 24917, |
| 7873 | 24892, 24867, 24843, 24818, 24794, |
| 7874 | 24770, 24765, 24721, 24697, 24672, |
| 7875 | 24648, 24624, 24600, 24576, 24552, |
| 7876 | 24528, 24504, 24480, 24457, 24433, |
| 7877 | 24409, 24385, 24362, 24338, 24315, |
| 7878 | 24291, 24268, 24245, 24221, 24198, |
| 7879 | 24175, 24151, 24128, 24105, 24082, |
| 7880 | 24059, 24036, 24013, 23990, 23967, |
| 7881 | 23945, 23922, 23899, 23876, 23854, |
| 7882 | 23831, 23809, 23786, 23764, 23741, |
| 7883 | 23719, 23697, 23674, 23652, 23630, |
| 7884 | 23608, 23586, 23564, 23541, 23519, |
| 7885 | 23498, 23476, 23454, 23432, 23410, |
| 7886 | 23388, 23367, 23345, 23323, 23302, |
| 7887 | 23280, 23259, 23237, 23216, 23194, |
| 7888 | 23173, 23152, 23130, 23109, 23088, |
| 7889 | 23067, 23046, 23025, 23003, 22982, |
| 7890 | 22962, 22941, 22920, 22899, 22878, |
| 7891 | 22857, 22837, 22816, 22795, 22775, |
| 7892 | 22754, 22733, 22713, 22692, 22672, |
| 7893 | 22652, 22631, 22611, 22591, 22570, |
| 7894 | 22550, 22530, 22510, 22490, 22469, |
| 7895 | 22449, 22429, 22409, 22390, 22370, |
| 7896 | 22350, 22336, 22310, 22290, 22271, |
| 7897 | 22251, 22231, 22212, 22192, 22173, |
| 7898 | 22153, 22134, 22114, 22095, 22075, |
| 7899 | 22056, 22037, 22017, 21998, 21979, |
| 7900 | 21960, 21941, 21921, 21902, 21883, |
| 7901 | 21864, 21845, 21826, 21807, 21789, |
| 7902 | 21770, 21751, 21732, 21713, 21695, |
| 7903 | 21676, 21657, 21639, 21620, 21602, |
| 7904 | 21583, 21565, 21546, 21528, 21509, |
| 7905 | 21491, 21473, 21454, 21436, 21418, |
| 7906 | 21400, 21381, 21363, 21345, 21327, |
| 7907 | 21309, 21291, 21273, 21255, 21237, |
| 7908 | 21219, 21201, 21183, 21166, 21148, |
| 7909 | 21130, 21112, 21095, 21077, 21059, |
| 7910 | 21042, 21024, 21007, 20989, 20972, |
| 7911 | 25679, 25653, 25627, 25601, 25575, |
| 7912 | 25549, 25523, 25497, 25471, 25446, |
| 7913 | 25420, 25394, 25369, 25343, 25318, |
| 7914 | 25292, 25267, 25242, 25216, 25191, |
| 7915 | 25166 }; |
| 7916 | |
| 7917 | static unsigned int TargetChnl_2G[TARGET_CHNL_NUM_2G] = { // channel 1~14 |
| 7918 | 26084, 26030, 25976, 25923, 25869, 25816, 25764, |
| 7919 | 25711, 25658, 25606, 25554, 25502, 25451, 25328 |
| 7920 | }; |
| 7921 | |
| 7922 | void _PHY_CalcCurvIndex(struct rtl8192cd_priv *priv, unsigned int *TargetChnl, |
| 7923 | unsigned int *CurveCountVal, char is5G, unsigned int *CurveIndex) |
| 7924 | { |
| 7925 | unsigned int smallestABSVal = 0xffffffff, u4tmp; |
| 7926 | unsigned char i, j; |
| 7927 | unsigned char chnl_num = is5G?(TARGET_CHNL_NUM_5G) : (TARGET_CHNL_NUM_2G); |
| 7928 | |
| 7929 | |
| 7930 | for(i=0; i<chnl_num; i++) |
| 7931 | { |
| 7932 | //if(is5G && !IsLegal5GChannel(pAdapter, i+1)) |
| 7933 | //continue; |
| 7934 | |
| 7935 | CurveIndex[i] = 0; |
| 7936 | for(j=0; j<(CV_CURVE_CNT*2); j++) |
| 7937 | { |
| 7938 | u4tmp = RTL_ABS(TargetChnl[i], CurveCountVal[j]); |
| 7939 | //if (i==115) |
| 7940 | //printk("cv[%d]=%x\n", j, u4tmp); |
| 7941 | if(u4tmp < smallestABSVal) |
| 7942 | { |
| 7943 | CurveIndex[i] = j; |
| 7944 | smallestABSVal = u4tmp; |
| 7945 | } |
| 7946 | } |
| 7947 | |
| 7948 | smallestABSVal = 0xffffffff; |
| 7949 | } |
| 7950 | } |
| 7951 | |
| 7952 | void phy_ReloadLCKSetting(struct rtl8192cd_priv *priv) |
| 7953 | { |
| 7954 | unsigned int eRFPath = priv->pmib->dot11RFEntry.phyBandSelect == PHY_BAND_5G? RF_PATH_A:(priv->pmib->dot11RFEntry.macPhyMode==SINGLEMAC_SINGLEPHY?RF_PATH_B:RF_PATH_A); |
| 7955 | unsigned int u4tmp = 0; |
| 7956 | // unsigned char bNeedPowerDownRadio = FALSE; |
| 7957 | unsigned int channel = priv->pshare->RegRF18[eRFPath]&0xff; |
| 7958 | //unsigned int channel = phy_query_rf_reg(priv, eRFPath, rRfChannel, 0xff, 1); |
| 7959 | |
| 7960 | DEBUG_INFO("====>phy_ReloadLCKSetting interface %d path %d ch %d [0x%05x]\n", priv->pshare->wlandev_idx, eRFPath, channel, priv->pshare->RegRF28[eRFPath]); |
| 7961 | |
| 7962 | //only for 92D C-cut SMSP |
| 7963 | if(GET_CHIP_VER(priv)!=VERSION_8192D |
| 7964 | #ifdef CONFIG_RTL_92C_SUPPORT |
| 7965 | || IS_TEST_CHIP(priv) |
| 7966 | #endif |
| 7967 | ) |
| 7968 | return; |
| 7969 | |
| 7970 | if(priv->pmib->dot11RFEntry.phyBandSelect == PHY_BAND_5G) |
| 7971 | { |
| 7972 | //Path-A for 5G |
| 7973 | u4tmp = CurveIndex_5G[channel-1]; |
| 7974 | //printk("%s ver 1 set RF-A, 5G, 0x28 = 0x%x !!\n",__FUNCTION__, u4tmp); |
| 7975 | #ifdef CONFIG_RTL_92D_DMDP |
| 7976 | if(priv->pmib->dot11RFEntry.macPhyMode == DUALMAC_DUALPHY && priv->pshare->wlandev_idx == 1) |
| 7977 | { |
| 7978 | priv->pshare->RegRF28[RF_PATH_A] = RTL_SET_MASK(priv->pshare->RegRF28[RF_PATH_A],0x3f800,u4tmp,11); //DMDP_PHY_SetRFReg(0, RF_PATH_A, 0x28, 0x3f800, u4tmp); |
| 7979 | DMDP_PHY_SetRFReg(0, RF_PATH_A, 0x28, bMask20Bits, priv->pshare->RegRF28[RF_PATH_A]); |
| 7980 | }else |
| 7981 | #endif |
| 7982 | { |
| 7983 | priv->pshare->RegRF28[eRFPath] = RTL_SET_MASK(priv->pshare->RegRF28[eRFPath],0x3f800,u4tmp,11); //phy_set_rf_reg(priv, eRFPath, 0x28, 0x3f800, u4tmp); |
| 7984 | phy_set_rf_reg(priv, eRFPath, 0x28, bMask20Bits, priv->pshare->RegRF28[eRFPath]); |
| 7985 | } |
| 7986 | DEBUG_INFO("%s ver 3 set RF-B, 2G, 0x28 = 0x%05x [0x%05x]!!\n", __FUNCTION__, phy_query_rf_reg(priv, eRFPath, 0x28, bMask20Bits, 1), priv->pshare->RegRF28[eRFPath]); |
| 7987 | } |
| 7988 | else if(priv->pmib->dot11RFEntry.phyBandSelect == PHY_BAND_2G) |
| 7989 | { |
| 7990 | u4tmp = CurveIndex_2G[channel-1]; |
| 7991 | //printk("%s ver 3 set RF-B, 2G, 0x28 = 0x%x !!\n", __FUNCTION__, u4tmp); |
| 7992 | #ifdef CONFIG_RTL_92D_DMDP |
| 7993 | if(priv->pmib->dot11RFEntry.macPhyMode == DUALMAC_DUALPHY && priv->pshare->wlandev_idx == 0) |
| 7994 | { |
| 7995 | priv->pshare->RegRF28[RF_PATH_A] = RTL_SET_MASK(priv->pshare->RegRF28[RF_PATH_A],0x3f800,u4tmp,11); //DMDP_PHY_SetRFReg(1, RF_PATH_A, 0x28, 0x3f800, u4tmp); |
| 7996 | DMDP_PHY_SetRFReg(1, RF_PATH_A, 0x28, bMask20Bits, priv->pshare->RegRF28[RF_PATH_A]); |
| 7997 | }else |
| 7998 | #endif |
| 7999 | { |
| 8000 | priv->pshare->RegRF28[eRFPath] = RTL_SET_MASK(priv->pshare->RegRF28[eRFPath],0x3f800,u4tmp,11); // phy_set_rf_reg(priv, eRFPath, 0x28, 0x3f800, u4tmp); |
| 8001 | phy_set_rf_reg(priv, eRFPath, 0x28, bMask20Bits, priv->pshare->RegRF28[eRFPath]); |
| 8002 | } |
| 8003 | DEBUG_INFO("%s ver 3 set RF-B, 2G, 0x28 = 0x%05x [0x%05x]!!\n", __FUNCTION__, phy_query_rf_reg(priv, eRFPath, 0x28, bMask20Bits, 1), priv->pshare->RegRF28[eRFPath]); |
| 8004 | } |
| 8005 | |
| 8006 | } |
| 8007 | |
| 8008 | /* Software LCK */ |
| 8009 | void PHY_LCCalibrate_92D(struct rtl8192cd_priv *priv) |
| 8010 | { |
| 8011 | unsigned char tmpReg; |
| 8012 | unsigned int RF_mode[2]; |
| 8013 | unsigned int eRFPath, curMaxRFPath; |
| 8014 | unsigned int i; |
| 8015 | unsigned int curveCountVal[CV_CURVE_CNT*2]={0}; |
| 8016 | unsigned short timeout = 800, timecount = 0; |
| 8017 | |
| 8018 | if (priv->pmib->dot11RFEntry.macPhyMode == DUALMAC_DUALPHY) |
| 8019 | curMaxRFPath = RF_PATH_B; |
| 8020 | else |
| 8021 | curMaxRFPath = RF_PATH_MAX; |
| 8022 | |
| 8023 | //Check continuous TX and Packet TX |
| 8024 | tmpReg = RTL_R8(0xd03); |
| 8025 | |
| 8026 | if ((tmpReg & 0x70) != 0) // Deal with contisuous TX case |
| 8027 | RTL_W8(0xd03, tmpReg&0x8F); // disable all continuous TX |
| 8028 | else // Deal with Packet TX case |
| 8029 | RTL_W8(TXPAUSE, 0xFF); // block all queues |
| 8030 | |
| 8031 | phy_set_bb_reg(priv, REG_FPGA0_ANALOG_PARAMETER4, 0xF00000, 0x0F); |
| 8032 | |
| 8033 | for(eRFPath = RF_PATH_A; eRFPath < curMaxRFPath; eRFPath++) { |
| 8034 | // 1. Read original RF mode |
| 8035 | RF_mode[eRFPath] = phy_query_rf_reg(priv, eRFPath, 0x00, bMask20Bits, 1); |
| 8036 | |
| 8037 | // 2. Set RF mode = standby mode |
| 8038 | phy_set_rf_reg(priv, eRFPath, 0x00, 0x70000, 0x01); |
| 8039 | |
| 8040 | // switch CV-curve control by LC-calibration |
| 8041 | phy_set_rf_reg(priv, eRFPath, 0x2B, BIT(17), 0x0); |
| 8042 | |
| 8043 | // jenyu suggest |
| 8044 | phy_set_rf_reg(priv, eRFPath, 0x28, BIT(8), 0x1); |
| 8045 | |
| 8046 | //4. Set LC calibration begin |
| 8047 | phy_set_rf_reg(priv, eRFPath, 0x18, BIT(15), 0x01); |
| 8048 | |
| 8049 | while(!(phy_query_rf_reg(priv, eRFPath, 0x2A, BIT(11), 1) && |
| 8050 | timecount <= timeout)){ |
| 8051 | //DEBUG_INFO("PHY_LCK delay for %d ms=2\n", timecount); |
| 8052 | delay_ms(50); |
| 8053 | timecount+=50; |
| 8054 | } |
| 8055 | |
| 8056 | //u4tmp = phy_query_rf_reg(priv, eRFPath, 0x28, bMask20Bits, 1); |
| 8057 | |
| 8058 | memset((void *)curveCountVal, 0, CV_CURVE_CNT*2); |
| 8059 | |
| 8060 | //Set LC calibration off |
| 8061 | phy_set_rf_reg(priv, eRFPath, 0x18, BIT(15), 0x00); |
| 8062 | |
| 8063 | // jenyu suggest |
| 8064 | phy_set_rf_reg(priv, eRFPath, 0x28, BIT(8), 0x0); |
| 8065 | |
| 8066 | //save Curve-counting number |
| 8067 | for(i=0; i<CV_CURVE_CNT; i++) |
| 8068 | { |
| 8069 | unsigned int readVal=0, readVal2=0; |
| 8070 | |
| 8071 | phy_set_rf_reg(priv, eRFPath, 0x3F, 0x7f, i); |
| 8072 | |
| 8073 | phy_set_rf_reg(priv, eRFPath, 0x4D, bMask20Bits, 0); |
| 8074 | |
| 8075 | readVal = phy_query_rf_reg(priv, eRFPath, 0x4F, bMask20Bits, 1); |
| 8076 | |
| 8077 | curveCountVal[2*i+1] = (readVal & 0xfffe0) >> 5; |
| 8078 | |
| 8079 | readVal2 = phy_query_rf_reg(priv, eRFPath, 0x50, 0xffc00, 1); |
| 8080 | |
| 8081 | curveCountVal[2*i] = (((readVal & 0x1F) << 10) | readVal2); |
| 8082 | } |
| 8083 | |
| 8084 | if(eRFPath == RF_PATH_A |
| 8085 | #ifdef CONFIG_RTL_92D_DMDP |
| 8086 | && priv->pshare->wlandev_idx == 0 |
| 8087 | #endif |
| 8088 | ) |
| 8089 | _PHY_CalcCurvIndex(priv, TargetChnl_5G, curveCountVal, TRUE, CurveIndex_5G); |
| 8090 | else |
| 8091 | _PHY_CalcCurvIndex(priv, TargetChnl_2G, curveCountVal, FALSE, CurveIndex_2G); |
| 8092 | |
| 8093 | // switch CV-curve control mode |
| 8094 | phy_set_rf_reg(priv, eRFPath, 0x2B, BIT(17), 0x1); |
| 8095 | |
| 8096 | // store 0x28 for Reload_LCK |
| 8097 | priv->pshare->RegRF28[eRFPath] = phy_query_rf_reg(priv, eRFPath, 0x28, bMask20Bits, 1); |
| 8098 | } |
| 8099 | |
| 8100 | //Restore original situation |
| 8101 | for(eRFPath = RF_PATH_A; eRFPath < curMaxRFPath; eRFPath++) |
| 8102 | { |
| 8103 | phy_set_rf_reg(priv, eRFPath, 0x00, bMask20Bits, RF_mode[eRFPath]); |
| 8104 | } |
| 8105 | |
| 8106 | if((tmpReg&0x70) != 0) |
| 8107 | { |
| 8108 | //Path-A |
| 8109 | RTL_W8(0xd03, tmpReg); |
| 8110 | } |
| 8111 | else // Deal with Packet TX case |
| 8112 | { |
| 8113 | RTL_W8(TXPAUSE, 0x00); |
| 8114 | } |
| 8115 | |
| 8116 | phy_set_bb_reg(priv, REG_FPGA0_ANALOG_PARAMETER4, 0xF00000, 0x00); |
| 8117 | |
| 8118 | phy_ReloadLCKSetting(priv); |
| 8119 | |
| 8120 | } |
| 8121 | |
| 8122 | #else |
| 8123 | /* Hardware LCK */ |
| 8124 | static void PHY_LCCalibrate_92D(struct rtl8192cd_priv *priv) |
| 8125 | { |
| 8126 | unsigned char tmpReg; |
| 8127 | unsigned int RF_mode[2], tmpu4Byte[2]; |
| 8128 | |
| 8129 | unsigned int eRFPath, curMaxRFPath; |
| 8130 | unsigned char timeout = 800, timecount = 0; |
| 8131 | |
| 8132 | if (priv->pmib->dot11RFEntry.macPhyMode == DUALMAC_DUALPHY) |
| 8133 | curMaxRFPath = RF_PATH_B; |
| 8134 | else |
| 8135 | curMaxRFPath = RF_PATH_MAX; |
| 8136 | |
| 8137 | |
| 8138 | // Check continuous TX and Packet TX |
| 8139 | tmpReg = RTL_R8(0xd03); |
| 8140 | |
| 8141 | if ((tmpReg & 0x70) != 0) // Deal with contisuous TX case |
| 8142 | RTL_W8(0xd03, tmpReg&0x8F); // disable all continuous TX |
| 8143 | else // Deal with Packet TX case |
| 8144 | RTL_W8(TXPAUSE, 0xFF); // block all queues |
| 8145 | |
| 8146 | phy_set_bb_reg(priv, REG_FPGA0_ANALOG_PARAMETER4, 0xF00000, 0x0F); |
| 8147 | |
| 8148 | for(eRFPath = RF_PATH_A; eRFPath < curMaxRFPath; eRFPath++) { |
| 8149 | // 1. Read original RF mode |
| 8150 | RF_mode[eRFPath] = phy_query_rf_reg(priv, eRFPath, 0x00, bMask20Bits, 1); |
| 8151 | |
| 8152 | // 2. Set RF mode = standby mode |
| 8153 | phy_set_rf_reg(priv, eRFPath, 0x00, 0x70000, 0x01); |
| 8154 | |
| 8155 | tmpu4Byte[eRFPath] = phy_query_rf_reg(priv, eRFPath, 0x28, bMask20Bits, 1); |
| 8156 | phy_set_rf_reg(priv, eRFPath, 0x28, 0x700, 0x07); |
| 8157 | |
| 8158 | //4. Set LC calibration begin |
| 8159 | phy_set_rf_reg(priv, eRFPath, 0x18, 0x08000, 0x01); |
| 8160 | } |
| 8161 | |
| 8162 | watchdog_kick(); |
| 8163 | |
| 8164 | for(eRFPath = RF_PATH_A; eRFPath < curMaxRFPath; eRFPath++) { |
| 8165 | while(!(phy_query_rf_reg(priv, eRFPath, 0x2A, BIT(11), 1) && |
| 8166 | timecount <= timeout)){ |
| 8167 | DEBUG_INFO("PHY_LCK delay for %d ms=2\n", timecount); |
| 8168 | delay_ms(50); |
| 8169 | timecount+=50; |
| 8170 | } |
| 8171 | } |
| 8172 | |
| 8173 | for(eRFPath = RF_PATH_A; eRFPath < curMaxRFPath; eRFPath++) { |
| 8174 | phy_set_rf_reg(priv, eRFPath, 0x28, bMask20Bits, tmpu4Byte[eRFPath]); |
| 8175 | priv->pshare->RegRF28[eRFPath] = tmpu4Byte[eRFPath]; |
| 8176 | phy_set_rf_reg(priv, eRFPath, 0x00, bMask20Bits, RF_mode[eRFPath]); |
| 8177 | } |
| 8178 | |
| 8179 | // Restore original situation |
| 8180 | if ((tmpReg & 0x70) != 0) // Deal with contisuous TX case |
| 8181 | RTL_W8(0xd03, tmpReg); |
| 8182 | else // Deal with Packet TX case |
| 8183 | RTL_W8(TXPAUSE, 0x00); |
| 8184 | |
| 8185 | phy_set_bb_reg(priv, REG_FPGA0_ANALOG_PARAMETER4, 0xF00000, 0x0); |
| 8186 | |
| 8187 | } |
| 8188 | |
| 8189 | |
| 8190 | #endif //LCK_SW |
| 8191 | |
| 8192 | #ifdef DPK_92D |
| 8193 | |
| 8194 | #if 1 //copy from driver of station team |
| 8195 | #define RF_AC 0x00 |
| 8196 | |
| 8197 | #define REG_PDP_ANT_A 0xb00 |
| 8198 | #define rBndA 0xb30 |
| 8199 | #define REG_PDP_ANT_B 0xb70 |
| 8200 | #define rBndB 0xba0 |
| 8201 | |
| 8202 | #define RF_MODE1 0x10 |
| 8203 | #define RF_MODE2 0x11 |
| 8204 | |
| 8205 | #define rTxAGC_A_CCK11_2_B_CCK11 0x86c |
| 8206 | |
| 8207 | #define RF_TX_G3 0x22 |
| 8208 | |
| 8209 | #define RF_TXPA_G1 0x31 // RF TX PA control |
| 8210 | #define RF_TXPA_G2 0x32 // RF TX PA control |
| 8211 | #define RF_TXPA_G3 0x33 // RF TX PA control |
| 8212 | #define RF_LOBF_9 0x38 |
| 8213 | #define RF_RXRF_A3 0x3C |
| 8214 | #define RF_TRSW 0x3F |
| 8215 | |
| 8216 | #define RF_TXPA_G1 0x31 // RF TX PA control |
| 8217 | #define RF_TXPA_G2 0x32 // RF TX PA control |
| 8218 | #define RF_TXPA_G3 0x33 // RF TX PA control |
| 8219 | #define RF_LOBF_9 0x38 |
| 8220 | #define RF_RXRF_A3 0x3C |
| 8221 | #define RF_TRSW 0x3F |
| 8222 | |
| 8223 | #define RF_TXRF_A2 0x41 |
| 8224 | #define RF_TXPA_G4 0x46 |
| 8225 | #define RF_TXPA_A4 0x4B |
| 8226 | |
| 8227 | #define RF_IQADJ_G1 0x01 |
| 8228 | #define RF_IQADJ_G2 0x02 |
| 8229 | #define RF_BS_PA_APSET_G1_G4 0x03 |
| 8230 | #define RF_BS_PA_APSET_G5_G8 0x04 |
| 8231 | #define RF_POW_TRSW 0x05 |
| 8232 | |
| 8233 | #define DP_OFFSET_NUM 9 |
| 8234 | #define DP_AP_CUREVE_SELECT_NUM 3 |
| 8235 | #define DP_gain_loss 1 |
| 8236 | #define DP_PA_BIAS_NUM 4 |
| 8237 | |
| 8238 | #define rTxAGC_B_CCK5_1_Mcs32 0x838 |
| 8239 | |
| 8240 | #define RF_TXBIAS 0x16 |
| 8241 | #endif |
| 8242 | |
| 8243 | #define DPK_DEBUG(fmt,args...) |
| 8244 | |
| 8245 | #define DP_BB_REG_NUM 7 |
| 8246 | //#define DP_BB_REG_NUM_A 11 |
| 8247 | //#define DP_BB_REG_NUM_B 10 |
| 8248 | #define DP_BB_REG_NUM_A 10 |
| 8249 | #define DP_BB_REG_NUM_B 9 |
| 8250 | |
| 8251 | #define DP_BB_REG_NUM_settings 6 |
| 8252 | #define DP_BB_REG_NUM_loop 30 |
| 8253 | #define DP_BB_REG_NUM_loop_tx 12 |
| 8254 | #define DP_BB_REG_NUM_loop_rx 8 |
| 8255 | #define DP_BB_REG_NUM_loop_pa 4 |
| 8256 | #define DP_RF_REG_NUM 4 |
| 8257 | #define DP_SRAM_NUM 16 |
| 8258 | //#define DP_SRAM_NUM_db 22 |
| 8259 | #define DP_SRAM_NUM_db 86 |
| 8260 | |
| 8261 | #define DP_PATH_NUM 2 |
| 8262 | #define DP_PA_MODEL_NUM 32 |
| 8263 | #define DP_PA_MODEL_RUN_NUM 8 |
| 8264 | #define DP_PA_MODEL_PER_RUN_NUM 4 |
| 8265 | #define DP_RETRY_LIMIT 10 |
| 8266 | #define DP_DPK_NUM 3 |
| 8267 | #define DP_DPK_VALUE_NUM 2 |
| 8268 | #if 1 |
| 8269 | #define DP_GAIN_LOSS_BOUND_NUM 14 |
| 8270 | #else |
| 8271 | #define DP_GAIN_LOSS_BOUND_NUM 8 |
| 8272 | #endif |
| 8273 | #define DP_OFFSET_NUM 9 |
| 8274 | //#define DP_AP_CUREVE_SELECT_NUM 2 // 3 |
| 8275 | #define DP_gain_loss 1 |
| 8276 | |
| 8277 | |
| 8278 | static __always_inline void rtl8192cd_DPK_timer(unsigned long task_priv) |
| 8279 | { |
| 8280 | struct rtl8192cd_priv *priv = (struct rtl8192cd_priv *)task_priv; |
| 8281 | |
| 8282 | if (!(priv->drv_state & DRV_STATE_OPEN)) |
| 8283 | return; |
| 8284 | |
| 8285 | if (priv->pshare->pwr_trk_ongoing){ |
| 8286 | DPK_DEBUG("==>_PHY_DigitalPredistortion() TxPowerTrackingInProgress() delay 100ms\n"); |
| 8287 | rtk_mod_timer(&priv->pshare->DPKTimer, jiffies + RTL_MILISECONDS_TO_JIFFIES(100)); |
| 8288 | }else{ |
| 8289 | PHY_DPCalibrate(priv); |
| 8290 | } |
| 8291 | } |
| 8292 | DEFINE_TIMER_CALLBACK(rtl8192cd_DPK_timer); |
| 8293 | |
| 8294 | void init_DPKTimer(struct rtl8192cd_priv *priv) |
| 8295 | { |
| 8296 | rtk_timer_setup(&(priv->pshare->DPKTimer), rtl8192cd_DPK_timer, (unsigned long)priv, 0); |
| 8297 | } |
| 8298 | |
| 8299 | void _PHY_DPK_polling(struct rtl8192cd_priv *priv) |
| 8300 | { |
| 8301 | unsigned int delaycount = 0, delaybound = 30, delay = 800; |
| 8302 | unsigned int u4tmp; |
| 8303 | |
| 8304 | delaycount = 0; |
| 8305 | |
| 8306 | do{ |
| 8307 | delay_us(delay); |
| 8308 | |
| 8309 | u4tmp = phy_query_bb_reg(priv, 0xdf4, bMaskDWord); |
| 8310 | //RTPRINT(FINIT, INIT_IQK, ("0xdf4 = 0x%x, delay %d us\n", u4tmp, delaycount*delay+800)); |
| 8311 | delaycount++; |
| 8312 | delay = 100; |
| 8313 | u4tmp = (u4tmp & BIT(26)) >> 26; |
| 8314 | }while(u4tmp == 0x01 && delaycount < delaybound); |
| 8315 | |
| 8316 | } |
| 8317 | |
| 8318 | // if AP curve check fail return FALSE |
| 8319 | int _PHY_DPK_AP_curve_check(struct rtl8192cd_priv *priv, unsigned int *PA_power, unsigned int RegiesterNum) |
| 8320 | { |
| 8321 | unsigned int PA_power_temp[DP_PA_MODEL_NUM], i = 0, index = 5, |
| 8322 | base = 532, ref1, ref2; |
| 8323 | int power_I, power_Q; |
| 8324 | |
| 8325 | //store I, Q |
| 8326 | |
| 8327 | for(i = 0; i < DP_PA_MODEL_NUM; i++){ |
| 8328 | power_I = (PA_power[i] >> 8); |
| 8329 | if(power_I & BIT(7)) |
| 8330 | power_I |= bMaskH3Bytes; |
| 8331 | |
| 8332 | power_Q = PA_power[i] & bMaskByte0; |
| 8333 | if(power_Q & BIT(7)) |
| 8334 | power_Q |= bMaskH3Bytes; |
| 8335 | |
| 8336 | PA_power_temp[i] = power_I*power_I+power_Q*power_Q; |
| 8337 | } |
| 8338 | |
| 8339 | ref1 = PA_power_temp[0]; |
| 8340 | for(i = 0; i < index; i++) |
| 8341 | ref1 = (ref1 > PA_power_temp[i])?ref1:PA_power_temp[i]; |
| 8342 | |
| 8343 | ref2 = PA_power_temp[index]; |
| 8344 | for(i = index; i < index*2; i++) |
| 8345 | ref2 = (ref2 > PA_power_temp[i])?ref2:PA_power_temp[i]; |
| 8346 | |
| 8347 | DPK_DEBUG("==>_PHY_DPK_AP_cureve_check ref1 = 0x%x ref2 = 0x%x\n", ref1, ref2); |
| 8348 | |
| 8349 | if(ref1 == 0) |
| 8350 | return FALSE; |
| 8351 | |
| 8352 | return ((ref2 << 9)/ref1) < base; |
| 8353 | } |
| 8354 | |
| 8355 | // if DPK fail return FALSE |
| 8356 | int _PHY_DPK_check(struct rtl8192cd_priv *priv, unsigned int *PA_power, unsigned int RegiesterNum) |
| 8357 | { |
| 8358 | unsigned int base = 407, PA_power_temp[2], i = 0; |
| 8359 | int power_I, power_Q; |
| 8360 | |
| 8361 | while(i ==0 || i == (RegiesterNum-1)) |
| 8362 | { |
| 8363 | power_I = (PA_power[i] >> 8); |
| 8364 | if(power_I & BIT(7)) |
| 8365 | power_I |= bMaskH3Bytes; |
| 8366 | |
| 8367 | power_Q = PA_power[i] & bMaskByte0; |
| 8368 | if(power_Q & BIT(7)) |
| 8369 | power_Q |= bMaskH3Bytes; |
| 8370 | |
| 8371 | PA_power_temp[i==0?0:1] = power_I*power_I+ power_Q*power_Q; |
| 8372 | |
| 8373 | DPK_DEBUG("==>_PHY_DPK_check pa_power_temp[%d] 0x%x\n", i, PA_power_temp[i==0?0:1]); |
| 8374 | |
| 8375 | if(i == 0) |
| 8376 | i = RegiesterNum -1; |
| 8377 | else if (i == RegiesterNum -1) |
| 8378 | break; |
| 8379 | } |
| 8380 | |
| 8381 | //normalization |
| 8382 | if(PA_power_temp[0] == 0) |
| 8383 | return TRUE; |
| 8384 | else |
| 8385 | return (((PA_power_temp[1] << 9) /PA_power_temp[0]) <= base); |
| 8386 | |
| 8387 | } |
| 8388 | |
| 8389 | int _PHY_Find_Tx_Power_Index(struct rtl8192cd_priv *priv, unsigned int *PA_power, unsigned char path, unsigned char bPlus3db, char bDecreaseTxIndex, unsigned char *tx_index_out) |
| 8390 | { |
| 8391 | unsigned char i, tx_index = bDecreaseTxIndex?0x0f:0x15; |
| 8392 | unsigned int tmpReg[11], tmpBase, RegNum = 11, base = /*323*/256; |
| 8393 | unsigned int PA_power_normal[11]; |
| 8394 | // unsigned int check_base =bPlus3db?(400-base):(323-base); |
| 8395 | unsigned int check_base =bPlus3db?400:323; |
| 8396 | |
| 8397 | int power_I, power_Q; |
| 8398 | int index = -1; |
| 8399 | |
| 8400 | DPK_DEBUG("==>tx_index minus %d bplus3db %d\n", base, bPlus3db); |
| 8401 | |
| 8402 | _PHY_DPK_polling(priv); |
| 8403 | |
| 8404 | if(path == RF_PATH_A) |
| 8405 | { |
| 8406 | phy_set_bb_reg(priv, 0xb00, bMaskDWord, 0x01017018); |
| 8407 | tmpReg[0] = phy_query_bb_reg(priv, 0xbdc, bMaskDWord); |
| 8408 | tmpReg[1] = phy_query_bb_reg(priv, 0xbe8, bMaskDWord); |
| 8409 | |
| 8410 | phy_set_bb_reg(priv, 0xb00, bMaskDWord, 0x01017019); |
| 8411 | tmpReg[2] = phy_query_bb_reg(priv, 0xbdc, bMaskDWord); |
| 8412 | tmpReg[3] = phy_query_bb_reg(priv, 0xbe0, bMaskDWord); |
| 8413 | tmpReg[4] = phy_query_bb_reg(priv, 0xbe8, bMaskDWord); |
| 8414 | |
| 8415 | phy_set_bb_reg(priv, 0xb00, bMaskDWord, 0x0101701a); |
| 8416 | tmpReg[5] = phy_query_bb_reg(priv, 0xbe0, bMaskDWord); |
| 8417 | |
| 8418 | phy_set_bb_reg(priv, 0xb00, bMaskDWord, 0x0101701b); |
| 8419 | tmpReg[6] = phy_query_bb_reg(priv, 0xbdc, bMaskDWord); |
| 8420 | tmpReg[7] = phy_query_bb_reg(priv, 0xbe8, bMaskDWord); |
| 8421 | |
| 8422 | phy_set_bb_reg(priv, 0xb00, bMaskDWord, 0x0101701c); |
| 8423 | tmpReg[8] = phy_query_bb_reg(priv, 0xbe8, bMaskDWord); |
| 8424 | |
| 8425 | phy_set_bb_reg(priv, 0xb00, bMaskDWord, 0x0101701e); |
| 8426 | tmpReg[9] = phy_query_bb_reg(priv, 0xbdc, bMaskDWord); |
| 8427 | |
| 8428 | phy_set_bb_reg(priv, 0xb00, bMaskDWord, 0x0101701f); |
| 8429 | tmpReg[10] = phy_query_bb_reg(priv, 0xbe8, bMaskDWord); |
| 8430 | |
| 8431 | //RTPRINT(FINIT, INIT_IQK, ("==>_PHY_Find_Tx_Power_Index path A\n")); |
| 8432 | |
| 8433 | } |
| 8434 | else if(path == RF_PATH_B) |
| 8435 | { |
| 8436 | phy_set_bb_reg(priv, 0xb70, bMaskDWord, 0x01017018); |
| 8437 | tmpReg[0] = phy_query_bb_reg(priv, 0xbec, bMaskDWord); |
| 8438 | tmpReg[1] = phy_query_bb_reg(priv, 0xbf8, bMaskDWord); |
| 8439 | |
| 8440 | phy_set_bb_reg(priv, 0xb70, bMaskDWord, 0x01017019); |
| 8441 | tmpReg[2] = phy_query_bb_reg(priv, 0xbec, bMaskDWord); |
| 8442 | tmpReg[3] = phy_query_bb_reg(priv, 0xbf0, bMaskDWord); |
| 8443 | tmpReg[4] = phy_query_bb_reg(priv, 0xbf8, bMaskDWord); |
| 8444 | |
| 8445 | phy_set_bb_reg(priv, 0xb70, bMaskDWord, 0x0101701a); |
| 8446 | tmpReg[5] = phy_query_bb_reg(priv, 0xbf4, bMaskDWord); |
| 8447 | |
| 8448 | phy_set_bb_reg(priv, 0xb70, bMaskDWord, 0x0101701b); |
| 8449 | tmpReg[6] = phy_query_bb_reg(priv, 0xbec, bMaskDWord); |
| 8450 | tmpReg[7] = phy_query_bb_reg(priv, 0xbf8, bMaskDWord); |
| 8451 | |
| 8452 | phy_set_bb_reg(priv, 0xb70, bMaskDWord, 0x0101701c); |
| 8453 | tmpReg[8] = phy_query_bb_reg(priv, 0xbf8, bMaskDWord); |
| 8454 | |
| 8455 | phy_set_bb_reg(priv, 0xb70, bMaskDWord, 0x0101701e); |
| 8456 | tmpReg[9] = phy_query_bb_reg(priv, 0xbec, bMaskDWord); |
| 8457 | |
| 8458 | phy_set_bb_reg(priv, 0xb70, bMaskDWord, 0x0101701f); |
| 8459 | tmpReg[10] = phy_query_bb_reg(priv, 0xbf8, bMaskDWord); |
| 8460 | |
| 8461 | //RTPRINT(FINIT, INIT_IQK, ("==>_PHY_Find_Tx_Power_Index path B\n")); |
| 8462 | |
| 8463 | } |
| 8464 | |
| 8465 | for(i = 0; i < RegNum; i++) |
| 8466 | { |
| 8467 | power_I = (tmpReg[i] >> 8); |
| 8468 | if(power_I & BIT(7)) |
| 8469 | power_I |= bMaskH3Bytes; |
| 8470 | |
| 8471 | power_Q = tmpReg[i] & bMaskByte0; |
| 8472 | if(power_Q & BIT(7)) |
| 8473 | power_Q |= bMaskH3Bytes; |
| 8474 | |
| 8475 | PA_power[i] = power_I*power_I+ power_Q*power_Q; |
| 8476 | } |
| 8477 | |
| 8478 | //normalization |
| 8479 | tmpBase = PA_power[0]; |
| 8480 | //RTPRINT(FINIT, INIT_IQK, ("==>PA_power START normalized\n")); |
| 8481 | |
| 8482 | if(tmpBase == 0) |
| 8483 | DPK_DEBUG("==>PA_power[0] is ZERO !!!!!\n"); |
| 8484 | |
| 8485 | for(i = 0; i < RegNum; i++) |
| 8486 | { |
| 8487 | if(tmpBase != 0) |
| 8488 | PA_power[i] = (PA_power[i] << 9) /tmpBase; |
| 8489 | else |
| 8490 | PA_power[i] = (PA_power[i] << 9) ; |
| 8491 | PA_power_normal[i] = PA_power[i]; |
| 8492 | PA_power[i] = (PA_power[i] > base)?(PA_power[i] - base):(base - PA_power[i]); |
| 8493 | DPK_DEBUG("==>PA_power normalized index %d value 0x%x\n", i, PA_power[i]); |
| 8494 | } |
| 8495 | |
| 8496 | //choose min for TX index to do DPK |
| 8497 | base = bMaskDWord; |
| 8498 | for(i = 0; i < RegNum; i++) |
| 8499 | { |
| 8500 | if(PA_power[i] < base) |
| 8501 | { |
| 8502 | base = PA_power[i]; |
| 8503 | index = i; |
| 8504 | } |
| 8505 | } |
| 8506 | |
| 8507 | if(index == -1) |
| 8508 | { |
| 8509 | tx_index = 0x1c; |
| 8510 | index = 0x1f - tx_index; |
| 8511 | } |
| 8512 | else |
| 8513 | { |
| 8514 | tx_index += index; |
| 8515 | } |
| 8516 | |
| 8517 | DPK_DEBUG("==>tx_index result 0x%x PA_power[%d] = 0x%x\n", tx_index, index, PA_power[index]); |
| 8518 | |
| 8519 | *tx_index_out = tx_index; |
| 8520 | |
| 8521 | //Check pattern reliability |
| 8522 | if(((PA_power_normal[index] > check_base) && (tx_index == 0x1f)) || |
| 8523 | ((PA_power_normal[10] > base) && (!bPlus3db)) || |
| 8524 | ((tx_index < 0x1a) && (!bPlus3db)) || |
| 8525 | ((tx_index < 0x13) && (bDecreaseTxIndex)) |
| 8526 | ) |
| 8527 | return FALSE; |
| 8528 | else |
| 8529 | return TRUE; |
| 8530 | // return tx_index; |
| 8531 | |
| 8532 | } |
| 8533 | |
| 8534 | unsigned char _PHY_Find_Rx_Power_Index(struct rtl8192cd_priv *priv, unsigned char tx_index, unsigned char rx_index, unsigned char path, char *bDecreaseTxIndex) |
| 8535 | { |
| 8536 | // u1Byte rx_index = 0x04; |
| 8537 | unsigned int tmpReg; |
| 8538 | int power_I, power_Q, tmp; |
| 8539 | unsigned char bPlus = FALSE, bMinus = FALSE; |
| 8540 | unsigned short offset[2][2] = {{ //path, offset |
| 8541 | 0xb28, 0xbe8},{ |
| 8542 | 0xb98, 0xbf8}}; |
| 8543 | int round = 0; |
| 8544 | |
| 8545 | while (TRUE) { |
| 8546 | tmpReg = 0x52000 | tx_index | (rx_index << 5); |
| 8547 | phy_set_rf_reg(priv, path, RF_AC, bMask20Bits, tmpReg); |
| 8548 | //RTPRINT(FINIT, INIT_IQK, ("==>RF 0ffset 0 = 0x%x readback = 0x%x\n", tmpReg, |
| 8549 | //phy_query_rf_reg(pAdapter, path, RF_AC, bRFRegOffsetMask))); |
| 8550 | |
| 8551 | //----send one shot signal----// |
| 8552 | phy_set_bb_reg(priv, offset[path][0], bMaskDWord, 0x80080000); //0xb28, 0xb98 |
| 8553 | phy_set_bb_reg(priv, offset[path][0], bMaskDWord, 0x00080000); |
| 8554 | |
| 8555 | _PHY_DPK_polling(priv); |
| 8556 | |
| 8557 | tmpReg = phy_query_bb_reg(priv, offset[path][1], bMaskDWord); |
| 8558 | power_I = ((tmpReg & bMaskByte1) >> 8); |
| 8559 | power_Q = tmpReg & bMaskByte0; |
| 8560 | |
| 8561 | if(power_I & BIT(7)) |
| 8562 | { |
| 8563 | power_I |= bMaskH3Bytes; |
| 8564 | power_I = 0-power_I; //absolute value |
| 8565 | } |
| 8566 | |
| 8567 | if(power_Q & BIT(7)) |
| 8568 | { |
| 8569 | power_Q |= bMaskH3Bytes; |
| 8570 | power_Q = 0-power_Q; |
| 8571 | } |
| 8572 | //RTPRINT(FINIT, INIT_IQK, ("==>rx_index 0x%x I = 0x%x Q = 0x%x offset 0xbe8 = 0x%x\n", rx_index, power_I, power_Q, tmpReg)); |
| 8573 | |
| 8574 | tmp = (power_I > power_Q)? power_I:power_Q; |
| 8575 | |
| 8576 | #if 0 |
| 8577 | if((rx_index == 0 && tmp > 0x6f)||(rx_index == 31 && tmp < 0x50)) |
| 8578 | break; |
| 8579 | #endif |
| 8580 | |
| 8581 | if((tmp<= 0x6f && tmp >= 0x50) ) |
| 8582 | { |
| 8583 | break; |
| 8584 | } |
| 8585 | else if(tmp < 0x50) |
| 8586 | { |
| 8587 | bPlus = TRUE; |
| 8588 | if(bMinus) |
| 8589 | { |
| 8590 | rx_index++; |
| 8591 | break; |
| 8592 | } |
| 8593 | // rx_index++; |
| 8594 | rx_index += 2; |
| 8595 | } |
| 8596 | else if (tmp > 0x6f) |
| 8597 | { |
| 8598 | bMinus = TRUE; |
| 8599 | if(bPlus) |
| 8600 | { |
| 8601 | rx_index--; |
| 8602 | break; |
| 8603 | } |
| 8604 | // rx_index--; |
| 8605 | rx_index -= 2; |
| 8606 | } |
| 8607 | |
| 8608 | if(rx_index == 0 || rx_index == 31) |
| 8609 | break; |
| 8610 | |
| 8611 | if (++round > 10000) { |
| 8612 | panic_printk("%s[%d] while (1) goes too many\n", __FUNCTION__, __LINE__); |
| 8613 | break; |
| 8614 | } |
| 8615 | } |
| 8616 | if(rx_index == 0 && tmp > 0x6f) |
| 8617 | *bDecreaseTxIndex = TRUE; |
| 8618 | |
| 8619 | DPK_DEBUG("==>rx_index FINAL 0x%x I = 0x%x Q = 0x%x\n", rx_index, power_I, power_Q); |
| 8620 | |
| 8621 | return rx_index; |
| 8622 | |
| 8623 | } |
| 8624 | |
| 8625 | void PHY_DPCalibrate(struct rtl8192cd_priv *priv) |
| 8626 | { |
| 8627 | char is2T = ((priv->pmib->dot11RFEntry.macPhyMode != DUALMAC_DUALPHY) ?1 :0); |
| 8628 | |
| 8629 | unsigned int tmpReg, value32/*, checkbit*/; |
| 8630 | unsigned int AFE_backup[IQK_ADDA_REG_NUM]; |
| 8631 | static unsigned int AFE_REG[IQK_ADDA_REG_NUM] = { |
| 8632 | REG_FPGA0_XCD_SWITCH_CONTROL, 0xe6c, 0xe70, 0xe74, 0xe78, |
| 8633 | 0xe7c, 0xe80, 0xe84, 0xe88, 0xe8c, |
| 8634 | 0xed0, 0xed4, 0xed8, 0xedc, 0xee0, |
| 8635 | 0xeec}; |
| 8636 | |
| 8637 | static unsigned int BB_backup[DP_BB_REG_NUM]; |
| 8638 | static unsigned int BB_REG[DP_BB_REG_NUM] = { |
| 8639 | REG_OFDM_0_TRX_PATH_ENABLE, REG_FPGA0_RFMOD, |
| 8640 | REG_OFDM_0_TR_MUX_PAR, REG_FPGA0_XCD_RF_INTERFACE_SW, |
| 8641 | REG_FPGA0_ANALOG_PARAMETER4, REG_FPGA0_XAB_RF_INTERFACE_SW, |
| 8642 | REG_TX_AGC_B_CCK_11_A_CCK_2_11 |
| 8643 | }; |
| 8644 | |
| 8645 | static unsigned int BB_backup_A[DP_BB_REG_NUM_A]; |
| 8646 | static unsigned int BB_REG_A[DP_BB_REG_NUM_A] = { |
| 8647 | REG_FPGA0_XA_RF_INTERFACE_OE, REG_TX_AGC_A_RATE18_06, |
| 8648 | REG_TX_AGC_A_RATE54_24, REG_TX_AGC_A_CCK_1_MCS32, |
| 8649 | 0xe0c, REG_TX_AGC_A_MCS03_MCS00, |
| 8650 | REG_TX_AGC_A_MCS07_MCS04, REG_TX_AGC_A_MCS11_MCS08, |
| 8651 | REG_TX_AGC_A_MCS15_MCS12, REG_OFDM_0_XA_AGC_CORE1/*, |
| 8652 | rBndA*/ |
| 8653 | }; |
| 8654 | |
| 8655 | |
| 8656 | static unsigned int BB_backup_B[DP_BB_REG_NUM_B]; |
| 8657 | static unsigned int BB_REG_B[DP_BB_REG_NUM_B] = { |
| 8658 | REG_FPGA0_XB_RF_INTERFACE_OE, REG_TX_AGC_B_RATE18_06, |
| 8659 | REG_TX_AGC_B_RATE54_24, REG_TX_AGC_B_CCK_1_55_MCS32, |
| 8660 | REG_TX_AGC_B_MCS03_MCS00, REG_TX_AGC_B_MCS07_MCS04, |
| 8661 | REG_TX_AGC_B_MCS11_MCS08, REG_TX_AGC_B_MCS15_MCS12, |
| 8662 | REG_OFDM_0_XB_AGC_CORE1 /*, rBndB*/ |
| 8663 | }; |
| 8664 | |
| 8665 | static unsigned int BB_settings[DP_BB_REG_NUM_settings] = { |
| 8666 | 0x00a05430, 0x02040000, 0x000800e4, 0x22208000, |
| 8667 | 0xccf000c0/*, 0x07600760*/}; |
| 8668 | |
| 8669 | static unsigned int BB_REG_loop[DP_PATH_NUM][DP_BB_REG_NUM_loop] = { |
| 8670 | {0xb00, 0xb04, 0xb28, 0xb68, |
| 8671 | 0xb08, 0xb0c, 0xb10, 0xb14, |
| 8672 | 0xb18, 0xb1c, 0xb20, 0xb24, |
| 8673 | 0xe28, 0xb00, 0xb04, 0xb08, |
| 8674 | 0xb0c, 0xb10, 0xb14, 0xb18, |
| 8675 | 0xb1c, 0xb20, 0xb24, 0xb28, |
| 8676 | 0xb2c, rBndA, 0xb34, 0xb38, |
| 8677 | 0xb3c, 0xe28}, |
| 8678 | {0xb70, 0xb74, 0xb98, 0xb6C, |
| 8679 | 0xb78, 0xb7c, 0xb80, 0xb84, |
| 8680 | 0xb88, 0xb8c, 0xb90, 0xb94, |
| 8681 | 0xe28, 0xb60, 0xb64, 0xb68, |
| 8682 | 0xb6c, 0xb70, 0xb74, 0xb78, |
| 8683 | 0xb7c, 0xb80, 0xb84, 0xb88, |
| 8684 | 0xb8c, 0xb90, 0xb94, 0xb98, |
| 8685 | 0xb9c, 0xe28} |
| 8686 | }; |
| 8687 | |
| 8688 | static unsigned int BB_settings_loop[DP_BB_REG_NUM_loop] = { |
| 8689 | 0x01017e18, 0xf76d9f84, 0x00080000, 0x11880000, |
| 8690 | 0x41382e21, 0x5b554f48, 0x6f6b6661, 0x817d7874, |
| 8691 | 0x908c8884, 0x9d9a9793, 0xaaa7a4a1, 0xb6b3b0ad, |
| 8692 | 0x40000000, 0x7d327c18, 0x7e057db3, 0x7e5f7e37, |
| 8693 | 0x7e967e7c, 0x7ebe7eac, 0x7ed77ecc, 0x7eee7ee4, |
| 8694 | 0x7f017ef9, 0x7f0e7f07, 0x7f1c7f15, 0x7f267f20, |
| 8695 | 0x7f2f7f2a, 0x7f377f34, 0x7f3e7f3b, 0x7f457f42, |
| 8696 | 0x7f4b7f48, 0x00000000 |
| 8697 | }; |
| 8698 | |
| 8699 | static unsigned int BB_settings_loop_3db[DP_BB_REG_NUM_loop] = { |
| 8700 | 0x01017e18, 0xf76d9f84, 0x00080000, 0x11880000, |
| 8701 | 0x5b4e402e, 0x7f776f65, 0x9c968f88, 0xb5afa8a3, |
| 8702 | 0xcac4bfb9, 0xdcd8d4ce, 0xeeeae6e2, 0xfffbf7f2, |
| 8703 | 0x40000000, 0x7dfe7d32, 0x7e967e59, 0x7ed77eba, |
| 8704 | 0x7efd7eeb, 0x7f1a7f0e, 0x7f2d7f25, 0x7f3c7f36, |
| 8705 | 0x7f4a7f44, 0x7f547f4e, 0x7f5d7f58, 0x7f657f60, |
| 8706 | 0x7f6a7f68, 0x7f717f6e, 0x7f767f73, 0x7f7b7f78, |
| 8707 | 0x7f7f7f7d, 0x00000000 |
| 8708 | }; |
| 8709 | |
| 8710 | static unsigned int BB_settings_loop_tx[DP_BB_REG_NUM_loop] = { |
| 8711 | 0x01017e18, 0xf76d9f84, 0x00080000, 0x11880000, |
| 8712 | 0x21212121, 0x21212121, 0x21212121, 0x21212121, |
| 8713 | 0x21212121, 0x21212121, 0x21212121, 0x21212121, |
| 8714 | 0x40000000, 0x7c187c18, 0x7c187c18, 0x7c187c18, |
| 8715 | 0x7c187c18, 0x7c187c18, 0x7c187c18, 0x7c187c18, |
| 8716 | 0x7c187c18, 0x7c187c18, 0x7c187c18, 0x7c187c18, |
| 8717 | 0x7c187c18, 0x7c187c18, 0x7c187c18, 0x7c187c18, |
| 8718 | 0x7c187c18, 0x00000000 |
| 8719 | }; |
| 8720 | |
| 8721 | static unsigned int BB_settings_loop_tx_3db[DP_BB_REG_NUM_loop] = { |
| 8722 | 0x01017e18, 0xf76d9f84, 0x00080000, 0x11880000, |
| 8723 | 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, |
| 8724 | 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, |
| 8725 | 0x40000000, 0x7d327d32, 0x7d327d32, 0x7d327d32, |
| 8726 | 0x7d327d32, 0x7d327d32, 0x7d327d32, 0x7d327d32, |
| 8727 | 0x7d327d32, 0x7d327d32, 0x7d327d32, 0x7d327d32, |
| 8728 | 0x7d327d32, 0x7d327d32, 0x7d327d32, 0x7d327d32, |
| 8729 | 0x7d327d32, 0x00000000 |
| 8730 | }; |
| 8731 | |
| 8732 | |
| 8733 | //for find 2dB loss point |
| 8734 | static unsigned int BB_settings_loop_tx_2[DP_BB_REG_NUM_loop] = { |
| 8735 | 0x01017e18, 0xf76d9f84, 0x00080000, 0x11880000, |
| 8736 | 0x41382e21, 0x5b554f48, 0x6f6b6661, 0x817d7874, |
| 8737 | 0x908c8884, 0x9d9a9793, 0xaaa7a4a1, 0xb6b3b0ad, |
| 8738 | 0x40000000, 0x7d327c18, 0x7e057db3, 0x7e5f7e37, |
| 8739 | 0x7e967e7c, 0x7ebe7eac, 0x7ed77ecc, 0x7eee7ee4, |
| 8740 | 0x7f017ef9, 0x7f0e7f07, 0x7f1c7f15, 0x7f267f20, |
| 8741 | 0x7f2f7f2a, 0x7f377f34, 0x7f3e7f3b, 0x7f457f42, |
| 8742 | 0x7f4b7f48, 0x00000000 |
| 8743 | }; |
| 8744 | |
| 8745 | //for find 2dB loss point |
| 8746 | static unsigned int BB_settings_loop_tx_2_3db[DP_BB_REG_NUM_loop] = { |
| 8747 | 0x01017e18, 0xf76d9f84, 0x00080000, 0x11880000, |
| 8748 | 0x5b4e402e, 0x7f776f65, 0x9c968f88, 0xb5afa8a3, |
| 8749 | 0xcac4bfb9, 0xdcd8d4ce, 0xeeeae6e2, 0xfffbf7f2, |
| 8750 | 0x40000000, 0x7dfe7d32, 0x7e967e59, 0x7ed77eba, |
| 8751 | 0x7efd7eeb, 0x7f1a7f0e, 0x7f2d7f25, 0x7f3c7f36, |
| 8752 | 0x7f4a7f44, 0x7f547f4e, 0x7f5d7f58, 0x7f657f60, |
| 8753 | 0x7f6a7f68, 0x7f717f6e, 0x7f767f73, 0x7f7b7f78, |
| 8754 | 0x7f7f7f7d, 0x00000000 |
| 8755 | }; |
| 8756 | |
| 8757 | |
| 8758 | static unsigned int BB_settings_loop_rx[DP_BB_REG_NUM_loop_rx] = { |
| 8759 | 0x01017e18, 0xf76d9f84, 0x00080000, 0x11880000, |
| 8760 | 0x21212121, 0x40000000, 0x7c187c18, 0x00000000 |
| 8761 | }; |
| 8762 | |
| 8763 | static unsigned int BB_settings_loop_rx_3db[DP_BB_REG_NUM_loop_rx] = { |
| 8764 | 0x01017e18, 0xf76d9f84, 0x00080000, 0x11880000, |
| 8765 | 0x2e2e2e2e, 0x40000000, 0x7d327d32, 0x00000000 |
| 8766 | }; |
| 8767 | |
| 8768 | static unsigned int BB_settings_loop_pa[DP_BB_REG_NUM_loop_pa] = { |
| 8769 | 0x02096eb8, 0xf76d9f84, 0x00044499, 0x02880140 |
| 8770 | }; |
| 8771 | |
| 8772 | static unsigned int BB_settings_loop_dp[DP_BB_REG_NUM_loop_pa] = { |
| 8773 | 0x01017098, 0x776d9f84, 0x00000000, 0x08080000 |
| 8774 | }; |
| 8775 | |
| 8776 | unsigned int *BB_settings_temp; |
| 8777 | |
| 8778 | static unsigned char Sram_db_settings[DP_SRAM_NUM_db] = { |
| 8779 | 0xfe, 0xf0, 0xe3, 0xd6, 0xca, |
| 8780 | 0xbf, 0xb4, 0xaa, 0xa0, 0x97, |
| 8781 | 0x8f, 0x87, 0x7f, 0x78, 0x71, |
| 8782 | 0x6b, 0x65, 0x5f, 0x5a, 0x55, |
| 8783 | 0x50, 0x4c, 0x47, 0x43, 0x40, |
| 8784 | 0x3c, 0x39, 0x35, 0x32, 0x2f, |
| 8785 | 0x2d, 0x2a, 0x28, 0x26, 0x23, |
| 8786 | 0x21, 0x20, 0x1e, 0x1c, 0x1a, |
| 8787 | 0x19, 0x18, 0x16, 0x16, 0x14, |
| 8788 | 0x13, 0x12, 0x11, 0x10, 0x0f, |
| 8789 | 0x0e, 0x0d, 0x0c, 0x0c, 0x0b, |
| 8790 | 0x0a, 0x0a, 0x09, 0x09, 0x08, |
| 8791 | 0x08, 0x07, 0x07, 0x06, 0x06, |
| 8792 | 0x06, 0x05, 0x05, 0x05, 0x04, |
| 8793 | 0x04, 0x04, 0x04, 0x03, 0x03, |
| 8794 | 0x03, 0x03, 0x03, 0x02, 0x02, |
| 8795 | 0x02, 0x02, 0x02, 0x02, 0x02, |
| 8796 | 0x01 |
| 8797 | }; |
| 8798 | |
| 8799 | //unsigned int pwsf[DP_SRAM_NUM]; |
| 8800 | |
| 8801 | static unsigned int offset[2][DP_OFFSET_NUM] = {{ //path, offset |
| 8802 | 0xe34, 0xb28, 0xb00, 0xbdc, 0xbc0, |
| 8803 | 0xbe8, REG_OFDM_0_XA_TX_IQ_IMBALANCE, rBndA, |
| 8804 | 0xb68},{ |
| 8805 | 0xe54, 0xb98, 0xb70, 0xbec, 0xbc4, |
| 8806 | 0xbf8, REG_OFDM_0_XB_TX_IQ_IMBALANCE, rBndB, |
| 8807 | 0xb6c}}; |
| 8808 | |
| 8809 | //unsigned char OFDM_min_index = 6, OFDM_min_index_internalPA = 3; |
| 8810 | unsigned char OFDM_index[2]; |
| 8811 | //unsigned char retrycount = 0, retrybound = 1; |
| 8812 | |
| 8813 | unsigned int RF_backup[DP_PATH_NUM][DP_RF_REG_NUM]; |
| 8814 | static unsigned int RF_REG[DP_RF_REG_NUM] = { |
| 8815 | RF_TX_G3, RF_TXPA_A4, RF_RXRF_A3, |
| 8816 | RF_BS_PA_APSET_G1_G4/*, RF_BS_PA_APSET_G5_G8, |
| 8817 | RF_BS_PA_APSET_G9_G11*/}; |
| 8818 | |
| 8819 | static unsigned int RF_AP_curve_select[DP_AP_CUREVE_SELECT_NUM] = { |
| 8820 | 0x7bdef, 0x94a52, 0xa5294/*, 0xb5ad6*/ }; |
| 8821 | |
| 8822 | static unsigned int RF_PA_BIAS[3][DP_PA_BIAS_NUM] = {{ //40MHz / 20MHz, original |
| 8823 | 0xe189f, 0xa189f, 0x6189f, 0x2189f },{ |
| 8824 | 0xe087f, 0xa087f, 0x6087f, 0x2087f },{ |
| 8825 | 0xe1874, 0xa1874, 0x61874, 0x21874}}; |
| 8826 | |
| 8827 | unsigned int PA_model_backup[DP_PATH_NUM][DP_PA_MODEL_NUM]; |
| 8828 | |
| 8829 | unsigned int PA_power[DP_PATH_NUM][DP_PA_MODEL_RUN_NUM*2]; |
| 8830 | |
| 8831 | #if DP_gain_loss == 1 |
| 8832 | |
| 8833 | int power_I, power_Q, coef; |
| 8834 | |
| 8835 | int gain_loss_backup[DP_PATH_NUM][DP_PA_MODEL_NUM]; //I,Q |
| 8836 | |
| 8837 | static unsigned int gain_loss_bound[DP_GAIN_LOSS_BOUND_NUM] = { |
| 8838 | 63676, 60114 , 56751 , 53577 , 49145, |
| 8839 | 47750, 45079 , 42557 , 40177 , 37929 , |
| 8840 | 35807 , 33804 , 31913, 30128 |
| 8841 | }; |
| 8842 | |
| 8843 | static int gain_loss_coef[DP_GAIN_LOSS_BOUND_NUM+1] = { |
| 8844 | 512, 527, 543, 558, 573, |
| 8845 | 589, 609, 625, 645, 666, |
| 8846 | 681, 701, 722, 742, 768 |
| 8847 | }; |
| 8848 | |
| 8849 | // BOOLEAN bNegative = FALSE; |
| 8850 | // unsigned char index_for_zero_db = 24, AP_curve_index = 0; |
| 8851 | unsigned char GainLossIndex = 0; //0db, 0x40 |
| 8852 | char SramIndex = 24; |
| 8853 | unsigned char /*index_for_zero_db = 6,*/ AP_curve_index = 0; |
| 8854 | |
| 8855 | #else |
| 8856 | |
| 8857 | unsigned char index_for_zero_db = 6, AP_curve_index = 0; |
| 8858 | int power_I, power_Q; |
| 8859 | static unsigned int gain_loss_bound[DP_GAIN_LOSS_BOUND_NUM] = { |
| 8860 | 61870, 55142, 49145, 43801, 39037, |
| 8861 | 34792, 31008, 27636 |
| 8862 | }; |
| 8863 | #endif |
| 8864 | |
| 8865 | unsigned int MAC_backup[IQK_MAC_REG_NUM]; |
| 8866 | static unsigned int MAC_REG[IQK_MAC_REG_NUM] = { |
| 8867 | 0x522, 0x550, 0x551, 0x040}; |
| 8868 | |
| 8869 | //unsigned int AFE_on_off[PATH_NUM] = { |
| 8870 | // 0x04db25a4, 0x0b1b25a4}; //path A on path B path A off path B on |
| 8871 | |
| 8872 | unsigned char path_num, /*path_bound,*/ path = RF_PATH_A, i, j, tx_index, rx_index; |
| 8873 | int index, index_1, index_repeat; |
| 8874 | |
| 8875 | char bInternalPA = FALSE; |
| 8876 | #if (DP_gain_loss != 1) |
| 8877 | char SkipStep5 = FALSE; |
| 8878 | #endif |
| 8879 | char bPlus3db = FALSE, bDecreaseTxIndex = FALSE, bDecreaseTxIndexWithRx = FALSE; |
| 8880 | |
| 8881 | #ifdef DFS |
| 8882 | if ((priv->pshare->rf_ft_var.dfsdelayiqk) && |
| 8883 | (OPMODE & WIFI_AP_STATE) && |
| 8884 | !priv->pmib->dot11DFSEntry.disable_DFS && |
| 8885 | (rtk_timer_pending(&priv->ch_avail_chk_timer) || |
| 8886 | priv->pmib->dot11DFSEntry.disable_tx)) |
| 8887 | return; |
| 8888 | #endif |
| 8889 | |
| 8890 | DPK_DEBUG("==>_PHY_DigitalPredistortion() interface index %d is2T = %d\n", priv->pshare->wlandev_idx, is2T); //anchin |
| 8891 | |
| 8892 | DPK_DEBUG("_PHY_DigitalPredistortion for %s\n", (is2T ? "2T2R" : "1T1R")); |
| 8893 | |
| 8894 | DPK_DEBUG("==>_PHY_DigitalPredistortion() current thermal meter = 0x%x PG thermal meter = 0x%x bPlus3db %d\n", |
| 8895 | priv->pshare->ThermalValue_DPKtrack, priv->pmib->dot11RFEntry.ther, bPlus3db); |
| 8896 | |
| 8897 | if ((priv->pmib->dot11RFEntry.phyBandSelect!= PHY_BAND_5G)||(GET_CHIP_VER(priv)!=VERSION_8192D)) |
| 8898 | return; |
| 8899 | |
| 8900 | bInternalPA = priv->pshare->rf_ft_var.use_intpa92d; |
| 8901 | |
| 8902 | if(!is2T) |
| 8903 | path_num = 1; |
| 8904 | else |
| 8905 | path_num = 2; |
| 8906 | |
| 8907 | if(!bInternalPA) { |
| 8908 | DPK_DEBUG("==>_PHY_DigitalPredistortion() NOT internal5G\n"); |
| 8909 | return; |
| 8910 | } |
| 8911 | |
| 8912 | if(priv->pshare->pwr_trk_ongoing){ |
| 8913 | DPK_DEBUG("==>_PHY_DigitalPredistortion() TxPowerTrackingInProgress() delay 100ms\n"); |
| 8914 | rtk_mod_timer(&priv->pshare->DPKTimer, jiffies + RTL_MILISECONDS_TO_JIFFIES(100)); |
| 8915 | return; |
| 8916 | } |
| 8917 | |
| 8918 | OFDM_index[RF_PATH_A] = priv->pshare->OFDM_index[RF_PATH_A]; |
| 8919 | OFDM_index[RF_PATH_B] = priv->pshare->OFDM_index[RF_PATH_B]; |
| 8920 | |
| 8921 | DPK_DEBUG("original index 0x%x \n", priv->pshare->OFDM_index[0]); |
| 8922 | |
| 8923 | priv->pshare->bDPKworking = TRUE; |
| 8924 | |
| 8925 | //save global setting |
| 8926 | //save BB default value |
| 8927 | _phy_save_adda_registers(priv, BB_REG, BB_backup, DP_BB_REG_NUM); |
| 8928 | |
| 8929 | //save MAC default value |
| 8930 | _phy_save_mac_registers(priv, MAC_REG, MAC_backup); |
| 8931 | |
| 8932 | //save AFE default value |
| 8933 | _phy_save_adda_registers(priv, AFE_REG, AFE_backup, IQK_ADDA_REG_NUM); |
| 8934 | |
| 8935 | //save path A default value |
| 8936 | //save path A BB default value |
| 8937 | _phy_save_adda_registers(priv, BB_REG_A, BB_backup_A, DP_BB_REG_NUM_A); |
| 8938 | |
| 8939 | //save path B BB default value |
| 8940 | if(is2T) |
| 8941 | _phy_save_adda_registers(priv, BB_REG_B, BB_backup_B, DP_BB_REG_NUM_B); |
| 8942 | |
| 8943 | //save pathA/B RF default value |
| 8944 | for(path=0; path<path_num; path++){ |
| 8945 | for(index=0; index<DP_RF_REG_NUM; index++) |
| 8946 | RF_backup[path][index] = phy_query_rf_reg(priv, path, RF_REG[index], bMaskDWord, 1); |
| 8947 | } |
| 8948 | |
| 8949 | //BB register setting |
| 8950 | for(index = 0; index < DP_BB_REG_NUM_settings; index++) |
| 8951 | phy_set_bb_reg(priv, BB_REG[index], bMaskDWord, BB_settings[index]); |
| 8952 | |
| 8953 | //BB path A debug setting |
| 8954 | phy_set_bb_reg(priv, rFPGA1_DebugSelect, bMaskDWord, 0x00000302); |
| 8955 | |
| 8956 | //BB pah A register setting: fix TRSW to TX, external PA on, external LAN off |
| 8957 | if(!bInternalPA) |
| 8958 | { |
| 8959 | phy_set_bb_reg(priv, REG_FPGA0_XAB_RF_INTERFACE_SW, bMaskDWord, 0x07600f60); |
| 8960 | phy_set_bb_reg(priv, REG_FPGA0_XA_RF_INTERFACE_OE, ~(BIT8|BIT9), 0x66e60a30); |
| 8961 | } |
| 8962 | else |
| 8963 | { |
| 8964 | phy_set_bb_reg(priv, REG_FPGA0_XAB_RF_INTERFACE_SW, bMaskDWord, 0x07600760); |
| 8965 | phy_set_bb_reg(priv, REG_FPGA0_XA_RF_INTERFACE_OE, ~(BIT8|BIT9), 0x66e60230); |
| 8966 | } |
| 8967 | phy_set_bb_reg(priv, rBndA, 0xF00000, 0x0a); |
| 8968 | |
| 8969 | //BB pah B register setting: fix TRSW to TX, external PA off, external LNA off |
| 8970 | if(is2T) |
| 8971 | { |
| 8972 | if(!bInternalPA) |
| 8973 | { |
| 8974 | phy_set_bb_reg(priv, REG_FPGA0_XAB_RF_INTERFACE_SW, bMaskDWord, 0x0f600f60); |
| 8975 | phy_set_bb_reg(priv, REG_FPGA0_XB_RF_INTERFACE_OE, bMaskDWord, 0x061f0130); |
| 8976 | } |
| 8977 | else |
| 8978 | { |
| 8979 | phy_set_bb_reg(priv, REG_FPGA0_XAB_RF_INTERFACE_SW, bMaskDWord, 0x07600760); |
| 8980 | phy_set_bb_reg(priv, REG_FPGA0_XB_RF_INTERFACE_OE, bMaskDWord, 0x061f0130); |
| 8981 | } |
| 8982 | phy_set_bb_reg(priv, rBndB, 0xF00000, 0x0a); |
| 8983 | } |
| 8984 | |
| 8985 | //MAC register setting |
| 8986 | _phy_mac_setting_calibration(priv, MAC_REG, MAC_backup); |
| 8987 | |
| 8988 | //path A/B DPK |
| 8989 | //Path-A/B AFE all on |
| 8990 | for(path=0; path<path_num; path++) |
| 8991 | { |
| 8992 | |
| 8993 | //if(is2T && !pHalData->InternalPA5G[path]) |
| 8994 | //continue; |
| 8995 | |
| 8996 | if(path == RF_PATH_B) |
| 8997 | { |
| 8998 | //BB pah A register setting:fix TRSW to TX;external LNA off |
| 8999 | if(!bInternalPA) |
| 9000 | { |
| 9001 | phy_set_bb_reg(priv, REG_FPGA0_XAB_RF_INTERFACE_SW, bMaskDWord, 0x0f600f60); |
| 9002 | phy_set_bb_reg(priv, REG_FPGA0_XA_RF_INTERFACE_OE, ~(BIT8|BIT9), 0x66e60230); |
| 9003 | } |
| 9004 | else |
| 9005 | { |
| 9006 | phy_set_bb_reg(priv, REG_FPGA0_XAB_RF_INTERFACE_SW, bMaskDWord, 0x07600760); |
| 9007 | phy_set_bb_reg(priv, REG_FPGA0_XA_RF_INTERFACE_OE, ~(BIT8|BIT9), 0x66e60230); |
| 9008 | } |
| 9009 | phy_set_bb_reg(priv, rBndA, 0xF00000, 0x0a); |
| 9010 | |
| 9011 | //BB pah B register setting:fix TRSW to TX;external LNA off |
| 9012 | if(is2T) |
| 9013 | { |
| 9014 | if(!bInternalPA) |
| 9015 | { |
| 9016 | phy_set_bb_reg(priv, REG_FPGA0_XAB_RF_INTERFACE_SW, bMaskDWord, 0x0f600f60); |
| 9017 | phy_set_bb_reg(priv, REG_FPGA0_XB_RF_INTERFACE_OE, bMaskDWord, 0x061f0930); |
| 9018 | } |
| 9019 | else |
| 9020 | { |
| 9021 | phy_set_bb_reg(priv, REG_FPGA0_XAB_RF_INTERFACE_SW, bMaskDWord, 0x07600760); |
| 9022 | phy_set_bb_reg(priv, REG_FPGA0_XB_RF_INTERFACE_OE, bMaskDWord, 0x061f0130); |
| 9023 | } |
| 9024 | phy_set_bb_reg(priv, rBndB, 0xF00000, 0x0a); |
| 9025 | } |
| 9026 | } |
| 9027 | |
| 9028 | AP_curve_index = 1; |
| 9029 | rx_index = 0x06; |
| 9030 | bPlus3db = FALSE; |
| 9031 | bDecreaseTxIndex = FALSE; |
| 9032 | |
| 9033 | if(path == RF_PATH_A) |
| 9034 | { |
| 9035 | _phy_path_adda_on(priv, AFE_REG, TRUE, is2T); |
| 9036 | } |
| 9037 | else |
| 9038 | { |
| 9039 | _phy_path_adda_on(priv, AFE_REG, FALSE, is2T); |
| 9040 | } |
| 9041 | |
| 9042 | if(path == RF_PATH_B) |
| 9043 | phy_set_bb_reg(priv, rFPGA1_DebugSelect, bMaskDWord, 0x00000303); |
| 9044 | |
| 9045 | //path A/B RF setting |
| 9046 | //internal lopback off |
| 9047 | if(path == RF_PATH_A && !bInternalPA) |
| 9048 | { |
| 9049 | phy_set_rf_reg(priv, RF_PATH_A, RF_MODE1, bMask20Bits, 0x5007f); |
| 9050 | phy_set_rf_reg(priv, RF_PATH_A, RF_MODE2, bMask20Bits, 0x6f1f9); |
| 9051 | } |
| 9052 | else if(path == RF_PATH_B) |
| 9053 | { |
| 9054 | phy_set_rf_reg(priv, RF_PATH_A, RF_MODE1, bMask20Bits, 0x1000f); |
| 9055 | phy_set_rf_reg(priv, RF_PATH_A, RF_MODE2, bMask20Bits, 0x60103); |
| 9056 | } |
| 9057 | |
| 9058 | phy_set_rf_reg(priv, path, RF_RXRF_A3, bMask20Bits, 0xef456); |
| 9059 | |
| 9060 | //Path A/B to standby mode |
| 9061 | phy_set_rf_reg(priv, path==RF_PATH_A?RF_PATH_B:RF_PATH_A, |
| 9062 | RF_AC, bMask20Bits, 0x10000); |
| 9063 | |
| 9064 | //set DPK PA bias table |
| 9065 | index = priv->pshare->CurrentChannelBW == CHANNEL_WIDTH_40?0:1; |
| 9066 | if(path == RF_PATH_A) |
| 9067 | { |
| 9068 | for(i = 0; i < path_num; i++) |
| 9069 | { |
| 9070 | for(j = 0; j < DP_PA_BIAS_NUM; j++) |
| 9071 | phy_set_rf_reg(priv, i, RF_TXBIAS, bMask20Bits, RF_PA_BIAS[index][j]); |
| 9072 | } |
| 9073 | } |
| 9074 | |
| 9075 | Step1: |
| 9076 | |
| 9077 | DPK_DEBUG("==>AP curve select 0x%x bplus3db %d path%s!!\n", RF_AP_curve_select[AP_curve_index], bPlus3db, path==RF_PATH_A?"A":"B"); |
| 9078 | |
| 9079 | //RF setting for AP curve selection |
| 9080 | //default AP curve = 15 |
| 9081 | phy_set_rf_reg(priv, path, RF_BS_PA_APSET_G1_G4, bMask20Bits, RF_AP_curve_select[AP_curve_index]); |
| 9082 | |
| 9083 | ////////////////////////////////////////////////// |
| 9084 | // step 1: find RF TX/RX index |
| 9085 | ///////////////////////////////////////////////// |
| 9086 | //find RF TX index |
| 9087 | //============================= |
| 9088 | // PAGE_B for Path-A PM setting |
| 9089 | //============================= |
| 9090 | // open inner loopback @ b00[19]:od 0xb00 0x01097018 |
| 9091 | if(bPlus3db) |
| 9092 | BB_settings_temp = &(BB_settings_loop_tx_3db[0]); |
| 9093 | else |
| 9094 | BB_settings_temp = &(BB_settings_loop_tx[0]); |
| 9095 | _PHY_SetADDARegisters(priv, BB_REG_loop[path], BB_settings_temp, DP_BB_REG_NUM_loop); |
| 9096 | |
| 9097 | if(bDecreaseTxIndex) |
| 9098 | tx_index = 0x19; |
| 9099 | else |
| 9100 | tx_index = 0x1f; |
| 9101 | bDecreaseTxIndexWithRx = FALSE; |
| 9102 | |
| 9103 | //Set Tx GAC = 0x1f, than find Rx AGC |
| 9104 | rx_index = _PHY_Find_Rx_Power_Index(priv, tx_index, rx_index, path, &bDecreaseTxIndexWithRx); |
| 9105 | if(bDecreaseTxIndexWithRx) |
| 9106 | { |
| 9107 | if(bDecreaseTxIndex) |
| 9108 | { |
| 9109 | phy_set_bb_reg(priv, offset[path][2], bMaskDWord, 0x01017098); //0xb00, 0xb70 |
| 9110 | phy_set_bb_reg(priv, offset[path][8], bMaskDWord, 0x28080000); //0xb68, 0xb6c |
| 9111 | |
| 9112 | for(i = 3; i < DP_RF_REG_NUM; i++) |
| 9113 | phy_set_rf_reg(priv, path, RF_REG[i], bMask20Bits, RF_backup[path][i]); |
| 9114 | |
| 9115 | //set original DPK bias table |
| 9116 | for(j = 0; j < DP_PA_BIAS_NUM; j++) |
| 9117 | phy_set_rf_reg(priv, path, RF_TXBIAS, bMask20Bits, RF_PA_BIAS[2][j]); |
| 9118 | continue; |
| 9119 | } |
| 9120 | else |
| 9121 | { |
| 9122 | bDecreaseTxIndex = TRUE; |
| 9123 | goto Step1; |
| 9124 | } |
| 9125 | } |
| 9126 | |
| 9127 | //find 2dB loss point |
| 9128 | //============================= |
| 9129 | // PAGE_B for Path-A PM setting |
| 9130 | //============================= |
| 9131 | // open inner loopback @ b00[19]:od 0xb00 0x01097018 |
| 9132 | if(bPlus3db) |
| 9133 | BB_settings_temp = &(BB_settings_loop_tx_2_3db[0]); |
| 9134 | else |
| 9135 | BB_settings_temp = &(BB_settings_loop_tx_2[0]); |
| 9136 | _PHY_SetADDARegisters(priv, BB_REG_loop[path], BB_settings_temp, DP_BB_REG_NUM_loop); |
| 9137 | |
| 9138 | //RF setting |
| 9139 | phy_set_rf_reg(priv, path, RF_AC, bMask20Bits, 0x52000 | tx_index | (rx_index << 5)); |
| 9140 | |
| 9141 | //----send one shot signal----// |
| 9142 | phy_set_bb_reg(priv, offset[path][1], bMaskDWord, 0x80080000); //0xb28, 0xb98 |
| 9143 | phy_set_bb_reg(priv, offset[path][1], bMaskDWord, 0x00080000); |
| 9144 | |
| 9145 | //get power |
| 9146 | if(!_PHY_Find_Tx_Power_Index(priv, PA_power[path], path, bPlus3db, bDecreaseTxIndex, &tx_index)) |
| 9147 | { |
| 9148 | if(/*tx_index == 0x1f &&*/ !bPlus3db) |
| 9149 | { |
| 9150 | if(bDecreaseTxIndex) |
| 9151 | { |
| 9152 | if(tx_index < 0x11) |
| 9153 | { |
| 9154 | phy_set_bb_reg(priv, offset[path][2], bMaskDWord, 0x01017098); //0xb00, 0xb70 |
| 9155 | phy_set_bb_reg(priv, offset[path][8], bMaskDWord, 0x28080000); //0xb68, 0xb6c |
| 9156 | |
| 9157 | for(i = 3; i < DP_RF_REG_NUM; i++) |
| 9158 | phy_set_rf_reg(priv, path, RF_REG[i], bMask20Bits, RF_backup[path][i]); |
| 9159 | |
| 9160 | //set original DPK bias table |
| 9161 | for(j = 0; j < DP_PA_BIAS_NUM; j++) |
| 9162 | phy_set_rf_reg(priv, path, RF_TXBIAS, bMask20Bits, RF_PA_BIAS[2][j]); |
| 9163 | |
| 9164 | continue; |
| 9165 | } |
| 9166 | else |
| 9167 | { |
| 9168 | //RTPRINT(FINIT, INIT_IQK, ("==>Check pattern reliability path%s SUCCESS tx_index = 0x1b!!!!\n", path==RF90_PATH_A?"A":"B")); |
| 9169 | } |
| 9170 | } |
| 9171 | else if(tx_index < 0x1a) |
| 9172 | { |
| 9173 | bDecreaseTxIndex = TRUE; |
| 9174 | goto Step1; |
| 9175 | } |
| 9176 | else |
| 9177 | { |
| 9178 | bPlus3db = TRUE; |
| 9179 | goto Step1; |
| 9180 | } |
| 9181 | } |
| 9182 | else if(tx_index == 0x1f) |
| 9183 | { |
| 9184 | DPK_DEBUG("==>Check pattern reliability path%s FAIL!!!!\n", path==RF_PATH_A?"A":"B"); |
| 9185 | phy_set_bb_reg(priv, offset[path][2], bMaskDWord, 0x01017098); //0xb00, 0xb70 |
| 9186 | phy_set_bb_reg(priv, offset[path][8], bMaskDWord, 0x28080000); //0xb68, 0xb6c |
| 9187 | |
| 9188 | for(i = 3; i < DP_RF_REG_NUM; i++) |
| 9189 | phy_set_rf_reg(priv, path, RF_REG[i], bMask20Bits, RF_backup[path][i]); |
| 9190 | |
| 9191 | //set original DPK bias table |
| 9192 | for(j = 0; j < DP_PA_BIAS_NUM; j++) |
| 9193 | phy_set_rf_reg(priv, path, RF_TXBIAS, bMask20Bits, RF_PA_BIAS[2][j]); |
| 9194 | |
| 9195 | continue; |
| 9196 | } |
| 9197 | |
| 9198 | |
| 9199 | } |
| 9200 | else |
| 9201 | { |
| 9202 | DPK_DEBUG("==>Check pattern reliability path%s SUCCESS!!!!\n", path==RF_PATH_A?"A":"B"); |
| 9203 | } |
| 9204 | |
| 9205 | //find RF RX index |
| 9206 | //============================= |
| 9207 | // PAGE_B for Path-A PM setting |
| 9208 | //============================= |
| 9209 | // open inner loopback @ b00[19]:od 0xb00 0x01097018 |
| 9210 | if(bPlus3db) |
| 9211 | BB_settings_temp = &(BB_settings_loop_rx_3db[0]); |
| 9212 | else |
| 9213 | BB_settings_temp = &(BB_settings_loop_rx[0]); |
| 9214 | |
| 9215 | for(i = 0; i < 4; i++) |
| 9216 | phy_set_bb_reg(priv, BB_REG_loop[path][i], bMaskDWord, BB_settings_temp[i]); |
| 9217 | for(; i < 12; i++) |
| 9218 | phy_set_bb_reg(priv, BB_REG_loop[path][i], bMaskDWord, BB_settings_temp[4]); |
| 9219 | phy_set_bb_reg(priv, BB_REG_loop[path][i], bMaskDWord, BB_settings_temp[5]); |
| 9220 | for(; i < 29; i++) |
| 9221 | phy_set_bb_reg(priv, BB_REG_loop[path][i], bMaskDWord, BB_settings_temp[6]); |
| 9222 | phy_set_bb_reg(priv, BB_REG_loop[path][i], bMaskDWord, BB_settings_temp[7]); |
| 9223 | |
| 9224 | rx_index = _PHY_Find_Rx_Power_Index(priv, tx_index, rx_index, path, &bDecreaseTxIndex); |
| 9225 | |
| 9226 | ////////////////////////////////////// |
| 9227 | //2.measure PA model |
| 9228 | ////////////////////////////////////// |
| 9229 | //========================================= |
| 9230 | //PAGE_B for Path-A PAS setting //========================================= |
| 9231 | // open inner loopback @ b00[19]:10 od 0xb00 0x01097018 |
| 9232 | if(bPlus3db) |
| 9233 | BB_settings_temp = &(BB_settings_loop_3db[0]); |
| 9234 | else |
| 9235 | BB_settings_temp = &(BB_settings_loop[0]); |
| 9236 | _PHY_SetADDARegisters(priv, BB_REG_loop[path], BB_settings_temp, DP_BB_REG_NUM_loop); |
| 9237 | |
| 9238 | //LNA VDD to gnd |
| 9239 | phy_set_rf_reg(priv,path, RF_AC, bMask20Bits, 0x52000 | tx_index | (rx_index << 5)); |
| 9240 | |
| 9241 | //----send one shot signal----// |
| 9242 | // Path A |
| 9243 | phy_set_bb_reg(priv, offset[path][1], bMaskDWord, 0x80080000); //0xb28, 0xb98 |
| 9244 | phy_set_bb_reg(priv, offset[path][1], bMaskDWord, 0x00080000); |
| 9245 | |
| 9246 | phy_set_rf_reg(priv, RF_PATH_A, RF_T_METER, BIT17|BIT16, 0x03); |
| 9247 | |
| 9248 | _PHY_DPK_polling(priv); |
| 9249 | |
| 9250 | priv->pshare->ThermalValue_DPKstore = (unsigned char)phy_query_rf_reg(priv, RF_PATH_A, RF_T_METER, 0xf800, 1); //0x42: RF Reg[15:11] 92D |
| 9251 | |
| 9252 | // read PA model and save to PA_model_A[32] |
| 9253 | for(i = 0; i < DP_PA_MODEL_RUN_NUM; i++) |
| 9254 | { |
| 9255 | phy_set_bb_reg(priv, offset[path][2], bMaskDWord, 0x01017018+i); //0xb00, 0xb70 |
| 9256 | for(index = 0; index < DP_PA_MODEL_PER_RUN_NUM; index++) |
| 9257 | { |
| 9258 | PA_model_backup[path][i*4+index] = phy_query_bb_reg(priv, offset[path][3]+index*4, bMaskDWord); //0xbdc, 0xbec |
| 9259 | DPK_DEBUG("==>PA_model_backup index %d value 0x%x()\n", i*4+index, PA_model_backup[path][i*4+index]); |
| 9260 | } |
| 9261 | } |
| 9262 | |
| 9263 | #if 0 |
| 9264 | //find appropriate AP curve |
| 9265 | if(AP_curve_index != (DP_AP_CUREVE_SELECT_NUM-1)) |
| 9266 | { |
| 9267 | if(!_PHY_DPK_AP_curve_check(priv, PA_model_backup[path], DP_PA_MODEL_NUM)) |
| 9268 | { |
| 9269 | DPK_DEBUG("==>find appropriate AP curve 0x%x path%s FAIL!!!!\n", RF_AP_curve_select[AP_curve_index], path==RF_PATH_A?"A":"B"); |
| 9270 | AP_curve_index++; |
| 9271 | if(AP_curve_index < DP_AP_CUREVE_SELECT_NUM) |
| 9272 | goto Step1; |
| 9273 | } |
| 9274 | else |
| 9275 | { |
| 9276 | DPK_DEBUG("==>find appropriate AP curve path%s SUCCESS!!!!\n", path==RF_PATH_A?"A":"B"); |
| 9277 | } |
| 9278 | } |
| 9279 | #endif |
| 9280 | |
| 9281 | //check PA model |
| 9282 | if(!_PHY_DPK_check(priv, PA_model_backup[path], DP_PA_MODEL_NUM)) |
| 9283 | { |
| 9284 | phy_set_bb_reg(priv, offset[path][2], bMaskDWord, 0x01017098); // add in 2011-06-02 |
| 9285 | phy_set_bb_reg(priv, offset[path][8], bMaskDWord, 0x28080000); //0xb68, 0xb6c |
| 9286 | |
| 9287 | for(i = 3; i < DP_RF_REG_NUM; i++) |
| 9288 | phy_set_rf_reg(priv, path, RF_REG[i], bMaskDWord, RF_backup[path][i]); |
| 9289 | DPK_DEBUG("==>PA model path%s FAIL!!!!\n", path==RF_PATH_A?"A":"B"); |
| 9290 | priv->pshare->bDPKdone[path] = FALSE; |
| 9291 | //set original DPK bias table |
| 9292 | for(j = 0; j < DP_PA_BIAS_NUM; j++) |
| 9293 | phy_set_rf_reg(priv, path, RF_TXBIAS, bMask20Bits, RF_PA_BIAS[2][j]); |
| 9294 | |
| 9295 | continue; |
| 9296 | } |
| 9297 | else |
| 9298 | { |
| 9299 | DPK_DEBUG("==>PA model path%s SUCCESS!!!!\n", path==RF_PATH_A?"A":"B"); |
| 9300 | // priv->pshare->bDPKdone[path] = TRUE; |
| 9301 | // priv->pshare->bDPKstore = TRUE; |
| 9302 | } |
| 9303 | |
| 9304 | ///////////////////////////////////////////////////////////////////////////////////////////////////// |
| 9305 | // step 3: fill PA model to DP Calibration |
| 9306 | ///////////////////////////////////////////////////////////////////////////////////////////////////// |
| 9307 | //fill BB TX index for the DPK reference |
| 9308 | DPK_DEBUG("==>fill PA model to DP Calibration\n"); |
| 9309 | |
| 9310 | if(path == RF_PATH_A){ |
| 9311 | for(index = 0; index < DP_PA_MODEL_RUN_NUM; index++){ |
| 9312 | if(index != 3){ |
| 9313 | phy_set_bb_reg(priv, 0xe00+index*4, bMaskDWord, 0x3c3c3c3c); |
| 9314 | } else { |
| 9315 | phy_set_bb_reg(priv, 0xe00+index*4, bMaskDWord, 0x03903c3c); |
| 9316 | } |
| 9317 | } |
| 9318 | phy_set_bb_reg(priv, 0x86c, bMaskDWord, 0x3c3c3c3c); |
| 9319 | }else if (path == RF_PATH_B){ |
| 9320 | for(index = 0; index < 4; index++) { |
| 9321 | phy_set_bb_reg(priv, 0x830+index*4, bMaskDWord, 0x3c3c3c3c); |
| 9322 | } |
| 9323 | for(index = 0; index < 2; index++) { |
| 9324 | phy_set_bb_reg(priv, 0x848+index*4, bMaskDWord, 0x3c3c3c3c); |
| 9325 | } |
| 9326 | for(index = 0; index < 2; index++) { |
| 9327 | phy_set_bb_reg(priv, 0x868+index*4, bMaskDWord, 0x3c3c3c3c); |
| 9328 | } |
| 9329 | } |
| 9330 | |
| 9331 | // SRAM boundary setting |
| 9332 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0x400000); |
| 9333 | |
| 9334 | if(priv->pshare->phw->bNewTxGainTable) |
| 9335 | phy_set_bb_reg(priv, offset[path][4], bMaskDWord, 0x0008421f); //0xbc0, 0xbc4 |
| 9336 | else |
| 9337 | phy_set_bb_reg(priv, offset[path][4], bMaskDWord, 0x0009ce7f); //0xbc0, 0xbc4 |
| 9338 | |
| 9339 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0); |
| 9340 | |
| 9341 | _PHY_SetADDARegisters(priv, BB_REG_loop[path], BB_settings_loop_pa, DP_BB_REG_NUM_loop_pa); |
| 9342 | |
| 9343 | // fill PA model to page B1 registers |
| 9344 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0x400000); |
| 9345 | for(index = 0; index < (DP_PA_MODEL_NUM/2); index++){ //path A = 0xb00, path B = 0xb60 |
| 9346 | phy_set_bb_reg(priv, 0xb00+index*4+path*0x60, bMaskDWord, |
| 9347 | (PA_model_backup[path][index*2+1] << 16) | PA_model_backup[path][index*2]); |
| 9348 | } |
| 9349 | phy_set_bb_reg(priv, 0xe28, 0xffffff00, 0); |
| 9350 | |
| 9351 | //one shot |
| 9352 | phy_set_bb_reg(priv, offset[path][1], bMaskDWord, 0x80044499); //0xb28, 0xb98 |
| 9353 | phy_set_bb_reg(priv, offset[path][1], bMaskDWord, 0x00044499); |
| 9354 | |
| 9355 | _PHY_DPK_polling(priv); |
| 9356 | |
| 9357 | #if 1 |
| 9358 | ////////////////////////////////////////////////////// |
| 9359 | // step 4: calculate gain loss caused by DP |
| 9360 | ////////////////////////////////////////////////////// |
| 9361 | phy_set_bb_reg(priv, offset[path][2], bMaskDWord, 0x0029701f); //0xb00, 0xb70 |
| 9362 | tmpReg = phy_query_bb_reg(priv, offset[path][5], bMaskDWord); //0xbe8, 0xbf8 |
| 9363 | |
| 9364 | power_I = (tmpReg >> 16); |
| 9365 | if(power_I & BIT(15)) |
| 9366 | power_I |= bMaskLWord; ////////ZZZZZZZZZZZZZZZZZZ |
| 9367 | |
| 9368 | power_Q = tmpReg & bMaskLWord; |
| 9369 | if(power_Q & BIT(15)) |
| 9370 | power_Q |= bMaskHWord; |
| 9371 | |
| 9372 | DPK_DEBUG("0x%x = 0x%x power_I = 0x%x power_Q = 0x%x\n", offset[path][5], tmpReg, power_I, power_Q); |
| 9373 | |
| 9374 | tmpReg = power_I*power_I + power_Q*power_Q; |
| 9375 | |
| 9376 | DPK_DEBUG("gain loss = 0x%x \n", tmpReg); |
| 9377 | |
| 9378 | if(tmpReg < 26090) |
| 9379 | { |
| 9380 | phy_set_bb_reg(priv, offset[path][2], bMaskDWord, 0x01017098); //0xb00, 0xb70 |
| 9381 | phy_set_bb_reg(priv, offset[path][8], bMaskDWord, 0x28080000); //0xb68, 0xb6c |
| 9382 | |
| 9383 | for(i = 3; i < DP_RF_REG_NUM; i++) |
| 9384 | phy_set_rf_reg(priv, path, RF_REG[i], bMask20Bits, RF_backup[path][i]); |
| 9385 | priv->pshare->bDPKdone[path] = FALSE; |
| 9386 | //set original DPK bias table |
| 9387 | for(j = 0; j < DP_PA_BIAS_NUM; j++) |
| 9388 | phy_set_rf_reg(priv, path, RF_TXBIAS, bMask20Bits, RF_PA_BIAS[2][j]); |
| 9389 | |
| 9390 | continue; |
| 9391 | } |
| 9392 | else |
| 9393 | { |
| 9394 | priv->pshare->bDPKdone[path] = TRUE; |
| 9395 | priv->pshare->bDPKstore = TRUE; |
| 9396 | } |
| 9397 | |
| 9398 | for(i = 0; i < DP_GAIN_LOSS_BOUND_NUM; i++) |
| 9399 | { |
| 9400 | #if DP_gain_loss == 1 |
| 9401 | if(tmpReg > gain_loss_bound[i]/* || i == (DP_GAIN_LOSS_BOUND_NUM -1)*/) |
| 9402 | #else |
| 9403 | if(tmpReg > gain_loss_bound[i] || i == (DP_GAIN_LOSS_BOUND_NUM -1)) |
| 9404 | #endif |
| 9405 | { |
| 9406 | #if DP_gain_loss == 0 |
| 9407 | if(i == 0) |
| 9408 | break; |
| 9409 | |
| 9410 | index = OFDM_index[path] > i?OFDM_index[path]-i:0; |
| 9411 | if(index < OFDM_min_index_internalPA) |
| 9412 | index = OFDM_min_index_internalPA; |
| 9413 | phy_set_bb_reg(priv, offset[path][6], bMaskDWord, ofdm_swing_table[index]); //0xc80, 0xc88 |
| 9414 | DPK_DEBUG("original index 0x%x gain_loss minus index 0x%x\n", priv->pshare->OFDM_index[0], i); |
| 9415 | #endif |
| 9416 | break; |
| 9417 | } |
| 9418 | } |
| 9419 | |
| 9420 | #if DP_gain_loss == 1 |
| 9421 | |
| 9422 | DPK_DEBUG("gain_loss Compensated coefficient %d\n", gain_loss_coef[i]); |
| 9423 | coef = gain_loss_coef[i]; |
| 9424 | GainLossIndex = i; |
| 9425 | priv->pshare->OFDM_min_index_internalPA_DPK[path] = GainLossIndex == 0?0:(GainLossIndex/2+GainLossIndex%2); |
| 9426 | |
| 9427 | //read DP LUT value from register |
| 9428 | for(i = 0; i < DP_PA_MODEL_RUN_NUM; i++) |
| 9429 | { |
| 9430 | phy_set_bb_reg(priv, offset[path][2], bMaskDWord, 0x00297018+i); //0xb00, 0xb70 |
| 9431 | for(index = 0; index < DP_PA_MODEL_PER_RUN_NUM; index++) |
| 9432 | { |
| 9433 | tmpReg = (i == 0 && index==0)?0x01000000:phy_query_bb_reg(priv, offset[path][3]+index*4, bMaskDWord); //0xbdc, 0xbec |
| 9434 | |
| 9435 | gain_loss_backup[1][i*4+index] = (tmpReg >> 16); //I |
| 9436 | if(gain_loss_backup[1][i*4+index] & BIT(15)) |
| 9437 | gain_loss_backup[1][i*4+index] |= bMaskHWord; |
| 9438 | |
| 9439 | gain_loss_backup[0][i*4+index] = (tmpReg & bMaskLWord); //Q |
| 9440 | if(gain_loss_backup[0][i*4+index] & BIT(15)) |
| 9441 | gain_loss_backup[0][i*4+index] |= bMaskHWord; |
| 9442 | DPK_DEBUG("==>DP LUT index %d value 0x%x() I = 0x%x, Q = 0x%x\n", i*4+index, tmpReg, gain_loss_backup[1][i*4+index], gain_loss_backup[0][i*4+index]); |
| 9443 | |
| 9444 | //gain * LUT |
| 9445 | for(j = 0; j < 2; j++) |
| 9446 | { |
| 9447 | // RTPRINT(FINIT, INIT_IQK, ("==>0DP LUT sram %s index %d value %d()\n", j == 0?"Q":"I", i*4+index, gain_loss_backup[j][i*4+index])); |
| 9448 | |
| 9449 | gain_loss_backup[j][i*4+index] = (gain_loss_backup[j][i*4+index] * coef) / (int)(512); |
| 9450 | // RTPRINT(FINIT, INIT_IQK, ("==>1DP LUT sram %s index %d value 0x%x()\n", j == 0?"Q":"I", i*4+index, gain_loss_backup[j][i*4+index])); |
| 9451 | |
| 9452 | gain_loss_backup[j][i*4+index] = gain_loss_backup[j][i*4+index] >= (int)(512)?(int)(511):gain_loss_backup[j][i*4+index] < (int)(-512)?(int)(-512):gain_loss_backup[j][i*4+index]; |
| 9453 | // RTPRINT(FINIT, INIT_IQK, ("==>2DP LUT sram %s index %d value 0x%x()\n", j == 0?"Q":"I", i*4+index, gain_loss_backup[j][i*4+index])); |
| 9454 | |
| 9455 | gain_loss_backup[j][i*4+index] = gain_loss_backup[j][i*4+index] >> 2; |
| 9456 | // RTPRINT(FINIT, INIT_IQK, ("==>3DP LUT sram %s index %d value 0x%x()\n", j == 0?"Q":"I", i*4+index, gain_loss_backup[j][i*4+index])); |
| 9457 | |
| 9458 | } |
| 9459 | tmpReg = ((gain_loss_backup[1][i*4+index] & bMaskByte0) << 8 ) | ((gain_loss_backup[0][i*4+index] & bMaskByte0)); |
| 9460 | gain_loss_backup[0][i*4+index] = tmpReg & bMaskLWord; |
| 9461 | DPK_DEBUG("==>DP LUT sram index %d value 0x%x()\n", i*4+index, tmpReg); |
| 9462 | } |
| 9463 | } |
| 9464 | |
| 9465 | //write DP LUT into sram |
| 9466 | for(i = 0; i < DP_PA_MODEL_NUM; i++) |
| 9467 | { |
| 9468 | value32 = (path==RF_PATH_A?((i%2 == 0)?0x01000000:0x02000000): |
| 9469 | ((i%2 == 0)?0x04000000:0x08000000)) | |
| 9470 | gain_loss_backup[0][(DP_PA_MODEL_NUM-1)-i] |( (i/2) << 16); |
| 9471 | DPK_DEBUG("0xb2c value = 0x%x\n", value32); |
| 9472 | phy_set_bb_reg(priv, 0xb2c , bMaskDWord, value32); |
| 9473 | } |
| 9474 | // phy_set_bb_reg(priv, 0xb2c , bMaskDWord, 0x00000000); |
| 9475 | |
| 9476 | #endif |
| 9477 | |
| 9478 | #endif |
| 9479 | |
| 9480 | /////////////////////////////////////////////////////////////// |
| 9481 | // step 5: Enable Digital Predistortion |
| 9482 | /////////////////////////////////////////////////////////////// |
| 9483 | // LUT from sram |
| 9484 | #if DP_gain_loss == 1 |
| 9485 | { |
| 9486 | _PHY_SetADDARegisters(priv, BB_REG_loop[path], BB_settings_loop_dp, DP_BB_REG_NUM_loop_pa); |
| 9487 | |
| 9488 | // pwsf boundary |
| 9489 | phy_set_bb_reg(priv, offset[path][7], bMaskDWord, 0x000fffff); //0xb30, 0xba0 |
| 9490 | |
| 9491 | // write pwsf to sram |
| 9492 | //find tx_index index value |
| 9493 | SramIndex = 24; //restore default value |
| 9494 | SramIndex -= GainLossIndex; |
| 9495 | if(bPlus3db) |
| 9496 | SramIndex += 3*4; |
| 9497 | |
| 9498 | SramIndex = SramIndex >= DP_SRAM_NUM_db?DP_SRAM_NUM_db-1:(SramIndex<0?0:SramIndex); |
| 9499 | |
| 9500 | DPK_DEBUG("tx_index = 0x%x, sram value 0x%x gainloss index %d bPlus3db %d\n", tx_index, Sram_db_settings[SramIndex], GainLossIndex, bPlus3db); |
| 9501 | |
| 9502 | index = 0x1f - tx_index; |
| 9503 | if(SramIndex >= index*4) |
| 9504 | { |
| 9505 | index = SramIndex - index*4; |
| 9506 | index_repeat = -2; |
| 9507 | SramIndex = -2; |
| 9508 | } |
| 9509 | else |
| 9510 | { |
| 9511 | index_repeat = index - SramIndex/4; |
| 9512 | SramIndex %= 4; |
| 9513 | index = 0; |
| 9514 | } |
| 9515 | |
| 9516 | index = index >= DP_SRAM_NUM_db?DP_SRAM_NUM_db-1:index; |
| 9517 | if(index_repeat == 1) |
| 9518 | index_1 = SramIndex; |
| 9519 | else |
| 9520 | index_1 = index < (DP_SRAM_NUM_db-1)?(index_repeat==-2?index+1*4:index):index; |
| 9521 | |
| 9522 | DPK_DEBUG("0x1f value = 0x%x, index 0x%x repeat %d SramIndex %d\n", Sram_db_settings[index], index, index_repeat, SramIndex); |
| 9523 | |
| 9524 | for(i = 0; i < DP_SRAM_NUM; i++) |
| 9525 | { |
| 9526 | value32 = (path==RF_PATH_A?0x10000000:0x20000000) | (i << 16) | |
| 9527 | (Sram_db_settings[index_1] << 8 )| Sram_db_settings[index]; |
| 9528 | DPK_DEBUG("0xb2c value = 0x%x\n", value32); |
| 9529 | |
| 9530 | phy_set_bb_reg(priv, 0xb2c , bMaskDWord, value32); |
| 9531 | if(index_repeat >= 0) |
| 9532 | index_repeat -= 2; |
| 9533 | else if(index_repeat == -1) |
| 9534 | index_repeat = -2; |
| 9535 | |
| 9536 | if((index < (DP_SRAM_NUM_db-1)-1)) |
| 9537 | { |
| 9538 | if(index_repeat == -2) |
| 9539 | { |
| 9540 | index+=2*4; |
| 9541 | index_1 = index < (DP_SRAM_NUM_db-1)?index+1*4:index; |
| 9542 | } |
| 9543 | if(index_repeat == 0) |
| 9544 | { |
| 9545 | index = SramIndex; |
| 9546 | index_1 = index < (DP_SRAM_NUM_db-1)?index+1*4:index; |
| 9547 | } |
| 9548 | else if(index_repeat == 1) |
| 9549 | { |
| 9550 | index_1 = SramIndex; |
| 9551 | } |
| 9552 | else if(index_repeat == -1) |
| 9553 | { |
| 9554 | index = index_1+1*4; |
| 9555 | index_1 = index < (DP_SRAM_NUM_db-1)?index+1*4:index; |
| 9556 | } |
| 9557 | } |
| 9558 | else |
| 9559 | { |
| 9560 | index = index_1 = (DP_SRAM_NUM_db-1); |
| 9561 | } |
| 9562 | |
| 9563 | index = index < DP_SRAM_NUM_db?index:DP_SRAM_NUM_db-1; |
| 9564 | index_1 = index_1 < DP_SRAM_NUM_db?index_1:DP_SRAM_NUM_db-1; |
| 9565 | } |
| 9566 | } |
| 9567 | #else |
| 9568 | if(!SkipStep5) |
| 9569 | { |
| 9570 | _PHY_SetADDARegisters(priv, BB_REG_loop[path], BB_settings_loop_dp, DP_BB_REG_NUM_loop_pa); |
| 9571 | |
| 9572 | // pwsf boundary |
| 9573 | phy_set_bb_reg(priv, offset[path][7], bMaskDWord, 0x000fffff); //0xb30, 0xba0 |
| 9574 | |
| 9575 | // write pwsf to sram |
| 9576 | //find RF0x1f index value |
| 9577 | if(bPlus3db) |
| 9578 | tx_index += 3; |
| 9579 | |
| 9580 | // tx_index = 0x21; |
| 9581 | |
| 9582 | index = 0x1f - tx_index; |
| 9583 | if(index_for_zero_db >= index) |
| 9584 | { |
| 9585 | index = index_for_zero_db - index; |
| 9586 | index_repeat = -2; |
| 9587 | } |
| 9588 | else |
| 9589 | { |
| 9590 | index_repeat = index - index_for_zero_db; |
| 9591 | index = 0; |
| 9592 | } |
| 9593 | |
| 9594 | index = index >= DP_SRAM_NUM_db?DP_SRAM_NUM_db-1:index; |
| 9595 | index_1 = index < (DP_SRAM_NUM_db-1)?(index_repeat==-2?index+1:index):index; |
| 9596 | |
| 9597 | DPK_DEBUG("0x1f value = 0x%x, index 0x%x repeat %d\n", Sram_db_settings[index], index, index_repeat); |
| 9598 | |
| 9599 | for(i = 0; i < DP_SRAM_NUM; i++) |
| 9600 | { |
| 9601 | value32 = (path==RF_PATH_A?0x10000000:0x20000000) | (i << 16) | |
| 9602 | (Sram_db_settings[index_1] << 8 )| Sram_db_settings[index]; |
| 9603 | DPK_DEBUG("0xb2c value = 0x%x\n", value32); |
| 9604 | |
| 9605 | phy_set_bb_reg(priv, 0xb2c , bMaskDWord, value32); |
| 9606 | if(index_repeat >= 0) |
| 9607 | index_repeat -= 2; |
| 9608 | else if(index_repeat == -1) |
| 9609 | index_repeat = -2; |
| 9610 | |
| 9611 | if((index < (DP_SRAM_NUM_db-1)-1)) |
| 9612 | { |
| 9613 | if(index_repeat == -2) |
| 9614 | { |
| 9615 | index += 2; |
| 9616 | index_1 = index < (DP_SRAM_NUM_db-1)?index+1:index; |
| 9617 | } |
| 9618 | if(index_repeat == 0) |
| 9619 | { |
| 9620 | index_1 = index < (DP_SRAM_NUM_db-1)?index+1:index; |
| 9621 | } |
| 9622 | else if(index_repeat == -1) |
| 9623 | { |
| 9624 | index++; |
| 9625 | index_1 = index < (DP_SRAM_NUM_db-1)?index+1:index; |
| 9626 | } |
| 9627 | } |
| 9628 | else |
| 9629 | { |
| 9630 | index = index_1 = (DP_SRAM_NUM_db-1); |
| 9631 | } |
| 9632 | } |
| 9633 | } |
| 9634 | #endif |
| 9635 | } |
| 9636 | |
| 9637 | //reload RF default value |
| 9638 | for(path = 0; path<path_num; path++){ |
| 9639 | for( i = 2 ; i < 3 ; i++){ |
| 9640 | phy_set_rf_reg(priv, path, RF_REG[i], bMask20Bits, RF_backup[path][i]); |
| 9641 | } |
| 9642 | } |
| 9643 | |
| 9644 | //Reload standby mode default value (if path B excute DPK) |
| 9645 | if(is2T && priv->pshare->phw->InternalPA5G[RF_PATH_B]) |
| 9646 | { |
| 9647 | phy_set_rf_reg(priv, RF_PATH_A, RF_MODE1, bMask20Bits, 0x1000f); |
| 9648 | phy_set_rf_reg(priv, RF_PATH_A, RF_MODE2, bMask20Bits, 0x60101); |
| 9649 | } |
| 9650 | |
| 9651 | //reload BB default value |
| 9652 | for(index=0; index<DP_BB_REG_NUM; index++) |
| 9653 | phy_set_bb_reg(priv, BB_REG[index], bMaskDWord, BB_backup[index]); |
| 9654 | |
| 9655 | //external LNA on |
| 9656 | phy_set_bb_reg(priv, rBndA, 0xF00000, 0x00); |
| 9657 | |
| 9658 | if(is2T) |
| 9659 | phy_set_bb_reg(priv, rBndB, 0xF00000, 0x00); |
| 9660 | |
| 9661 | //Reload path A BB default value |
| 9662 | _phy_reload_adda_registers(priv, BB_REG_A, BB_backup_A, DP_BB_REG_NUM_A); |
| 9663 | |
| 9664 | |
| 9665 | #if 1 //Return to Rx mode after dpk |
| 9666 | //printk("BB_REG_A[9] 0x%x BB_backup_A[9] 0x%x\n\n", BB_REG_A[9], BB_backup_A[9]); |
| 9667 | phy_set_bb_reg(priv, BB_REG_A[9], bMaskByte0, 0x50); |
| 9668 | phy_set_bb_reg(priv, BB_REG_A[9], bMaskDWord, BB_backup_A[9]); |
| 9669 | #endif |
| 9670 | |
| 9671 | //Reload path B default value |
| 9672 | if(is2T) |
| 9673 | _phy_reload_adda_registers(priv, BB_REG_B, BB_backup_B, DP_BB_REG_NUM_B); |
| 9674 | |
| 9675 | #if 1 //Return to Rx mode after dpk |
| 9676 | //printk("BB_REG_B[8] 0x%x BB_backup_B[8] 0x%x\n\n", BB_REG_B[8], BB_backup_B[8]); |
| 9677 | phy_set_bb_reg(priv, BB_REG_B[8], bMaskByte0, 0x50); |
| 9678 | phy_set_bb_reg(priv, BB_REG_B[8], bMaskDWord, BB_backup_B[8]); |
| 9679 | #endif |
| 9680 | |
| 9681 | //reload AFE default value |
| 9682 | _phy_reload_adda_registers(priv, AFE_REG, AFE_backup, IQK_ADDA_REG_NUM); |
| 9683 | |
| 9684 | //reload MAC default value |
| 9685 | _phy_reload_mac_registers(priv, MAC_REG, MAC_backup); |
| 9686 | |
| 9687 | priv->pshare->bDPKworking = FALSE; |
| 9688 | |
| 9689 | DPK_DEBUG("<==_PHY_DigitalPredistortion()\n"); |
| 9690 | } |
| 9691 | |
| 9692 | #endif |
| 9693 | #endif |
| 9694 | |
| 9695 | #endif |