Yan-Hsuan Chuang | e303748 | 2019-04-26 15:17:37 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause |
| 2 | /* Copyright(c) 2018-2019 Realtek Corporation |
| 3 | */ |
| 4 | |
| 5 | #include "main.h" |
| 6 | #include "fw.h" |
| 7 | #include "tx.h" |
| 8 | #include "rx.h" |
| 9 | #include "phy.h" |
| 10 | #include "rtw8822c.h" |
| 11 | #include "rtw8822c_table.h" |
| 12 | #include "mac.h" |
| 13 | #include "reg.h" |
| 14 | #include "debug.h" |
| 15 | |
| 16 | static void rtw8822c_config_trx_mode(struct rtw_dev *rtwdev, u8 tx_path, |
| 17 | u8 rx_path, bool is_tx2_path); |
| 18 | |
| 19 | static void rtw8822ce_efuse_parsing(struct rtw_efuse *efuse, |
| 20 | struct rtw8822c_efuse *map) |
| 21 | { |
| 22 | ether_addr_copy(efuse->addr, map->e.mac_addr); |
| 23 | } |
| 24 | |
| 25 | static int rtw8822c_read_efuse(struct rtw_dev *rtwdev, u8 *log_map) |
| 26 | { |
| 27 | struct rtw_efuse *efuse = &rtwdev->efuse; |
| 28 | struct rtw8822c_efuse *map; |
| 29 | int i; |
| 30 | |
| 31 | map = (struct rtw8822c_efuse *)log_map; |
| 32 | |
| 33 | efuse->rfe_option = map->rfe_option; |
| 34 | efuse->crystal_cap = map->xtal_k; |
| 35 | efuse->channel_plan = map->channel_plan; |
| 36 | efuse->country_code[0] = map->country_code[0]; |
| 37 | efuse->country_code[1] = map->country_code[1]; |
| 38 | efuse->bt_setting = map->rf_bt_setting; |
| 39 | efuse->regd = map->rf_board_option & 0x7; |
| 40 | |
| 41 | for (i = 0; i < 4; i++) |
| 42 | efuse->txpwr_idx_table[i] = map->txpwr_idx_table[i]; |
| 43 | |
| 44 | switch (rtw_hci_type(rtwdev)) { |
| 45 | case RTW_HCI_TYPE_PCIE: |
| 46 | rtw8822ce_efuse_parsing(efuse, map); |
| 47 | break; |
| 48 | default: |
| 49 | /* unsupported now */ |
| 50 | return -ENOTSUPP; |
| 51 | } |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | static void rtw8822c_header_file_init(struct rtw_dev *rtwdev, bool pre) |
| 57 | { |
| 58 | rtw_write32_set(rtwdev, REG_3WIRE, BIT_3WIRE_TX_EN | BIT_3WIRE_RX_EN); |
| 59 | rtw_write32_set(rtwdev, REG_3WIRE, BIT_3WIRE_PI_ON); |
| 60 | rtw_write32_set(rtwdev, REG_3WIRE2, BIT_3WIRE_TX_EN | BIT_3WIRE_RX_EN); |
| 61 | rtw_write32_set(rtwdev, REG_3WIRE2, BIT_3WIRE_PI_ON); |
| 62 | |
| 63 | if (pre) |
| 64 | rtw_write32_clr(rtwdev, REG_ENCCK, BIT_CCK_OFDM_BLK_EN); |
| 65 | else |
| 66 | rtw_write32_set(rtwdev, REG_ENCCK, BIT_CCK_OFDM_BLK_EN); |
| 67 | } |
| 68 | |
| 69 | static void rtw8822c_dac_backup_reg(struct rtw_dev *rtwdev, |
| 70 | struct rtw_backup_info *backup, |
| 71 | struct rtw_backup_info *backup_rf) |
| 72 | { |
| 73 | u32 path, i; |
| 74 | u32 val; |
| 75 | u32 reg; |
| 76 | u32 rf_addr[DACK_RF_8822C] = {0x8f}; |
| 77 | u32 addrs[DACK_REG_8822C] = {0x180c, 0x1810, 0x410c, 0x4110, |
| 78 | 0x1c3c, 0x1c24, 0x1d70, 0x9b4, |
| 79 | 0x1a00, 0x1a14, 0x1d58, 0x1c38, |
| 80 | 0x1e24, 0x1e28, 0x1860, 0x4160}; |
| 81 | |
| 82 | for (i = 0; i < DACK_REG_8822C; i++) { |
| 83 | backup[i].len = 4; |
| 84 | backup[i].reg = addrs[i]; |
| 85 | backup[i].val = rtw_read32(rtwdev, addrs[i]); |
| 86 | } |
| 87 | |
| 88 | for (path = 0; path < DACK_PATH_8822C; path++) { |
| 89 | for (i = 0; i < DACK_RF_8822C; i++) { |
| 90 | reg = rf_addr[i]; |
| 91 | val = rtw_read_rf(rtwdev, path, reg, RFREG_MASK); |
| 92 | backup_rf[path * i + i].reg = reg; |
| 93 | backup_rf[path * i + i].val = val; |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | static void rtw8822c_dac_restore_reg(struct rtw_dev *rtwdev, |
| 99 | struct rtw_backup_info *backup, |
| 100 | struct rtw_backup_info *backup_rf) |
| 101 | { |
| 102 | u32 path, i; |
| 103 | u32 val; |
| 104 | u32 reg; |
| 105 | |
| 106 | rtw_restore_reg(rtwdev, backup, DACK_REG_8822C); |
| 107 | |
| 108 | for (path = 0; path < DACK_PATH_8822C; path++) { |
| 109 | for (i = 0; i < DACK_RF_8822C; i++) { |
| 110 | val = backup_rf[path * i + i].val; |
| 111 | reg = backup_rf[path * i + i].reg; |
| 112 | rtw_write_rf(rtwdev, path, reg, RFREG_MASK, val); |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | static void rtw8822c_rf_minmax_cmp(struct rtw_dev *rtwdev, u32 value, |
| 118 | u32 *min, u32 *max) |
| 119 | { |
| 120 | if (value >= 0x200) { |
| 121 | if (*min >= 0x200) { |
| 122 | if (*min > value) |
| 123 | *min = value; |
| 124 | } else { |
| 125 | *min = value; |
| 126 | } |
| 127 | if (*max >= 0x200) { |
| 128 | if (*max < value) |
| 129 | *max = value; |
| 130 | } |
| 131 | } else { |
| 132 | if (*min < 0x200) { |
| 133 | if (*min > value) |
| 134 | *min = value; |
| 135 | } |
| 136 | |
| 137 | if (*max >= 0x200) { |
| 138 | *max = value; |
| 139 | } else { |
| 140 | if (*max < value) |
| 141 | *max = value; |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | static void swap_u32(u32 *v1, u32 *v2) |
| 147 | { |
| 148 | u32 tmp; |
| 149 | |
| 150 | tmp = *v1; |
| 151 | *v1 = *v2; |
| 152 | *v2 = tmp; |
| 153 | } |
| 154 | |
| 155 | static void __rtw8822c_dac_iq_sort(struct rtw_dev *rtwdev, u32 *v1, u32 *v2) |
| 156 | { |
| 157 | if (*v1 >= 0x200 && *v2 >= 0x200) { |
| 158 | if (*v1 > *v2) |
| 159 | swap_u32(v1, v2); |
| 160 | } else if (*v1 < 0x200 && *v2 < 0x200) { |
| 161 | if (*v1 > *v2) |
| 162 | swap_u32(v1, v2); |
| 163 | } else if (*v1 < 0x200 && *v2 >= 0x200) { |
| 164 | swap_u32(v1, v2); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | static void rtw8822c_dac_iq_sort(struct rtw_dev *rtwdev, u32 *iv, u32 *qv) |
| 169 | { |
| 170 | u32 i, j; |
| 171 | |
| 172 | for (i = 0; i < DACK_SN_8822C - 1; i++) { |
| 173 | for (j = 0; j < (DACK_SN_8822C - 1 - i) ; j++) { |
| 174 | __rtw8822c_dac_iq_sort(rtwdev, &iv[j], &iv[j + 1]); |
| 175 | __rtw8822c_dac_iq_sort(rtwdev, &qv[j], &qv[j + 1]); |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | static void rtw8822c_dac_iq_offset(struct rtw_dev *rtwdev, u32 *vec, u32 *val) |
| 181 | { |
| 182 | u32 p, m, t, i; |
| 183 | |
| 184 | m = 0; |
| 185 | p = 0; |
| 186 | for (i = 10; i < DACK_SN_8822C - 10; i++) { |
| 187 | if (vec[i] > 0x200) |
| 188 | m = (0x400 - vec[i]) + m; |
| 189 | else |
| 190 | p = vec[i] + p; |
| 191 | } |
| 192 | |
| 193 | if (p > m) { |
| 194 | t = p - m; |
| 195 | t = t / (DACK_SN_8822C - 20); |
| 196 | } else { |
| 197 | t = m - p; |
| 198 | t = t / (DACK_SN_8822C - 20); |
| 199 | if (t != 0x0) |
| 200 | t = 0x400 - t; |
| 201 | } |
| 202 | |
| 203 | *val = t; |
| 204 | } |
| 205 | |
| 206 | static u32 rtw8822c_get_path_base_addr(u8 path) |
| 207 | { |
| 208 | u32 base_addr; |
| 209 | |
| 210 | switch (path) { |
| 211 | case RF_PATH_A: |
| 212 | base_addr = 0x1800; |
| 213 | break; |
| 214 | case RF_PATH_B: |
| 215 | base_addr = 0x4100; |
| 216 | break; |
| 217 | default: |
| 218 | WARN_ON(1); |
| 219 | return -1; |
| 220 | } |
| 221 | |
| 222 | return base_addr; |
| 223 | } |
| 224 | |
| 225 | static bool rtw8822c_dac_iq_check(struct rtw_dev *rtwdev, u32 value) |
| 226 | { |
| 227 | bool ret = true; |
| 228 | |
| 229 | if ((value >= 0x200 && (0x400 - value) > 0x64) || |
| 230 | (value < 0x200 && value > 0x64)) { |
| 231 | ret = false; |
| 232 | rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] Error overflow\n"); |
| 233 | } |
| 234 | |
| 235 | return ret; |
| 236 | } |
| 237 | |
| 238 | static void rtw8822c_dac_cal_iq_sample(struct rtw_dev *rtwdev, u32 *iv, u32 *qv) |
| 239 | { |
| 240 | u32 temp; |
| 241 | int i = 0, cnt = 0; |
| 242 | |
| 243 | while (i < DACK_SN_8822C && cnt < 10000) { |
| 244 | cnt++; |
| 245 | temp = rtw_read32_mask(rtwdev, 0x2dbc, 0x3fffff); |
| 246 | iv[i] = (temp & 0x3ff000) >> 12; |
| 247 | qv[i] = temp & 0x3ff; |
| 248 | |
| 249 | if (rtw8822c_dac_iq_check(rtwdev, iv[i]) && |
| 250 | rtw8822c_dac_iq_check(rtwdev, qv[i])) |
| 251 | i++; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | static void rtw8822c_dac_cal_iq_search(struct rtw_dev *rtwdev, |
| 256 | u32 *iv, u32 *qv, |
| 257 | u32 *i_value, u32 *q_value) |
| 258 | { |
| 259 | u32 i_max = 0, q_max = 0, i_min = 0, q_min = 0; |
| 260 | u32 i_delta, q_delta; |
| 261 | u32 temp; |
| 262 | int i, cnt = 0; |
| 263 | |
| 264 | do { |
| 265 | i_min = iv[0]; |
| 266 | i_max = iv[0]; |
| 267 | q_min = qv[0]; |
| 268 | q_max = qv[0]; |
| 269 | for (i = 0; i < DACK_SN_8822C; i++) { |
| 270 | rtw8822c_rf_minmax_cmp(rtwdev, iv[i], &i_min, &i_max); |
| 271 | rtw8822c_rf_minmax_cmp(rtwdev, qv[i], &q_min, &q_max); |
| 272 | } |
| 273 | |
| 274 | if (i_max < 0x200 && i_min < 0x200) |
| 275 | i_delta = i_max - i_min; |
| 276 | else if (i_max >= 0x200 && i_min >= 0x200) |
| 277 | i_delta = i_max - i_min; |
| 278 | else |
| 279 | i_delta = i_max + (0x400 - i_min); |
| 280 | |
| 281 | if (q_max < 0x200 && q_min < 0x200) |
| 282 | q_delta = q_max - q_min; |
| 283 | else if (q_max >= 0x200 && q_min >= 0x200) |
| 284 | q_delta = q_max - q_min; |
| 285 | else |
| 286 | q_delta = q_max + (0x400 - q_min); |
| 287 | |
| 288 | rtw_dbg(rtwdev, RTW_DBG_RFK, |
| 289 | "[DACK] i: min=0x%08x, max=0x%08x, delta=0x%08x\n", |
| 290 | i_min, i_max, i_delta); |
| 291 | rtw_dbg(rtwdev, RTW_DBG_RFK, |
| 292 | "[DACK] q: min=0x%08x, max=0x%08x, delta=0x%08x\n", |
| 293 | q_min, q_max, q_delta); |
| 294 | |
| 295 | rtw8822c_dac_iq_sort(rtwdev, iv, qv); |
| 296 | |
| 297 | if (i_delta > 5 || q_delta > 5) { |
| 298 | temp = rtw_read32_mask(rtwdev, 0x2dbc, 0x3fffff); |
| 299 | iv[0] = (temp & 0x3ff000) >> 12; |
| 300 | qv[0] = temp & 0x3ff; |
| 301 | temp = rtw_read32_mask(rtwdev, 0x2dbc, 0x3fffff); |
| 302 | iv[DACK_SN_8822C - 1] = (temp & 0x3ff000) >> 12; |
| 303 | qv[DACK_SN_8822C - 1] = temp & 0x3ff; |
| 304 | } else { |
| 305 | break; |
| 306 | } |
| 307 | } while (cnt++ < 100); |
| 308 | |
| 309 | rtw8822c_dac_iq_offset(rtwdev, iv, i_value); |
| 310 | rtw8822c_dac_iq_offset(rtwdev, qv, q_value); |
| 311 | } |
| 312 | |
| 313 | static void rtw8822c_dac_cal_rf_mode(struct rtw_dev *rtwdev, |
| 314 | u32 *i_value, u32 *q_value) |
| 315 | { |
| 316 | u32 iv[DACK_SN_8822C], qv[DACK_SN_8822C]; |
| 317 | u32 rf_a, rf_b; |
| 318 | |
| 319 | mdelay(10); |
| 320 | |
| 321 | rf_a = rtw_read_rf(rtwdev, RF_PATH_A, 0x0, RFREG_MASK); |
| 322 | rf_b = rtw_read_rf(rtwdev, RF_PATH_B, 0x0, RFREG_MASK); |
| 323 | |
| 324 | rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] RF path-A=0x%05x\n", rf_a); |
| 325 | rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] RF path-B=0x%05x\n", rf_b); |
| 326 | |
| 327 | rtw8822c_dac_cal_iq_sample(rtwdev, iv, qv); |
| 328 | rtw8822c_dac_cal_iq_search(rtwdev, iv, qv, i_value, q_value); |
| 329 | } |
| 330 | |
| 331 | static void rtw8822c_dac_bb_setting(struct rtw_dev *rtwdev) |
| 332 | { |
| 333 | rtw_write32_mask(rtwdev, 0x1d58, 0xff8, 0x1ff); |
| 334 | rtw_write32_mask(rtwdev, 0x1a00, 0x3, 0x2); |
| 335 | rtw_write32_mask(rtwdev, 0x1a14, 0x300, 0x3); |
| 336 | rtw_write32(rtwdev, 0x1d70, 0x7e7e7e7e); |
| 337 | rtw_write32_mask(rtwdev, 0x180c, 0x3, 0x0); |
| 338 | rtw_write32_mask(rtwdev, 0x410c, 0x3, 0x0); |
| 339 | rtw_write32(rtwdev, 0x1b00, 0x00000008); |
| 340 | rtw_write8(rtwdev, 0x1bcc, 0x3f); |
| 341 | rtw_write32(rtwdev, 0x1b00, 0x0000000a); |
| 342 | rtw_write8(rtwdev, 0x1bcc, 0x3f); |
| 343 | rtw_write32_mask(rtwdev, 0x1e24, BIT(31), 0x0); |
| 344 | rtw_write32_mask(rtwdev, 0x1e28, 0xf, 0x3); |
| 345 | } |
| 346 | |
| 347 | static void rtw8822c_dac_cal_adc(struct rtw_dev *rtwdev, |
| 348 | u8 path, u32 *adc_ic, u32 *adc_qc) |
| 349 | { |
| 350 | u32 ic = 0, qc = 0, temp = 0; |
| 351 | u32 base_addr; |
| 352 | u32 path_sel; |
| 353 | int i; |
| 354 | |
| 355 | rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] ADCK path(%d)\n", path); |
| 356 | |
| 357 | base_addr = rtw8822c_get_path_base_addr(path); |
| 358 | switch (path) { |
| 359 | case RF_PATH_A: |
| 360 | path_sel = 0xa0000; |
| 361 | break; |
| 362 | case RF_PATH_B: |
| 363 | path_sel = 0x80000; |
| 364 | break; |
| 365 | default: |
| 366 | WARN_ON(1); |
| 367 | return; |
| 368 | } |
| 369 | |
| 370 | /* ADCK step1 */ |
| 371 | rtw_write32_mask(rtwdev, base_addr + 0x30, BIT(30), 0x0); |
| 372 | if (path == RF_PATH_B) |
| 373 | rtw_write32(rtwdev, base_addr + 0x30, 0x30db8041); |
| 374 | rtw_write32(rtwdev, base_addr + 0x60, 0xf0040ff0); |
| 375 | rtw_write32(rtwdev, base_addr + 0x0c, 0xdff00220); |
| 376 | rtw_write32(rtwdev, base_addr + 0x10, 0x02dd08c4); |
| 377 | rtw_write32(rtwdev, base_addr + 0x0c, 0x10000260); |
| 378 | rtw_write_rf(rtwdev, RF_PATH_A, 0x0, RFREG_MASK, 0x10000); |
| 379 | rtw_write_rf(rtwdev, RF_PATH_B, 0x0, RFREG_MASK, 0x10000); |
| 380 | for (i = 0; i < 10; i++) { |
| 381 | rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] ADCK count=%d\n", i); |
| 382 | rtw_write32(rtwdev, 0x1c3c, path_sel + 0x8003); |
| 383 | rtw_write32(rtwdev, 0x1c24, 0x00010002); |
| 384 | rtw8822c_dac_cal_rf_mode(rtwdev, &ic, &qc); |
| 385 | rtw_dbg(rtwdev, RTW_DBG_RFK, |
| 386 | "[DACK] before: i=0x%x, q=0x%x\n", ic, qc); |
| 387 | |
| 388 | /* compensation value */ |
| 389 | if (ic != 0x0) { |
| 390 | ic = 0x400 - ic; |
| 391 | *adc_ic = ic; |
| 392 | } |
| 393 | if (qc != 0x0) { |
| 394 | qc = 0x400 - qc; |
| 395 | *adc_qc = qc; |
| 396 | } |
| 397 | temp = (ic & 0x3ff) | ((qc & 0x3ff) << 10); |
| 398 | rtw_write32(rtwdev, base_addr + 0x68, temp); |
| 399 | rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] ADCK 0x%08x=0x08%x\n", |
| 400 | base_addr + 0x68, temp); |
| 401 | /* check ADC DC offset */ |
| 402 | rtw_write32(rtwdev, 0x1c3c, path_sel + 0x8103); |
| 403 | rtw8822c_dac_cal_rf_mode(rtwdev, &ic, &qc); |
| 404 | rtw_dbg(rtwdev, RTW_DBG_RFK, |
| 405 | "[DACK] after: i=0x%08x, q=0x%08x\n", ic, qc); |
| 406 | if (ic >= 0x200) |
| 407 | ic = 0x400 - ic; |
| 408 | if (qc >= 0x200) |
| 409 | qc = 0x400 - qc; |
| 410 | if (ic < 5 && qc < 5) |
| 411 | break; |
| 412 | } |
| 413 | |
| 414 | /* ADCK step2 */ |
| 415 | rtw_write32(rtwdev, 0x1c3c, 0x00000003); |
| 416 | rtw_write32(rtwdev, base_addr + 0x0c, 0x10000260); |
| 417 | rtw_write32(rtwdev, base_addr + 0x10, 0x02d508c4); |
| 418 | |
| 419 | /* release pull low switch on IQ path */ |
| 420 | rtw_write_rf(rtwdev, path, 0x8f, BIT(13), 0x1); |
| 421 | } |
| 422 | |
| 423 | static void rtw8822c_dac_cal_step1(struct rtw_dev *rtwdev, u8 path) |
| 424 | { |
| 425 | u32 base_addr; |
| 426 | |
| 427 | base_addr = rtw8822c_get_path_base_addr(path); |
| 428 | |
| 429 | rtw_write32(rtwdev, base_addr + 0x0c, 0xdff00220); |
| 430 | if (path == RF_PATH_A) { |
| 431 | rtw_write32(rtwdev, base_addr + 0x60, 0xf0040ff0); |
| 432 | rtw_write32(rtwdev, 0x1c38, 0xffffffff); |
| 433 | } |
| 434 | rtw_write32(rtwdev, base_addr + 0x10, 0x02d508c5); |
| 435 | rtw_write32(rtwdev, 0x9b4, 0xdb66db00); |
| 436 | rtw_write32(rtwdev, base_addr + 0xb0, 0x0a11fb88); |
| 437 | rtw_write32(rtwdev, base_addr + 0xbc, 0x0008ff81); |
| 438 | rtw_write32(rtwdev, base_addr + 0xc0, 0x0003d208); |
| 439 | rtw_write32(rtwdev, base_addr + 0xcc, 0x0a11fb88); |
| 440 | rtw_write32(rtwdev, base_addr + 0xd8, 0x0008ff81); |
| 441 | rtw_write32(rtwdev, base_addr + 0xdc, 0x0003d208); |
| 442 | rtw_write32(rtwdev, base_addr + 0xb8, 0x60000000); |
| 443 | mdelay(2); |
| 444 | rtw_write32(rtwdev, base_addr + 0xbc, 0x000aff8d); |
| 445 | mdelay(2); |
| 446 | rtw_write32(rtwdev, base_addr + 0xb0, 0x0a11fb89); |
| 447 | rtw_write32(rtwdev, base_addr + 0xcc, 0x0a11fb89); |
| 448 | mdelay(1); |
| 449 | rtw_write32(rtwdev, base_addr + 0xb8, 0x62000000); |
| 450 | mdelay(20); |
| 451 | rtw_write32(rtwdev, base_addr + 0xd4, 0x62000000); |
| 452 | mdelay(20); |
| 453 | rtw_write32(rtwdev, base_addr + 0xb8, 0x02000000); |
| 454 | mdelay(20); |
| 455 | rtw_write32(rtwdev, base_addr + 0xbc, 0x0008ff87); |
| 456 | rtw_write32(rtwdev, 0x9b4, 0xdb6db600); |
| 457 | rtw_write32(rtwdev, base_addr + 0x10, 0x02d508c5); |
| 458 | rtw_write32(rtwdev, base_addr + 0xbc, 0x0008ff87); |
| 459 | rtw_write32(rtwdev, base_addr + 0x60, 0xf0000000); |
| 460 | } |
| 461 | |
| 462 | static void rtw8822c_dac_cal_step2(struct rtw_dev *rtwdev, |
| 463 | u8 path, u32 *ic_out, u32 *qc_out) |
| 464 | { |
| 465 | u32 base_addr; |
| 466 | u32 ic, qc, ic_in, qc_in; |
| 467 | |
| 468 | base_addr = rtw8822c_get_path_base_addr(path); |
| 469 | rtw_write32_mask(rtwdev, base_addr + 0xbc, 0xf0000000, 0x0); |
| 470 | rtw_write32_mask(rtwdev, base_addr + 0xc0, 0xf, 0x8); |
| 471 | rtw_write32_mask(rtwdev, base_addr + 0xd8, 0xf0000000, 0x0); |
| 472 | rtw_write32_mask(rtwdev, base_addr + 0xdc, 0xf, 0x8); |
| 473 | |
| 474 | rtw_write32(rtwdev, 0x1b00, 0x00000008); |
| 475 | rtw_write8(rtwdev, 0x1bcc, 0x03f); |
| 476 | rtw_write32(rtwdev, base_addr + 0x0c, 0xdff00220); |
| 477 | rtw_write32(rtwdev, base_addr + 0x10, 0x02d508c5); |
| 478 | rtw_write32(rtwdev, 0x1c3c, 0x00088103); |
| 479 | |
| 480 | rtw8822c_dac_cal_rf_mode(rtwdev, &ic_in, &qc_in); |
| 481 | ic = ic_in; |
| 482 | qc = qc_in; |
| 483 | |
| 484 | /* compensation value */ |
| 485 | if (ic != 0x0) |
| 486 | ic = 0x400 - ic; |
| 487 | if (qc != 0x0) |
| 488 | qc = 0x400 - qc; |
| 489 | if (ic < 0x300) { |
| 490 | ic = ic * 2 * 6 / 5; |
| 491 | ic = ic + 0x80; |
| 492 | } else { |
| 493 | ic = (0x400 - ic) * 2 * 6 / 5; |
| 494 | ic = 0x7f - ic; |
| 495 | } |
| 496 | if (qc < 0x300) { |
| 497 | qc = qc * 2 * 6 / 5; |
| 498 | qc = qc + 0x80; |
| 499 | } else { |
| 500 | qc = (0x400 - qc) * 2 * 6 / 5; |
| 501 | qc = 0x7f - qc; |
| 502 | } |
| 503 | |
| 504 | *ic_out = ic; |
| 505 | *qc_out = qc; |
| 506 | |
| 507 | rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] before i=0x%x, q=0x%x\n", ic_in, qc_in); |
| 508 | rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] after i=0x%x, q=0x%x\n", ic, qc); |
| 509 | } |
| 510 | |
| 511 | static void rtw8822c_dac_cal_step3(struct rtw_dev *rtwdev, u8 path, |
| 512 | u32 adc_ic, u32 adc_qc, |
| 513 | u32 *ic_in, u32 *qc_in, |
| 514 | u32 *i_out, u32 *q_out) |
| 515 | { |
| 516 | u32 base_addr; |
| 517 | u32 ic, qc; |
| 518 | u32 temp; |
| 519 | |
| 520 | base_addr = rtw8822c_get_path_base_addr(path); |
| 521 | ic = *ic_in; |
| 522 | qc = *qc_in; |
| 523 | |
| 524 | rtw_write32(rtwdev, base_addr + 0x0c, 0xdff00220); |
| 525 | rtw_write32(rtwdev, base_addr + 0x10, 0x02d508c5); |
| 526 | rtw_write32(rtwdev, 0x9b4, 0xdb66db00); |
| 527 | rtw_write32(rtwdev, base_addr + 0xb0, 0x0a11fb88); |
| 528 | rtw_write32(rtwdev, base_addr + 0xbc, 0xc008ff81); |
| 529 | rtw_write32(rtwdev, base_addr + 0xc0, 0x0003d208); |
| 530 | rtw_write32_mask(rtwdev, base_addr + 0xbc, 0xf0000000, ic & 0xf); |
| 531 | rtw_write32_mask(rtwdev, base_addr + 0xc0, 0xf, (ic & 0xf0) >> 4); |
| 532 | rtw_write32(rtwdev, base_addr + 0xcc, 0x0a11fb88); |
| 533 | rtw_write32(rtwdev, base_addr + 0xd8, 0xe008ff81); |
| 534 | rtw_write32(rtwdev, base_addr + 0xdc, 0x0003d208); |
| 535 | rtw_write32_mask(rtwdev, base_addr + 0xd8, 0xf0000000, qc & 0xf); |
| 536 | rtw_write32_mask(rtwdev, base_addr + 0xdc, 0xf, (qc & 0xf0) >> 4); |
| 537 | rtw_write32(rtwdev, base_addr + 0xb8, 0x60000000); |
| 538 | mdelay(2); |
| 539 | rtw_write32_mask(rtwdev, base_addr + 0xbc, 0xe, 0x6); |
| 540 | mdelay(2); |
| 541 | rtw_write32(rtwdev, base_addr + 0xb0, 0x0a11fb89); |
| 542 | rtw_write32(rtwdev, base_addr + 0xcc, 0x0a11fb89); |
| 543 | mdelay(1); |
| 544 | rtw_write32(rtwdev, base_addr + 0xb8, 0x62000000); |
| 545 | mdelay(20); |
| 546 | rtw_write32(rtwdev, base_addr + 0xd4, 0x62000000); |
| 547 | mdelay(20); |
| 548 | rtw_write32(rtwdev, base_addr + 0xb8, 0x02000000); |
| 549 | mdelay(20); |
| 550 | rtw_write32_mask(rtwdev, base_addr + 0xbc, 0xe, 0x3); |
| 551 | rtw_write32(rtwdev, 0x9b4, 0xdb6db600); |
| 552 | |
| 553 | /* check DAC DC offset */ |
| 554 | temp = ((adc_ic + 0x10) & 0x3ff) | (((adc_qc + 0x10) & 0x3ff) << 10); |
| 555 | rtw_write32(rtwdev, base_addr + 0x68, temp); |
| 556 | rtw_write32(rtwdev, base_addr + 0x10, 0x02d508c5); |
| 557 | rtw_write32(rtwdev, base_addr + 0x60, 0xf0000000); |
| 558 | rtw8822c_dac_cal_rf_mode(rtwdev, &ic, &qc); |
| 559 | if (ic >= 0x10) |
| 560 | ic = ic - 0x10; |
| 561 | else |
| 562 | ic = 0x400 - (0x10 - ic); |
| 563 | |
| 564 | if (qc >= 0x10) |
| 565 | qc = qc - 0x10; |
| 566 | else |
| 567 | qc = 0x400 - (0x10 - qc); |
| 568 | |
| 569 | *i_out = ic; |
| 570 | *q_out = qc; |
| 571 | |
| 572 | if (ic >= 0x200) |
| 573 | ic = 0x400 - ic; |
| 574 | if (qc >= 0x200) |
| 575 | qc = 0x400 - qc; |
| 576 | |
| 577 | *ic_in = ic; |
| 578 | *qc_in = qc; |
| 579 | |
| 580 | rtw_dbg(rtwdev, RTW_DBG_RFK, |
| 581 | "[DACK] after DACK i=0x%x, q=0x%x\n", *i_out, *q_out); |
| 582 | } |
| 583 | |
| 584 | static void rtw8822c_dac_cal_step4(struct rtw_dev *rtwdev, u8 path) |
| 585 | { |
| 586 | u32 base_addr = rtw8822c_get_path_base_addr(path); |
| 587 | |
| 588 | rtw_write32(rtwdev, base_addr + 0x68, 0x0); |
| 589 | rtw_write32(rtwdev, base_addr + 0x10, 0x02d508c4); |
| 590 | rtw_write32_mask(rtwdev, base_addr + 0xbc, 0x1, 0x0); |
| 591 | rtw_write32_mask(rtwdev, base_addr + 0x30, BIT(30), 0x1); |
| 592 | } |
| 593 | |
| 594 | static void rtw8822c_rf_dac_cal(struct rtw_dev *rtwdev) |
| 595 | { |
| 596 | struct rtw_backup_info backup_rf[DACK_RF_8822C * DACK_PATH_8822C]; |
| 597 | struct rtw_backup_info backup[DACK_REG_8822C]; |
| 598 | u32 ic = 0, qc = 0, i; |
| 599 | u32 i_a = 0x0, q_a = 0x0, i_b = 0x0, q_b = 0x0; |
| 600 | u32 ic_a = 0x0, qc_a = 0x0, ic_b = 0x0, qc_b = 0x0; |
| 601 | u32 adc_ic_a = 0x0, adc_qc_a = 0x0, adc_ic_b = 0x0, adc_qc_b = 0x0; |
| 602 | |
| 603 | rtw8822c_dac_backup_reg(rtwdev, backup, backup_rf); |
| 604 | |
| 605 | rtw8822c_dac_bb_setting(rtwdev); |
| 606 | |
| 607 | /* path-A */ |
| 608 | rtw8822c_dac_cal_adc(rtwdev, RF_PATH_A, &adc_ic_a, &adc_qc_a); |
| 609 | for (i = 0; i < 10; i++) { |
| 610 | rtw8822c_dac_cal_step1(rtwdev, RF_PATH_A); |
| 611 | rtw8822c_dac_cal_step2(rtwdev, RF_PATH_A, &ic, &qc); |
| 612 | ic_a = ic; |
| 613 | qc_a = qc; |
| 614 | |
| 615 | rtw8822c_dac_cal_step3(rtwdev, RF_PATH_A, adc_ic_a, adc_qc_a, |
| 616 | &ic, &qc, &i_a, &q_a); |
| 617 | |
| 618 | if (ic < 5 && qc < 5) |
| 619 | break; |
| 620 | } |
| 621 | rtw8822c_dac_cal_step4(rtwdev, RF_PATH_A); |
| 622 | |
| 623 | /* path-B */ |
| 624 | rtw8822c_dac_cal_adc(rtwdev, RF_PATH_B, &adc_ic_b, &adc_qc_b); |
| 625 | for (i = 0; i < 10; i++) { |
| 626 | rtw8822c_dac_cal_step1(rtwdev, RF_PATH_B); |
| 627 | rtw8822c_dac_cal_step2(rtwdev, RF_PATH_B, &ic, &qc); |
| 628 | ic_b = ic; |
| 629 | qc_b = qc; |
| 630 | |
| 631 | rtw8822c_dac_cal_step3(rtwdev, RF_PATH_B, adc_ic_b, adc_qc_b, |
| 632 | &ic, &qc, &i_b, &q_b); |
| 633 | |
| 634 | if (ic < 5 && qc < 5) |
| 635 | break; |
| 636 | } |
| 637 | rtw8822c_dac_cal_step4(rtwdev, RF_PATH_B); |
| 638 | |
| 639 | rtw_write32(rtwdev, 0x1b00, 0x00000008); |
| 640 | rtw_write32_mask(rtwdev, 0x4130, BIT(30), 0x1); |
| 641 | rtw_write8(rtwdev, 0x1bcc, 0x0); |
| 642 | rtw_write32(rtwdev, 0x1b00, 0x0000000a); |
| 643 | rtw_write8(rtwdev, 0x1bcc, 0x0); |
| 644 | |
| 645 | rtw8822c_dac_restore_reg(rtwdev, backup, backup_rf); |
| 646 | |
| 647 | rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] path A: ic=0x%x, qc=0x%x\n", ic_a, qc_a); |
| 648 | rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] path B: ic=0x%x, qc=0x%x\n", ic_b, qc_b); |
| 649 | rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] path A: i=0x%x, q=0x%x\n", i_a, q_a); |
| 650 | rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] path B: i=0x%x, q=0x%x\n", i_b, q_b); |
| 651 | } |
| 652 | |
| 653 | static void rtw8822c_rf_x2_check(struct rtw_dev *rtwdev) |
| 654 | { |
| 655 | u8 x2k_busy; |
| 656 | |
| 657 | mdelay(1); |
| 658 | x2k_busy = rtw_read_rf(rtwdev, RF_PATH_A, 0xb8, BIT(15)); |
| 659 | if (x2k_busy == 1) { |
| 660 | rtw_write_rf(rtwdev, RF_PATH_A, 0xb8, RFREG_MASK, 0xC4440); |
| 661 | rtw_write_rf(rtwdev, RF_PATH_A, 0xba, RFREG_MASK, 0x6840D); |
| 662 | rtw_write_rf(rtwdev, RF_PATH_A, 0xb8, RFREG_MASK, 0x80440); |
| 663 | mdelay(1); |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | static void rtw8822c_rf_init(struct rtw_dev *rtwdev) |
| 668 | { |
| 669 | rtw8822c_rf_dac_cal(rtwdev); |
| 670 | rtw8822c_rf_x2_check(rtwdev); |
| 671 | } |
| 672 | |
| 673 | static void rtw8822c_phy_set_param(struct rtw_dev *rtwdev) |
| 674 | { |
| 675 | struct rtw_dm_info *dm_info = &rtwdev->dm_info; |
| 676 | struct rtw_hal *hal = &rtwdev->hal; |
| 677 | u8 crystal_cap; |
| 678 | u8 cck_gi_u_bnd_msb = 0; |
| 679 | u8 cck_gi_u_bnd_lsb = 0; |
| 680 | u8 cck_gi_l_bnd_msb = 0; |
| 681 | u8 cck_gi_l_bnd_lsb = 0; |
| 682 | bool is_tx2_path; |
| 683 | |
| 684 | /* power on BB/RF domain */ |
| 685 | rtw_write8_set(rtwdev, REG_SYS_FUNC_EN, |
| 686 | BIT_FEN_BB_GLB_RST | BIT_FEN_BB_RSTB); |
| 687 | rtw_write8_set(rtwdev, REG_RF_CTRL, |
| 688 | BIT_RF_EN | BIT_RF_RSTB | BIT_RF_SDM_RSTB); |
| 689 | rtw_write32_set(rtwdev, REG_WLRF1, BIT_WLRF1_BBRF_EN); |
| 690 | |
| 691 | /* pre init before header files config */ |
| 692 | rtw8822c_header_file_init(rtwdev, true); |
| 693 | |
| 694 | rtw_phy_load_tables(rtwdev); |
| 695 | |
| 696 | crystal_cap = rtwdev->efuse.crystal_cap & 0x7f; |
| 697 | rtw_write32_mask(rtwdev, REG_ANAPAR_XTAL_0, 0xfffc00, |
| 698 | crystal_cap | (crystal_cap << 7)); |
| 699 | |
| 700 | /* post init after header files config */ |
| 701 | rtw8822c_header_file_init(rtwdev, false); |
| 702 | |
| 703 | is_tx2_path = false; |
| 704 | rtw8822c_config_trx_mode(rtwdev, hal->antenna_tx, hal->antenna_rx, |
| 705 | is_tx2_path); |
| 706 | rtw_phy_init(rtwdev); |
| 707 | |
| 708 | cck_gi_u_bnd_msb = (u8)rtw_read32_mask(rtwdev, 0x1a98, 0xc000); |
| 709 | cck_gi_u_bnd_lsb = (u8)rtw_read32_mask(rtwdev, 0x1aa8, 0xf0000); |
| 710 | cck_gi_l_bnd_msb = (u8)rtw_read32_mask(rtwdev, 0x1a98, 0xc0); |
| 711 | cck_gi_l_bnd_lsb = (u8)rtw_read32_mask(rtwdev, 0x1a70, 0x0f000000); |
| 712 | |
| 713 | dm_info->cck_gi_u_bnd = ((cck_gi_u_bnd_msb << 4) | (cck_gi_u_bnd_lsb)); |
| 714 | dm_info->cck_gi_l_bnd = ((cck_gi_l_bnd_msb << 4) | (cck_gi_l_bnd_lsb)); |
| 715 | |
| 716 | rtw8822c_rf_init(rtwdev); |
| 717 | /* wifi path controller */ |
| 718 | rtw_write32_mask(rtwdev, 0x70, 0xff000000, 0x0e); |
| 719 | rtw_write32_mask(rtwdev, 0x1704, 0xffffffff, 0x7700); |
| 720 | rtw_write32_mask(rtwdev, 0x1700, 0xffffffff, 0xc00f0038); |
| 721 | rtw_write32_mask(rtwdev, 0x6c0, 0xffffffff, 0xaaaaaaaa); |
| 722 | rtw_write32_mask(rtwdev, 0x6c4, 0xffffffff, 0xaaaaaaaa); |
| 723 | } |
| 724 | |
| 725 | #define WLAN_TXQ_RPT_EN 0x1F |
| 726 | #define WLAN_SLOT_TIME 0x09 |
| 727 | #define WLAN_PIFS_TIME 0x1C |
| 728 | #define WLAN_SIFS_CCK_CONT_TX 0x0A |
| 729 | #define WLAN_SIFS_OFDM_CONT_TX 0x0E |
| 730 | #define WLAN_SIFS_CCK_TRX 0x0A |
| 731 | #define WLAN_SIFS_OFDM_TRX 0x10 |
| 732 | #define WLAN_NAV_MAX 0xC8 |
| 733 | #define WLAN_RDG_NAV 0x05 |
| 734 | #define WLAN_TXOP_NAV 0x1B |
| 735 | #define WLAN_CCK_RX_TSF 0x30 |
| 736 | #define WLAN_OFDM_RX_TSF 0x30 |
| 737 | #define WLAN_TBTT_PROHIBIT 0x04 /* unit : 32us */ |
| 738 | #define WLAN_TBTT_HOLD_TIME 0x064 /* unit : 32us */ |
| 739 | #define WLAN_DRV_EARLY_INT 0x04 |
| 740 | #define WLAN_BCN_CTRL_CLT0 0x10 |
| 741 | #define WLAN_BCN_DMA_TIME 0x02 |
| 742 | #define WLAN_BCN_MAX_ERR 0xFF |
| 743 | #define WLAN_SIFS_CCK_DUR_TUNE 0x0A |
| 744 | #define WLAN_SIFS_OFDM_DUR_TUNE 0x10 |
| 745 | #define WLAN_SIFS_CCK_CTX 0x0A |
| 746 | #define WLAN_SIFS_CCK_IRX 0x0A |
| 747 | #define WLAN_SIFS_OFDM_CTX 0x0E |
| 748 | #define WLAN_SIFS_OFDM_IRX 0x0E |
| 749 | #define WLAN_EIFS_DUR_TUNE 0x40 |
| 750 | #define WLAN_EDCA_VO_PARAM 0x002FA226 |
| 751 | #define WLAN_EDCA_VI_PARAM 0x005EA328 |
| 752 | #define WLAN_EDCA_BE_PARAM 0x005EA42B |
| 753 | #define WLAN_EDCA_BK_PARAM 0x0000A44F |
| 754 | |
| 755 | #define WLAN_RX_FILTER0 0xFFFFFFFF |
| 756 | #define WLAN_RX_FILTER2 0xFFFF |
| 757 | #define WLAN_RCR_CFG 0xE400220E |
| 758 | #define WLAN_RXPKT_MAX_SZ 12288 |
| 759 | #define WLAN_RXPKT_MAX_SZ_512 (WLAN_RXPKT_MAX_SZ >> 9) |
| 760 | |
| 761 | #define WLAN_AMPDU_MAX_TIME 0x70 |
| 762 | #define WLAN_RTS_LEN_TH 0xFF |
| 763 | #define WLAN_RTS_TX_TIME_TH 0x08 |
| 764 | #define WLAN_MAX_AGG_PKT_LIMIT 0x20 |
| 765 | #define WLAN_RTS_MAX_AGG_PKT_LIMIT 0x20 |
| 766 | #define WLAN_PRE_TXCNT_TIME_TH 0x1E0 |
| 767 | #define FAST_EDCA_VO_TH 0x06 |
| 768 | #define FAST_EDCA_VI_TH 0x06 |
| 769 | #define FAST_EDCA_BE_TH 0x06 |
| 770 | #define FAST_EDCA_BK_TH 0x06 |
| 771 | #define WLAN_BAR_RETRY_LIMIT 0x01 |
| 772 | #define WLAN_BAR_ACK_TYPE 0x05 |
| 773 | #define WLAN_RA_TRY_RATE_AGG_LIMIT 0x08 |
| 774 | #define WLAN_RESP_TXRATE 0x84 |
| 775 | #define WLAN_ACK_TO 0x21 |
| 776 | #define WLAN_ACK_TO_CCK 0x6A |
| 777 | #define WLAN_DATA_RATE_FB_CNT_1_4 0x01000000 |
| 778 | #define WLAN_DATA_RATE_FB_CNT_5_8 0x08070504 |
| 779 | #define WLAN_RTS_RATE_FB_CNT_5_8 0x08070504 |
| 780 | #define WLAN_DATA_RATE_FB_RATE0 0xFE01F010 |
| 781 | #define WLAN_DATA_RATE_FB_RATE0_H 0x40000000 |
| 782 | #define WLAN_RTS_RATE_FB_RATE1 0x003FF010 |
| 783 | #define WLAN_RTS_RATE_FB_RATE1_H 0x40000000 |
| 784 | #define WLAN_RTS_RATE_FB_RATE4 0x0600F010 |
| 785 | #define WLAN_RTS_RATE_FB_RATE4_H 0x400003E0 |
| 786 | #define WLAN_RTS_RATE_FB_RATE5 0x0600F015 |
| 787 | #define WLAN_RTS_RATE_FB_RATE5_H 0x000000E0 |
| 788 | |
| 789 | #define WLAN_TX_FUNC_CFG1 0x30 |
| 790 | #define WLAN_TX_FUNC_CFG2 0x30 |
| 791 | #define WLAN_MAC_OPT_NORM_FUNC1 0x98 |
| 792 | #define WLAN_MAC_OPT_LB_FUNC1 0x80 |
| 793 | #define WLAN_MAC_OPT_FUNC2 0x30810041 |
| 794 | |
| 795 | #define WLAN_SIFS_CFG (WLAN_SIFS_CCK_CONT_TX | \ |
| 796 | (WLAN_SIFS_OFDM_CONT_TX << BIT_SHIFT_SIFS_OFDM_CTX) | \ |
| 797 | (WLAN_SIFS_CCK_TRX << BIT_SHIFT_SIFS_CCK_TRX) | \ |
| 798 | (WLAN_SIFS_OFDM_TRX << BIT_SHIFT_SIFS_OFDM_TRX)) |
| 799 | |
| 800 | #define WLAN_SIFS_DUR_TUNE (WLAN_SIFS_CCK_DUR_TUNE | \ |
| 801 | (WLAN_SIFS_OFDM_DUR_TUNE << 8)) |
| 802 | |
| 803 | #define WLAN_TBTT_TIME (WLAN_TBTT_PROHIBIT |\ |
| 804 | (WLAN_TBTT_HOLD_TIME << BIT_SHIFT_TBTT_HOLD_TIME_AP)) |
| 805 | |
| 806 | #define WLAN_NAV_CFG (WLAN_RDG_NAV | (WLAN_TXOP_NAV << 16)) |
| 807 | #define WLAN_RX_TSF_CFG (WLAN_CCK_RX_TSF | (WLAN_OFDM_RX_TSF) << 8) |
| 808 | |
| 809 | #define MAC_CLK_SPEED 80 /* 80M */ |
| 810 | #define EFUSE_PCB_INFO_OFFSET 0xCA |
| 811 | |
| 812 | static int rtw8822c_mac_init(struct rtw_dev *rtwdev) |
| 813 | { |
| 814 | u8 value8; |
| 815 | u16 value16; |
| 816 | u32 value32; |
| 817 | u16 pre_txcnt; |
| 818 | |
| 819 | /* txq control */ |
| 820 | value8 = rtw_read8(rtwdev, REG_FWHW_TXQ_CTRL); |
| 821 | value8 |= (BIT(7) & ~BIT(1) & ~BIT(2)); |
| 822 | rtw_write8(rtwdev, REG_FWHW_TXQ_CTRL, value8); |
| 823 | rtw_write8(rtwdev, REG_FWHW_TXQ_CTRL + 1, WLAN_TXQ_RPT_EN); |
| 824 | /* sifs control */ |
| 825 | rtw_write16(rtwdev, REG_SPEC_SIFS, WLAN_SIFS_DUR_TUNE); |
| 826 | rtw_write32(rtwdev, REG_SIFS, WLAN_SIFS_CFG); |
| 827 | rtw_write16(rtwdev, REG_RESP_SIFS_CCK, |
| 828 | WLAN_SIFS_CCK_CTX | WLAN_SIFS_CCK_IRX << 8); |
| 829 | rtw_write16(rtwdev, REG_RESP_SIFS_OFDM, |
| 830 | WLAN_SIFS_OFDM_CTX | WLAN_SIFS_OFDM_IRX << 8); |
| 831 | /* rate fallback control */ |
| 832 | rtw_write32(rtwdev, REG_DARFRC, WLAN_DATA_RATE_FB_CNT_1_4); |
| 833 | rtw_write32(rtwdev, REG_DARFRCH, WLAN_DATA_RATE_FB_CNT_5_8); |
| 834 | rtw_write32(rtwdev, REG_RARFRCH, WLAN_RTS_RATE_FB_CNT_5_8); |
| 835 | rtw_write32(rtwdev, REG_ARFR0, WLAN_DATA_RATE_FB_RATE0); |
| 836 | rtw_write32(rtwdev, REG_ARFRH0, WLAN_DATA_RATE_FB_RATE0_H); |
| 837 | rtw_write32(rtwdev, REG_ARFR1_V1, WLAN_RTS_RATE_FB_RATE1); |
| 838 | rtw_write32(rtwdev, REG_ARFRH1_V1, WLAN_RTS_RATE_FB_RATE1_H); |
| 839 | rtw_write32(rtwdev, REG_ARFR4, WLAN_RTS_RATE_FB_RATE4); |
| 840 | rtw_write32(rtwdev, REG_ARFRH4, WLAN_RTS_RATE_FB_RATE4_H); |
| 841 | rtw_write32(rtwdev, REG_ARFR5, WLAN_RTS_RATE_FB_RATE5); |
| 842 | rtw_write32(rtwdev, REG_ARFRH5, WLAN_RTS_RATE_FB_RATE5_H); |
| 843 | /* protocol configuration */ |
| 844 | rtw_write8(rtwdev, REG_AMPDU_MAX_TIME_V1, WLAN_AMPDU_MAX_TIME); |
| 845 | rtw_write8_set(rtwdev, REG_TX_HANG_CTRL, BIT_EN_EOF_V1); |
| 846 | pre_txcnt = WLAN_PRE_TXCNT_TIME_TH | BIT_EN_PRECNT; |
| 847 | rtw_write8(rtwdev, REG_PRECNT_CTRL, (u8)(pre_txcnt & 0xFF)); |
| 848 | rtw_write8(rtwdev, REG_PRECNT_CTRL + 1, (u8)(pre_txcnt >> 8)); |
| 849 | value32 = WLAN_RTS_LEN_TH | (WLAN_RTS_TX_TIME_TH << 8) | |
| 850 | (WLAN_MAX_AGG_PKT_LIMIT << 16) | |
| 851 | (WLAN_RTS_MAX_AGG_PKT_LIMIT << 24); |
| 852 | rtw_write32(rtwdev, REG_PROT_MODE_CTRL, value32); |
| 853 | rtw_write16(rtwdev, REG_BAR_MODE_CTRL + 2, |
| 854 | WLAN_BAR_RETRY_LIMIT | WLAN_RA_TRY_RATE_AGG_LIMIT << 8); |
| 855 | rtw_write8(rtwdev, REG_FAST_EDCA_VOVI_SETTING, FAST_EDCA_VO_TH); |
| 856 | rtw_write8(rtwdev, REG_FAST_EDCA_VOVI_SETTING + 2, FAST_EDCA_VI_TH); |
| 857 | rtw_write8(rtwdev, REG_FAST_EDCA_BEBK_SETTING, FAST_EDCA_BE_TH); |
| 858 | rtw_write8(rtwdev, REG_FAST_EDCA_BEBK_SETTING + 2, FAST_EDCA_BK_TH); |
| 859 | /* close BA parser */ |
| 860 | rtw_write8_clr(rtwdev, REG_LIFETIME_EN, BIT_BA_PARSER_EN); |
| 861 | rtw_write32_clr(rtwdev, REG_RRSR, BITS_RRSR_RSC); |
| 862 | |
| 863 | /* EDCA configuration */ |
| 864 | rtw_write32(rtwdev, REG_EDCA_VO_PARAM, WLAN_EDCA_VO_PARAM); |
| 865 | rtw_write32(rtwdev, REG_EDCA_VI_PARAM, WLAN_EDCA_VI_PARAM); |
| 866 | rtw_write32(rtwdev, REG_EDCA_BE_PARAM, WLAN_EDCA_BE_PARAM); |
| 867 | rtw_write32(rtwdev, REG_EDCA_BK_PARAM, WLAN_EDCA_BK_PARAM); |
| 868 | rtw_write8(rtwdev, REG_PIFS, WLAN_PIFS_TIME); |
| 869 | rtw_write8_clr(rtwdev, REG_TX_PTCL_CTRL + 1, BIT_SIFS_BK_EN >> 8); |
| 870 | rtw_write8_set(rtwdev, REG_RD_CTRL + 1, |
| 871 | (BIT_DIS_TXOP_CFE | BIT_DIS_LSIG_CFE | |
| 872 | BIT_DIS_STBC_CFE) >> 8); |
| 873 | |
| 874 | /* MAC clock configuration */ |
| 875 | rtw_write32_clr(rtwdev, REG_AFE_CTRL1, BIT_MAC_CLK_SEL); |
| 876 | rtw_write8(rtwdev, REG_USTIME_TSF, MAC_CLK_SPEED); |
| 877 | rtw_write8(rtwdev, REG_USTIME_EDCA, MAC_CLK_SPEED); |
| 878 | |
| 879 | rtw_write8_set(rtwdev, REG_MISC_CTRL, |
| 880 | BIT_EN_FREE_CNT | BIT_DIS_SECOND_CCA); |
| 881 | rtw_write8_clr(rtwdev, REG_TIMER0_SRC_SEL, BIT_TSFT_SEL_TIMER0); |
| 882 | rtw_write16(rtwdev, REG_TXPAUSE, 0x0000); |
| 883 | rtw_write8(rtwdev, REG_SLOT, WLAN_SLOT_TIME); |
| 884 | rtw_write32(rtwdev, REG_RD_NAV_NXT, WLAN_NAV_CFG); |
| 885 | rtw_write16(rtwdev, REG_RXTSF_OFFSET_CCK, WLAN_RX_TSF_CFG); |
| 886 | /* Set beacon cotnrol - enable TSF and other related functions */ |
| 887 | rtw_write8_set(rtwdev, REG_BCN_CTRL, BIT_EN_BCN_FUNCTION); |
| 888 | /* Set send beacon related registers */ |
| 889 | rtw_write32(rtwdev, REG_TBTT_PROHIBIT, WLAN_TBTT_TIME); |
| 890 | rtw_write8(rtwdev, REG_DRVERLYINT, WLAN_DRV_EARLY_INT); |
| 891 | rtw_write8(rtwdev, REG_BCN_CTRL_CLINT0, WLAN_BCN_CTRL_CLT0); |
| 892 | rtw_write8(rtwdev, REG_BCNDMATIM, WLAN_BCN_DMA_TIME); |
| 893 | rtw_write8(rtwdev, REG_BCN_MAX_ERR, WLAN_BCN_MAX_ERR); |
| 894 | |
| 895 | /* WMAC configuration */ |
| 896 | rtw_write8(rtwdev, REG_BBPSF_CTRL + 2, WLAN_RESP_TXRATE); |
| 897 | rtw_write8(rtwdev, REG_ACKTO, WLAN_ACK_TO); |
| 898 | rtw_write8(rtwdev, REG_ACKTO_CCK, WLAN_ACK_TO_CCK); |
| 899 | rtw_write16(rtwdev, REG_EIFS, WLAN_EIFS_DUR_TUNE); |
| 900 | rtw_write8(rtwdev, REG_NAV_CTRL + 2, WLAN_NAV_MAX); |
| 901 | rtw_write8(rtwdev, REG_WMAC_TRXPTCL_CTL_H + 2, WLAN_BAR_ACK_TYPE); |
| 902 | rtw_write32(rtwdev, REG_RXFLTMAP0, WLAN_RX_FILTER0); |
| 903 | rtw_write16(rtwdev, REG_RXFLTMAP2, WLAN_RX_FILTER2); |
| 904 | rtw_write32(rtwdev, REG_RCR, WLAN_RCR_CFG); |
| 905 | rtw_write8(rtwdev, REG_RX_PKT_LIMIT, WLAN_RXPKT_MAX_SZ_512); |
| 906 | rtw_write8(rtwdev, REG_TCR + 2, WLAN_TX_FUNC_CFG2); |
| 907 | rtw_write8(rtwdev, REG_TCR + 1, WLAN_TX_FUNC_CFG1); |
| 908 | rtw_write32_set(rtwdev, REG_GENERAL_OPTION, BIT_DUMMY_FCS_READY_MASK_EN); |
| 909 | rtw_write32(rtwdev, REG_WMAC_OPTION_FUNCTION + 8, WLAN_MAC_OPT_FUNC2); |
| 910 | rtw_write8(rtwdev, REG_WMAC_OPTION_FUNCTION_1, WLAN_MAC_OPT_NORM_FUNC1); |
| 911 | |
| 912 | /* init low power */ |
| 913 | value16 = rtw_read16(rtwdev, REG_RXPSF_CTRL + 2) & 0xF00F; |
| 914 | value16 |= (BIT_RXGCK_VHT_FIFOTHR(1) | BIT_RXGCK_HT_FIFOTHR(1) | |
| 915 | BIT_RXGCK_OFDM_FIFOTHR(1) | BIT_RXGCK_CCK_FIFOTHR(1)) >> 16; |
| 916 | rtw_write16(rtwdev, REG_RXPSF_CTRL + 2, value16); |
| 917 | value16 = 0; |
| 918 | value16 = BIT_SET_RXPSF_PKTLENTHR(value16, 1); |
| 919 | value16 |= BIT_RXPSF_CTRLEN | BIT_RXPSF_VHTCHKEN | BIT_RXPSF_HTCHKEN |
| 920 | | BIT_RXPSF_OFDMCHKEN | BIT_RXPSF_CCKCHKEN |
| 921 | | BIT_RXPSF_OFDMRST; |
| 922 | rtw_write16(rtwdev, REG_RXPSF_CTRL, value16); |
| 923 | rtw_write32(rtwdev, REG_RXPSF_TYPE_CTRL, 0xFFFFFFFF); |
| 924 | /* rx ignore configuration */ |
| 925 | value16 = rtw_read16(rtwdev, REG_RXPSF_CTRL); |
| 926 | value16 &= ~(BIT_RXPSF_MHCHKEN | BIT_RXPSF_CCKRST | |
| 927 | BIT_RXPSF_CONT_ERRCHKEN); |
| 928 | value16 = BIT_SET_RXPSF_ERRTHR(value16, 0x07); |
| 929 | rtw_write16(rtwdev, REG_RXPSF_CTRL, value16); |
| 930 | |
| 931 | return 0; |
| 932 | } |
| 933 | |
| 934 | static void rtw8822c_set_channel_rf(struct rtw_dev *rtwdev, u8 channel, u8 bw) |
| 935 | { |
| 936 | #define RF18_BAND_MASK (BIT(16) | BIT(9) | BIT(8)) |
| 937 | #define RF18_BAND_2G (0) |
| 938 | #define RF18_BAND_5G (BIT(16) | BIT(8)) |
| 939 | #define RF18_CHANNEL_MASK (MASKBYTE0) |
| 940 | #define RF18_RFSI_MASK (BIT(18) | BIT(17)) |
| 941 | #define RF18_RFSI_GE_CH80 (BIT(17)) |
| 942 | #define RF18_RFSI_GT_CH140 (BIT(18)) |
| 943 | #define RF18_BW_MASK (BIT(13) | BIT(12)) |
| 944 | #define RF18_BW_20M (BIT(13) | BIT(12)) |
| 945 | #define RF18_BW_40M (BIT(13)) |
| 946 | #define RF18_BW_80M (BIT(12)) |
| 947 | |
| 948 | u32 rf_reg18 = 0; |
| 949 | u32 rf_rxbb = 0; |
| 950 | |
| 951 | rf_reg18 = rtw_read_rf(rtwdev, RF_PATH_A, 0x18, RFREG_MASK); |
| 952 | |
| 953 | rf_reg18 &= ~(RF18_BAND_MASK | RF18_CHANNEL_MASK | RF18_RFSI_MASK | |
| 954 | RF18_BW_MASK); |
| 955 | |
| 956 | rf_reg18 |= (channel <= 14 ? RF18_BAND_2G : RF18_BAND_5G); |
| 957 | rf_reg18 |= (channel & RF18_CHANNEL_MASK); |
| 958 | if (channel > 144) |
| 959 | rf_reg18 |= RF18_RFSI_GT_CH140; |
| 960 | else if (channel >= 80) |
| 961 | rf_reg18 |= RF18_RFSI_GE_CH80; |
| 962 | |
| 963 | switch (bw) { |
| 964 | case RTW_CHANNEL_WIDTH_5: |
| 965 | case RTW_CHANNEL_WIDTH_10: |
| 966 | case RTW_CHANNEL_WIDTH_20: |
| 967 | default: |
| 968 | rf_reg18 |= RF18_BW_20M; |
| 969 | rf_rxbb = 0x18; |
| 970 | break; |
| 971 | case RTW_CHANNEL_WIDTH_40: |
| 972 | /* RF bandwidth */ |
| 973 | rf_reg18 |= RF18_BW_40M; |
| 974 | rf_rxbb = 0x10; |
| 975 | break; |
| 976 | case RTW_CHANNEL_WIDTH_80: |
| 977 | rf_reg18 |= RF18_BW_80M; |
| 978 | rf_rxbb = 0x8; |
| 979 | break; |
| 980 | } |
| 981 | |
| 982 | rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWE2, 0x04, 0x01); |
| 983 | rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWA, 0x1f, 0x12); |
| 984 | rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWD0, 0xfffff, rf_rxbb); |
| 985 | rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWE2, 0x04, 0x00); |
| 986 | |
| 987 | rtw_write_rf(rtwdev, RF_PATH_B, RF_LUTWE2, 0x04, 0x01); |
| 988 | rtw_write_rf(rtwdev, RF_PATH_B, RF_LUTWA, 0x1f, 0x12); |
| 989 | rtw_write_rf(rtwdev, RF_PATH_B, RF_LUTWD0, 0xfffff, rf_rxbb); |
| 990 | rtw_write_rf(rtwdev, RF_PATH_B, RF_LUTWE2, 0x04, 0x00); |
| 991 | |
| 992 | rtw_write_rf(rtwdev, RF_PATH_A, RF_CFGCH, RFREG_MASK, rf_reg18); |
| 993 | rtw_write_rf(rtwdev, RF_PATH_B, RF_CFGCH, RFREG_MASK, rf_reg18); |
| 994 | } |
| 995 | |
| 996 | static void rtw8822c_toggle_igi(struct rtw_dev *rtwdev) |
| 997 | { |
| 998 | u32 igi; |
| 999 | |
| 1000 | igi = rtw_read32_mask(rtwdev, REG_RXIGI, 0x7f); |
| 1001 | rtw_write32_mask(rtwdev, REG_RXIGI, 0x7f, igi - 2); |
| 1002 | rtw_write32_mask(rtwdev, REG_RXIGI, 0x7f00, igi - 2); |
| 1003 | rtw_write32_mask(rtwdev, REG_RXIGI, 0x7f, igi); |
| 1004 | rtw_write32_mask(rtwdev, REG_RXIGI, 0x7f00, igi); |
| 1005 | } |
| 1006 | |
| 1007 | static void rtw8822c_set_channel_bb(struct rtw_dev *rtwdev, u8 channel, u8 bw, |
| 1008 | u8 primary_ch_idx) |
| 1009 | { |
| 1010 | if (channel <= 14) { |
| 1011 | rtw_write32_clr(rtwdev, REG_BGCTRL, BITS_RX_IQ_WEIGHT); |
| 1012 | rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0xf0000000, 0x8); |
| 1013 | rtw_write32_set(rtwdev, REG_TXF4, BIT(20)); |
| 1014 | rtw_write32_clr(rtwdev, REG_CCK_CHECK, BIT_CHECK_CCK_EN); |
| 1015 | rtw_write32_clr(rtwdev, REG_CCKTXONLY, BIT_BB_CCK_CHECK_EN); |
| 1016 | rtw_write32_mask(rtwdev, REG_CCAMSK, 0x3F000000, 0xF); |
| 1017 | |
Chien-Hsun Liao | f859e71 | 2019-06-14 15:24:09 +0800 | [diff] [blame^] | 1018 | switch (bw) { |
| 1019 | case RTW_CHANNEL_WIDTH_20: |
| 1020 | rtw_write32_mask(rtwdev, REG_RXAGCCTL0, BITS_RXAGC_CCK, |
| 1021 | 0x5); |
| 1022 | rtw_write32_mask(rtwdev, REG_RXAGCCTL, BITS_RXAGC_CCK, |
| 1023 | 0x5); |
| 1024 | rtw_write32_mask(rtwdev, REG_RXAGCCTL0, BITS_RXAGC_OFDM, |
| 1025 | 0x6); |
| 1026 | rtw_write32_mask(rtwdev, REG_RXAGCCTL, BITS_RXAGC_OFDM, |
| 1027 | 0x6); |
| 1028 | break; |
| 1029 | case RTW_CHANNEL_WIDTH_40: |
| 1030 | rtw_write32_mask(rtwdev, REG_RXAGCCTL0, BITS_RXAGC_CCK, |
| 1031 | 0x4); |
| 1032 | rtw_write32_mask(rtwdev, REG_RXAGCCTL, BITS_RXAGC_CCK, |
| 1033 | 0x4); |
| 1034 | rtw_write32_mask(rtwdev, REG_RXAGCCTL0, BITS_RXAGC_OFDM, |
| 1035 | 0x0); |
| 1036 | rtw_write32_mask(rtwdev, REG_RXAGCCTL, BITS_RXAGC_OFDM, |
| 1037 | 0x0); |
| 1038 | break; |
| 1039 | } |
Yan-Hsuan Chuang | e303748 | 2019-04-26 15:17:37 +0300 | [diff] [blame] | 1040 | if (channel == 13 || channel == 14) |
| 1041 | rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x969); |
| 1042 | else if (channel == 11 || channel == 12) |
| 1043 | rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x96a); |
| 1044 | else |
| 1045 | rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x9aa); |
| 1046 | if (channel == 14) { |
| 1047 | rtw_write32_mask(rtwdev, REG_TXF0, MASKHWORD, 0x3da0); |
| 1048 | rtw_write32_mask(rtwdev, REG_TXF1, MASKDWORD, |
| 1049 | 0x4962c931); |
| 1050 | rtw_write32_mask(rtwdev, REG_TXF2, MASKLWORD, 0x6aa3); |
| 1051 | rtw_write32_mask(rtwdev, REG_TXF3, MASKHWORD, 0xaa7b); |
| 1052 | rtw_write32_mask(rtwdev, REG_TXF4, MASKLWORD, 0xf3d7); |
| 1053 | rtw_write32_mask(rtwdev, REG_TXF5, MASKDWORD, 0x0); |
| 1054 | rtw_write32_mask(rtwdev, REG_TXF6, MASKDWORD, |
| 1055 | 0xff012455); |
| 1056 | rtw_write32_mask(rtwdev, REG_TXF7, MASKDWORD, 0xffff); |
| 1057 | } else { |
| 1058 | rtw_write32_mask(rtwdev, REG_TXF0, MASKHWORD, 0x5284); |
| 1059 | rtw_write32_mask(rtwdev, REG_TXF1, MASKDWORD, |
| 1060 | 0x3e18fec8); |
| 1061 | rtw_write32_mask(rtwdev, REG_TXF2, MASKLWORD, 0x0a88); |
| 1062 | rtw_write32_mask(rtwdev, REG_TXF3, MASKHWORD, 0xacc4); |
| 1063 | rtw_write32_mask(rtwdev, REG_TXF4, MASKLWORD, 0xc8b2); |
| 1064 | rtw_write32_mask(rtwdev, REG_TXF5, MASKDWORD, |
| 1065 | 0x00faf0de); |
| 1066 | rtw_write32_mask(rtwdev, REG_TXF6, MASKDWORD, |
| 1067 | 0x00122344); |
| 1068 | rtw_write32_mask(rtwdev, REG_TXF7, MASKDWORD, |
| 1069 | 0x0fffffff); |
| 1070 | } |
| 1071 | if (channel == 13) |
| 1072 | rtw_write32_mask(rtwdev, REG_TXDFIR0, 0x70, 0x3); |
| 1073 | else |
| 1074 | rtw_write32_mask(rtwdev, REG_TXDFIR0, 0x70, 0x1); |
| 1075 | } else if (channel > 35) { |
| 1076 | rtw_write32_set(rtwdev, REG_CCKTXONLY, BIT_BB_CCK_CHECK_EN); |
| 1077 | rtw_write32_set(rtwdev, REG_CCK_CHECK, BIT_CHECK_CCK_EN); |
| 1078 | rtw_write32_set(rtwdev, REG_BGCTRL, BITS_RX_IQ_WEIGHT); |
| 1079 | rtw_write32_clr(rtwdev, REG_TXF4, BIT(20)); |
| 1080 | rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0xf0000000, 0x0); |
| 1081 | rtw_write32_mask(rtwdev, REG_CCAMSK, 0x3F000000, 0x22); |
| 1082 | rtw_write32_mask(rtwdev, REG_TXDFIR0, 0x70, 0x3); |
| 1083 | if (channel >= 36 && channel <= 64) { |
Chien-Hsun Liao | f859e71 | 2019-06-14 15:24:09 +0800 | [diff] [blame^] | 1084 | rtw_write32_mask(rtwdev, REG_RXAGCCTL0, BITS_RXAGC_OFDM, |
| 1085 | 0x1); |
| 1086 | rtw_write32_mask(rtwdev, REG_RXAGCCTL, BITS_RXAGC_OFDM, |
| 1087 | 0x1); |
Yan-Hsuan Chuang | e303748 | 2019-04-26 15:17:37 +0300 | [diff] [blame] | 1088 | } else if (channel >= 100 && channel <= 144) { |
Chien-Hsun Liao | f859e71 | 2019-06-14 15:24:09 +0800 | [diff] [blame^] | 1089 | rtw_write32_mask(rtwdev, REG_RXAGCCTL0, BITS_RXAGC_OFDM, |
| 1090 | 0x2); |
| 1091 | rtw_write32_mask(rtwdev, REG_RXAGCCTL, BITS_RXAGC_OFDM, |
| 1092 | 0x2); |
Yan-Hsuan Chuang | e303748 | 2019-04-26 15:17:37 +0300 | [diff] [blame] | 1093 | } else if (channel >= 149) { |
Chien-Hsun Liao | f859e71 | 2019-06-14 15:24:09 +0800 | [diff] [blame^] | 1094 | rtw_write32_mask(rtwdev, REG_RXAGCCTL0, BITS_RXAGC_OFDM, |
| 1095 | 0x3); |
| 1096 | rtw_write32_mask(rtwdev, REG_RXAGCCTL, BITS_RXAGC_OFDM, |
| 1097 | 0x3); |
Yan-Hsuan Chuang | e303748 | 2019-04-26 15:17:37 +0300 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | if (channel >= 36 && channel <= 51) |
| 1101 | rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x494); |
| 1102 | else if (channel >= 52 && channel <= 55) |
| 1103 | rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x493); |
| 1104 | else if (channel >= 56 && channel <= 111) |
| 1105 | rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x453); |
| 1106 | else if (channel >= 112 && channel <= 119) |
| 1107 | rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x452); |
| 1108 | else if (channel >= 120 && channel <= 172) |
| 1109 | rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x412); |
| 1110 | else if (channel >= 173 && channel <= 177) |
| 1111 | rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x411); |
| 1112 | } |
| 1113 | |
| 1114 | switch (bw) { |
| 1115 | case RTW_CHANNEL_WIDTH_20: |
| 1116 | rtw_write32_mask(rtwdev, REG_DFIRBW, 0x3FF0, 0x19B); |
| 1117 | rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xf, 0x0); |
| 1118 | rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xffc0, 0x0); |
| 1119 | rtw_write32_mask(rtwdev, REG_TXCLK, 0x700, 0x7); |
| 1120 | rtw_write32_mask(rtwdev, REG_TXCLK, 0x700000, 0x6); |
Chien-Hsun Liao | f859e71 | 2019-06-14 15:24:09 +0800 | [diff] [blame^] | 1121 | rtw_write32_mask(rtwdev, REG_CCK_SOURCE, BIT_NBI_EN, 0x0); |
| 1122 | rtw_write32_mask(rtwdev, REG_SBD, BITS_SUBTUNE, 0x1); |
| 1123 | rtw_write32_mask(rtwdev, REG_PT_CHSMO, BIT_PT_OPT, 0x0); |
Yan-Hsuan Chuang | e303748 | 2019-04-26 15:17:37 +0300 | [diff] [blame] | 1124 | break; |
| 1125 | case RTW_CHANNEL_WIDTH_40: |
| 1126 | rtw_write32_mask(rtwdev, REG_CCKSB, BIT(4), |
| 1127 | (primary_ch_idx == 1 ? 1 : 0)); |
| 1128 | rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xf, 0x5); |
| 1129 | rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xc0, 0x0); |
| 1130 | rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xff00, |
| 1131 | (primary_ch_idx | (primary_ch_idx << 4))); |
Chien-Hsun Liao | f859e71 | 2019-06-14 15:24:09 +0800 | [diff] [blame^] | 1132 | rtw_write32_mask(rtwdev, REG_CCK_SOURCE, BIT_NBI_EN, 0x1); |
| 1133 | rtw_write32_mask(rtwdev, REG_SBD, BITS_SUBTUNE, 0x1); |
| 1134 | rtw_write32_mask(rtwdev, REG_PT_CHSMO, BIT_PT_OPT, 0x1); |
Yan-Hsuan Chuang | e303748 | 2019-04-26 15:17:37 +0300 | [diff] [blame] | 1135 | break; |
| 1136 | case RTW_CHANNEL_WIDTH_80: |
| 1137 | rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xf, 0xa); |
| 1138 | rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xc0, 0x0); |
| 1139 | rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xff00, |
| 1140 | (primary_ch_idx | (primary_ch_idx << 4))); |
Chien-Hsun Liao | f859e71 | 2019-06-14 15:24:09 +0800 | [diff] [blame^] | 1141 | rtw_write32_mask(rtwdev, REG_SBD, BITS_SUBTUNE, 0x6); |
| 1142 | rtw_write32_mask(rtwdev, REG_PT_CHSMO, BIT_PT_OPT, 0x1); |
Yan-Hsuan Chuang | e303748 | 2019-04-26 15:17:37 +0300 | [diff] [blame] | 1143 | break; |
| 1144 | case RTW_CHANNEL_WIDTH_5: |
| 1145 | rtw_write32_mask(rtwdev, REG_DFIRBW, 0x3FF0, 0x2AB); |
| 1146 | rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xf, 0x0); |
| 1147 | rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xffc0, 0x1); |
| 1148 | rtw_write32_mask(rtwdev, REG_TXCLK, 0x700, 0x4); |
| 1149 | rtw_write32_mask(rtwdev, REG_TXCLK, 0x700000, 0x4); |
Chien-Hsun Liao | f859e71 | 2019-06-14 15:24:09 +0800 | [diff] [blame^] | 1150 | rtw_write32_mask(rtwdev, REG_CCK_SOURCE, BIT_NBI_EN, 0x0); |
| 1151 | rtw_write32_mask(rtwdev, REG_SBD, BITS_SUBTUNE, 0x1); |
| 1152 | rtw_write32_mask(rtwdev, REG_PT_CHSMO, BIT_PT_OPT, 0x0); |
Yan-Hsuan Chuang | e303748 | 2019-04-26 15:17:37 +0300 | [diff] [blame] | 1153 | break; |
| 1154 | case RTW_CHANNEL_WIDTH_10: |
| 1155 | rtw_write32_mask(rtwdev, REG_DFIRBW, 0x3FF0, 0x2AB); |
| 1156 | rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xf, 0x0); |
| 1157 | rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xffc0, 0x2); |
| 1158 | rtw_write32_mask(rtwdev, REG_TXCLK, 0x700, 0x6); |
| 1159 | rtw_write32_mask(rtwdev, REG_TXCLK, 0x700000, 0x5); |
Chien-Hsun Liao | f859e71 | 2019-06-14 15:24:09 +0800 | [diff] [blame^] | 1160 | rtw_write32_mask(rtwdev, REG_CCK_SOURCE, BIT_NBI_EN, 0x0); |
| 1161 | rtw_write32_mask(rtwdev, REG_SBD, BITS_SUBTUNE, 0x1); |
| 1162 | rtw_write32_mask(rtwdev, REG_PT_CHSMO, BIT_PT_OPT, 0x0); |
Yan-Hsuan Chuang | e303748 | 2019-04-26 15:17:37 +0300 | [diff] [blame] | 1163 | break; |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | static void rtw8822c_set_channel(struct rtw_dev *rtwdev, u8 channel, u8 bw, |
| 1168 | u8 primary_chan_idx) |
| 1169 | { |
| 1170 | rtw8822c_set_channel_bb(rtwdev, channel, bw, primary_chan_idx); |
| 1171 | rtw_set_channel_mac(rtwdev, channel, bw, primary_chan_idx); |
| 1172 | rtw8822c_set_channel_rf(rtwdev, channel, bw); |
| 1173 | rtw8822c_toggle_igi(rtwdev); |
| 1174 | } |
| 1175 | |
| 1176 | static void rtw8822c_config_cck_rx_path(struct rtw_dev *rtwdev, u8 rx_path) |
| 1177 | { |
| 1178 | if (rx_path == BB_PATH_A || rx_path == BB_PATH_B) { |
| 1179 | rtw_write32_mask(rtwdev, REG_CCANRX, 0x00060000, 0x0); |
| 1180 | rtw_write32_mask(rtwdev, REG_CCANRX, 0x00600000, 0x0); |
| 1181 | } else if (rx_path == BB_PATH_AB) { |
| 1182 | rtw_write32_mask(rtwdev, REG_CCANRX, 0x00600000, 0x1); |
| 1183 | rtw_write32_mask(rtwdev, REG_CCANRX, 0x00060000, 0x1); |
| 1184 | } |
| 1185 | |
| 1186 | if (rx_path == BB_PATH_A) |
| 1187 | rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0x0f000000, 0x0); |
| 1188 | else if (rx_path == BB_PATH_B) |
| 1189 | rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0x0f000000, 0x5); |
| 1190 | else if (rx_path == BB_PATH_AB) |
| 1191 | rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0x0f000000, 0x1); |
| 1192 | } |
| 1193 | |
| 1194 | static void rtw8822c_config_ofdm_rx_path(struct rtw_dev *rtwdev, u8 rx_path) |
| 1195 | { |
| 1196 | if (rx_path == BB_PATH_A || rx_path == BB_PATH_B) { |
| 1197 | rtw_write32_mask(rtwdev, REG_RXFNCTL, 0x300, 0x0); |
| 1198 | rtw_write32_mask(rtwdev, REG_RXFNCTL, 0x600000, 0x0); |
| 1199 | rtw_write32_mask(rtwdev, REG_AGCSWSH, BIT(17), 0x0); |
| 1200 | rtw_write32_mask(rtwdev, REG_ANTWTPD, BIT(20), 0x0); |
| 1201 | rtw_write32_mask(rtwdev, REG_MRCM, BIT(24), 0x0); |
| 1202 | } else if (rx_path == BB_PATH_AB) { |
| 1203 | rtw_write32_mask(rtwdev, REG_RXFNCTL, 0x300, 0x1); |
| 1204 | rtw_write32_mask(rtwdev, REG_RXFNCTL, 0x600000, 0x1); |
| 1205 | rtw_write32_mask(rtwdev, REG_AGCSWSH, BIT(17), 0x1); |
| 1206 | rtw_write32_mask(rtwdev, REG_ANTWTPD, BIT(20), 0x1); |
| 1207 | rtw_write32_mask(rtwdev, REG_MRCM, BIT(24), 0x1); |
| 1208 | } |
| 1209 | |
| 1210 | rtw_write32_mask(rtwdev, 0x824, 0x0f000000, rx_path); |
| 1211 | rtw_write32_mask(rtwdev, 0x824, 0x000f0000, rx_path); |
| 1212 | } |
| 1213 | |
| 1214 | static void rtw8822c_config_rx_path(struct rtw_dev *rtwdev, u8 rx_path) |
| 1215 | { |
| 1216 | rtw8822c_config_cck_rx_path(rtwdev, rx_path); |
| 1217 | rtw8822c_config_ofdm_rx_path(rtwdev, rx_path); |
| 1218 | } |
| 1219 | |
| 1220 | static void rtw8822c_config_cck_tx_path(struct rtw_dev *rtwdev, u8 tx_path, |
| 1221 | bool is_tx2_path) |
| 1222 | { |
| 1223 | if (tx_path == BB_PATH_A) { |
| 1224 | rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0xf0000000, 0x8); |
| 1225 | } else if (tx_path == BB_PATH_B) { |
| 1226 | rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0xf0000000, 0x4); |
| 1227 | } else { |
| 1228 | if (is_tx2_path) |
| 1229 | rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0xf0000000, 0xc); |
| 1230 | else |
| 1231 | rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0xf0000000, 0x8); |
| 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | static void rtw8822c_config_ofdm_tx_path(struct rtw_dev *rtwdev, u8 tx_path, |
| 1236 | bool is_tx2_path) |
| 1237 | { |
| 1238 | if (tx_path == BB_PATH_A) { |
| 1239 | rtw_write32_mask(rtwdev, REG_ANTMAP0, 0xff, 0x11); |
| 1240 | rtw_write32_mask(rtwdev, REG_TXLGMAP, 0xff, 0x0); |
| 1241 | } else if (tx_path == BB_PATH_B) { |
| 1242 | rtw_write32_mask(rtwdev, REG_ANTMAP0, 0xff, 0x12); |
| 1243 | rtw_write32_mask(rtwdev, REG_TXLGMAP, 0xff, 0x0); |
| 1244 | } else { |
| 1245 | if (is_tx2_path) { |
| 1246 | rtw_write32_mask(rtwdev, REG_ANTMAP0, 0xff, 0x33); |
| 1247 | rtw_write32_mask(rtwdev, REG_TXLGMAP, 0xffff, 0x0404); |
| 1248 | } else { |
| 1249 | rtw_write32_mask(rtwdev, REG_ANTMAP0, 0xff, 0x31); |
| 1250 | rtw_write32_mask(rtwdev, REG_TXLGMAP, 0xffff, 0x0400); |
| 1251 | } |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | static void rtw8822c_config_tx_path(struct rtw_dev *rtwdev, u8 tx_path, |
| 1256 | bool is_tx2_path) |
| 1257 | { |
| 1258 | rtw8822c_config_cck_tx_path(rtwdev, tx_path, is_tx2_path); |
| 1259 | rtw8822c_config_ofdm_tx_path(rtwdev, tx_path, is_tx2_path); |
| 1260 | } |
| 1261 | |
| 1262 | static void rtw8822c_config_trx_mode(struct rtw_dev *rtwdev, u8 tx_path, |
| 1263 | u8 rx_path, bool is_tx2_path) |
| 1264 | { |
| 1265 | if ((tx_path | rx_path) & BB_PATH_A) |
| 1266 | rtw_write32_mask(rtwdev, REG_ORITXCODE, MASK20BITS, 0x33312); |
| 1267 | else |
| 1268 | rtw_write32_mask(rtwdev, REG_ORITXCODE, MASK20BITS, 0x11111); |
| 1269 | if ((tx_path | rx_path) & BB_PATH_B) |
| 1270 | rtw_write32_mask(rtwdev, REG_ORITXCODE2, MASK20BITS, 0x33312); |
| 1271 | else |
| 1272 | rtw_write32_mask(rtwdev, REG_ORITXCODE2, MASK20BITS, 0x11111); |
| 1273 | |
| 1274 | rtw8822c_config_rx_path(rtwdev, rx_path); |
| 1275 | rtw8822c_config_tx_path(rtwdev, tx_path, is_tx2_path); |
| 1276 | |
| 1277 | rtw8822c_toggle_igi(rtwdev); |
| 1278 | } |
| 1279 | |
| 1280 | static void query_phy_status_page0(struct rtw_dev *rtwdev, u8 *phy_status, |
| 1281 | struct rtw_rx_pkt_stat *pkt_stat) |
| 1282 | { |
| 1283 | struct rtw_dm_info *dm_info = &rtwdev->dm_info; |
| 1284 | u8 l_bnd, u_bnd; |
| 1285 | u8 gain_a, gain_b; |
| 1286 | s8 rx_power[RTW_RF_PATH_MAX]; |
| 1287 | s8 min_rx_power = -120; |
| 1288 | |
| 1289 | rx_power[RF_PATH_A] = GET_PHY_STAT_P0_PWDB_A(phy_status); |
| 1290 | rx_power[RF_PATH_B] = GET_PHY_STAT_P0_PWDB_B(phy_status); |
| 1291 | l_bnd = dm_info->cck_gi_l_bnd; |
| 1292 | u_bnd = dm_info->cck_gi_u_bnd; |
| 1293 | gain_a = GET_PHY_STAT_P0_GAIN_A(phy_status); |
| 1294 | gain_b = GET_PHY_STAT_P0_GAIN_B(phy_status); |
| 1295 | if (gain_a < l_bnd) |
| 1296 | rx_power[RF_PATH_A] += (l_bnd - gain_a) << 1; |
| 1297 | else if (gain_a > u_bnd) |
| 1298 | rx_power[RF_PATH_A] -= (gain_a - u_bnd) << 1; |
| 1299 | if (gain_b < l_bnd) |
| 1300 | rx_power[RF_PATH_A] += (l_bnd - gain_b) << 1; |
| 1301 | else if (gain_b > u_bnd) |
| 1302 | rx_power[RF_PATH_A] -= (gain_b - u_bnd) << 1; |
| 1303 | |
| 1304 | rx_power[RF_PATH_A] -= 110; |
| 1305 | rx_power[RF_PATH_B] -= 110; |
| 1306 | |
| 1307 | pkt_stat->rx_power[RF_PATH_A] = max3(rx_power[RF_PATH_A], |
| 1308 | rx_power[RF_PATH_B], |
| 1309 | min_rx_power); |
| 1310 | pkt_stat->rssi = rtw_phy_rf_power_2_rssi(pkt_stat->rx_power, 1); |
| 1311 | pkt_stat->bw = RTW_CHANNEL_WIDTH_20; |
| 1312 | pkt_stat->signal_power = max(pkt_stat->rx_power[RF_PATH_A], |
| 1313 | min_rx_power); |
| 1314 | } |
| 1315 | |
| 1316 | static void query_phy_status_page1(struct rtw_dev *rtwdev, u8 *phy_status, |
| 1317 | struct rtw_rx_pkt_stat *pkt_stat) |
| 1318 | { |
| 1319 | u8 rxsc, bw; |
| 1320 | s8 min_rx_power = -120; |
| 1321 | |
| 1322 | if (pkt_stat->rate > DESC_RATE11M && pkt_stat->rate < DESC_RATEMCS0) |
| 1323 | rxsc = GET_PHY_STAT_P1_L_RXSC(phy_status); |
| 1324 | else |
| 1325 | rxsc = GET_PHY_STAT_P1_HT_RXSC(phy_status); |
| 1326 | |
| 1327 | if (rxsc >= 9 && rxsc <= 12) |
| 1328 | bw = RTW_CHANNEL_WIDTH_40; |
| 1329 | else if (rxsc >= 13) |
| 1330 | bw = RTW_CHANNEL_WIDTH_80; |
| 1331 | else |
| 1332 | bw = RTW_CHANNEL_WIDTH_20; |
| 1333 | |
| 1334 | pkt_stat->rx_power[RF_PATH_A] = GET_PHY_STAT_P1_PWDB_A(phy_status) - 110; |
| 1335 | pkt_stat->rx_power[RF_PATH_B] = GET_PHY_STAT_P1_PWDB_B(phy_status) - 110; |
| 1336 | pkt_stat->rssi = rtw_phy_rf_power_2_rssi(pkt_stat->rx_power, 2); |
| 1337 | pkt_stat->bw = bw; |
| 1338 | pkt_stat->signal_power = max3(pkt_stat->rx_power[RF_PATH_A], |
| 1339 | pkt_stat->rx_power[RF_PATH_B], |
| 1340 | min_rx_power); |
| 1341 | } |
| 1342 | |
| 1343 | static void query_phy_status(struct rtw_dev *rtwdev, u8 *phy_status, |
| 1344 | struct rtw_rx_pkt_stat *pkt_stat) |
| 1345 | { |
| 1346 | u8 page; |
| 1347 | |
| 1348 | page = *phy_status & 0xf; |
| 1349 | |
| 1350 | switch (page) { |
| 1351 | case 0: |
| 1352 | query_phy_status_page0(rtwdev, phy_status, pkt_stat); |
| 1353 | break; |
| 1354 | case 1: |
| 1355 | query_phy_status_page1(rtwdev, phy_status, pkt_stat); |
| 1356 | break; |
| 1357 | default: |
| 1358 | rtw_warn(rtwdev, "unused phy status page (%d)\n", page); |
| 1359 | return; |
| 1360 | } |
| 1361 | } |
| 1362 | |
| 1363 | static void rtw8822c_query_rx_desc(struct rtw_dev *rtwdev, u8 *rx_desc, |
| 1364 | struct rtw_rx_pkt_stat *pkt_stat, |
| 1365 | struct ieee80211_rx_status *rx_status) |
| 1366 | { |
| 1367 | struct ieee80211_hdr *hdr; |
| 1368 | u32 desc_sz = rtwdev->chip->rx_pkt_desc_sz; |
| 1369 | u8 *phy_status = NULL; |
| 1370 | |
| 1371 | memset(pkt_stat, 0, sizeof(*pkt_stat)); |
| 1372 | |
| 1373 | pkt_stat->phy_status = GET_RX_DESC_PHYST(rx_desc); |
| 1374 | pkt_stat->icv_err = GET_RX_DESC_ICV_ERR(rx_desc); |
| 1375 | pkt_stat->crc_err = GET_RX_DESC_CRC32(rx_desc); |
| 1376 | pkt_stat->decrypted = !GET_RX_DESC_SWDEC(rx_desc); |
| 1377 | pkt_stat->is_c2h = GET_RX_DESC_C2H(rx_desc); |
| 1378 | pkt_stat->pkt_len = GET_RX_DESC_PKT_LEN(rx_desc); |
| 1379 | pkt_stat->drv_info_sz = GET_RX_DESC_DRV_INFO_SIZE(rx_desc); |
| 1380 | pkt_stat->shift = GET_RX_DESC_SHIFT(rx_desc); |
| 1381 | pkt_stat->rate = GET_RX_DESC_RX_RATE(rx_desc); |
| 1382 | pkt_stat->cam_id = GET_RX_DESC_MACID(rx_desc); |
| 1383 | pkt_stat->ppdu_cnt = GET_RX_DESC_PPDU_CNT(rx_desc); |
| 1384 | pkt_stat->tsf_low = GET_RX_DESC_TSFL(rx_desc); |
| 1385 | |
| 1386 | /* drv_info_sz is in unit of 8-bytes */ |
| 1387 | pkt_stat->drv_info_sz *= 8; |
| 1388 | |
| 1389 | /* c2h cmd pkt's rx/phy status is not interested */ |
| 1390 | if (pkt_stat->is_c2h) |
| 1391 | return; |
| 1392 | |
| 1393 | hdr = (struct ieee80211_hdr *)(rx_desc + desc_sz + pkt_stat->shift + |
| 1394 | pkt_stat->drv_info_sz); |
| 1395 | if (pkt_stat->phy_status) { |
| 1396 | phy_status = rx_desc + desc_sz + pkt_stat->shift; |
| 1397 | query_phy_status(rtwdev, phy_status, pkt_stat); |
| 1398 | } |
| 1399 | |
| 1400 | rtw_rx_fill_rx_status(rtwdev, pkt_stat, hdr, rx_status, phy_status); |
| 1401 | } |
| 1402 | |
| 1403 | static void |
| 1404 | rtw8822c_set_write_tx_power_ref(struct rtw_dev *rtwdev, u8 *tx_pwr_ref_cck, |
| 1405 | u8 *tx_pwr_ref_ofdm) |
| 1406 | { |
| 1407 | struct rtw_hal *hal = &rtwdev->hal; |
| 1408 | u32 txref_cck[2] = {0x18a0, 0x41a0}; |
| 1409 | u32 txref_ofdm[2] = {0x18e8, 0x41e8}; |
| 1410 | u8 path; |
| 1411 | |
| 1412 | for (path = 0; path < hal->rf_path_num; path++) { |
| 1413 | rtw_write32_mask(rtwdev, 0x1c90, BIT(15), 0); |
| 1414 | rtw_write32_mask(rtwdev, txref_cck[path], 0x7f0000, |
| 1415 | tx_pwr_ref_cck[path]); |
| 1416 | } |
| 1417 | for (path = 0; path < hal->rf_path_num; path++) { |
| 1418 | rtw_write32_mask(rtwdev, 0x1c90, BIT(15), 0); |
| 1419 | rtw_write32_mask(rtwdev, txref_ofdm[path], 0x1fc00, |
| 1420 | tx_pwr_ref_ofdm[path]); |
| 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | static void rtw8822c_set_tx_power_diff(struct rtw_dev *rtwdev, u8 rate, |
| 1425 | s8 *diff_idx) |
| 1426 | { |
| 1427 | u32 offset_txagc = 0x3a00; |
| 1428 | u8 rate_idx = rate & 0xfc; |
| 1429 | u8 pwr_idx[4]; |
| 1430 | u32 phy_pwr_idx; |
| 1431 | int i; |
| 1432 | |
| 1433 | for (i = 0; i < 4; i++) |
| 1434 | pwr_idx[i] = diff_idx[i] & 0x7f; |
| 1435 | |
| 1436 | phy_pwr_idx = pwr_idx[0] | |
| 1437 | (pwr_idx[1] << 8) | |
| 1438 | (pwr_idx[2] << 16) | |
| 1439 | (pwr_idx[3] << 24); |
| 1440 | |
| 1441 | rtw_write32_mask(rtwdev, 0x1c90, BIT(15), 0x0); |
| 1442 | rtw_write32_mask(rtwdev, offset_txagc + rate_idx, MASKDWORD, |
| 1443 | phy_pwr_idx); |
| 1444 | } |
| 1445 | |
| 1446 | static void rtw8822c_set_tx_power_index(struct rtw_dev *rtwdev) |
| 1447 | { |
| 1448 | struct rtw_hal *hal = &rtwdev->hal; |
| 1449 | u8 rs, rate, j; |
| 1450 | u8 pwr_ref_cck[2] = {hal->tx_pwr_tbl[RF_PATH_A][DESC_RATE11M], |
| 1451 | hal->tx_pwr_tbl[RF_PATH_B][DESC_RATE11M]}; |
| 1452 | u8 pwr_ref_ofdm[2] = {hal->tx_pwr_tbl[RF_PATH_A][DESC_RATEMCS7], |
| 1453 | hal->tx_pwr_tbl[RF_PATH_B][DESC_RATEMCS7]}; |
| 1454 | s8 diff_a, diff_b; |
| 1455 | u8 pwr_a, pwr_b; |
| 1456 | s8 diff_idx[4]; |
| 1457 | |
| 1458 | rtw8822c_set_write_tx_power_ref(rtwdev, pwr_ref_cck, pwr_ref_ofdm); |
| 1459 | for (rs = 0; rs < RTW_RATE_SECTION_MAX; rs++) { |
| 1460 | for (j = 0; j < rtw_rate_size[rs]; j++) { |
| 1461 | rate = rtw_rate_section[rs][j]; |
| 1462 | pwr_a = hal->tx_pwr_tbl[RF_PATH_A][rate]; |
| 1463 | pwr_b = hal->tx_pwr_tbl[RF_PATH_B][rate]; |
| 1464 | if (rs == 0) { |
| 1465 | diff_a = (s8)pwr_a - (s8)pwr_ref_cck[0]; |
| 1466 | diff_b = (s8)pwr_b - (s8)pwr_ref_cck[1]; |
| 1467 | } else { |
| 1468 | diff_a = (s8)pwr_a - (s8)pwr_ref_ofdm[0]; |
| 1469 | diff_b = (s8)pwr_b - (s8)pwr_ref_ofdm[1]; |
| 1470 | } |
| 1471 | diff_idx[rate % 4] = min(diff_a, diff_b); |
| 1472 | if (rate % 4 == 3) |
| 1473 | rtw8822c_set_tx_power_diff(rtwdev, rate - 3, |
| 1474 | diff_idx); |
| 1475 | } |
| 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | static void rtw8822c_cfg_ldo25(struct rtw_dev *rtwdev, bool enable) |
| 1480 | { |
| 1481 | u8 ldo_pwr; |
| 1482 | |
| 1483 | ldo_pwr = rtw_read8(rtwdev, REG_ANAPARLDO_POW_MAC); |
| 1484 | ldo_pwr = enable ? ldo_pwr | BIT_LDOE25_PON : ldo_pwr & ~BIT_LDOE25_PON; |
| 1485 | rtw_write8(rtwdev, REG_ANAPARLDO_POW_MAC, ldo_pwr); |
| 1486 | } |
| 1487 | |
| 1488 | static void rtw8822c_false_alarm_statistics(struct rtw_dev *rtwdev) |
| 1489 | { |
| 1490 | struct rtw_dm_info *dm_info = &rtwdev->dm_info; |
| 1491 | u32 cck_enable; |
| 1492 | u32 cck_fa_cnt; |
| 1493 | u32 ofdm_fa_cnt; |
| 1494 | u32 ofdm_tx_counter; |
| 1495 | |
| 1496 | cck_enable = rtw_read32(rtwdev, REG_ENCCK) & BIT_CCK_BLK_EN; |
| 1497 | cck_fa_cnt = rtw_read16(rtwdev, REG_CCK_FACNT); |
| 1498 | ofdm_fa_cnt = rtw_read16(rtwdev, REG_OFDM_FACNT); |
| 1499 | ofdm_tx_counter = rtw_read16(rtwdev, REG_OFDM_TXCNT); |
| 1500 | ofdm_fa_cnt -= ofdm_tx_counter; |
| 1501 | |
| 1502 | dm_info->cck_fa_cnt = cck_fa_cnt; |
| 1503 | dm_info->ofdm_fa_cnt = ofdm_fa_cnt; |
| 1504 | dm_info->total_fa_cnt = ofdm_fa_cnt; |
| 1505 | dm_info->total_fa_cnt += cck_enable ? cck_fa_cnt : 0; |
| 1506 | |
| 1507 | rtw_write32_mask(rtwdev, REG_CCANRX, BIT_CCK_FA_RST, 0); |
| 1508 | rtw_write32_mask(rtwdev, REG_CCANRX, BIT_CCK_FA_RST, 2); |
| 1509 | rtw_write32_mask(rtwdev, REG_CCANRX, BIT_OFDM_FA_RST, 0); |
| 1510 | rtw_write32_mask(rtwdev, REG_CCANRX, BIT_OFDM_FA_RST, 2); |
| 1511 | rtw_write32_set(rtwdev, REG_CNT_CTRL, BIT_ALL_CNT_RST); |
| 1512 | rtw_write32_clr(rtwdev, REG_CNT_CTRL, BIT_ALL_CNT_RST); |
| 1513 | } |
| 1514 | |
| 1515 | static void rtw8822c_do_iqk(struct rtw_dev *rtwdev) |
| 1516 | { |
| 1517 | } |
| 1518 | |
| 1519 | static struct rtw_pwr_seq_cmd trans_carddis_to_cardemu_8822c[] = { |
| 1520 | {0x0086, |
| 1521 | RTW_PWR_CUT_ALL_MSK, |
| 1522 | RTW_PWR_INTF_SDIO_MSK, |
| 1523 | RTW_PWR_ADDR_SDIO, |
| 1524 | RTW_PWR_CMD_WRITE, BIT(0), 0}, |
| 1525 | {0x0086, |
| 1526 | RTW_PWR_CUT_ALL_MSK, |
| 1527 | RTW_PWR_INTF_SDIO_MSK, |
| 1528 | RTW_PWR_ADDR_SDIO, |
| 1529 | RTW_PWR_CMD_POLLING, BIT(1), BIT(1)}, |
| 1530 | {0x002E, |
| 1531 | RTW_PWR_CUT_ALL_MSK, |
| 1532 | RTW_PWR_INTF_ALL_MSK, |
| 1533 | RTW_PWR_ADDR_MAC, |
| 1534 | RTW_PWR_CMD_WRITE, BIT(2), BIT(2)}, |
| 1535 | {0x002D, |
| 1536 | RTW_PWR_CUT_ALL_MSK, |
| 1537 | RTW_PWR_INTF_ALL_MSK, |
| 1538 | RTW_PWR_ADDR_MAC, |
| 1539 | RTW_PWR_CMD_WRITE, BIT(0), 0}, |
| 1540 | {0x007F, |
| 1541 | RTW_PWR_CUT_ALL_MSK, |
| 1542 | RTW_PWR_INTF_ALL_MSK, |
| 1543 | RTW_PWR_ADDR_MAC, |
| 1544 | RTW_PWR_CMD_WRITE, BIT(7), 0}, |
| 1545 | {0x004A, |
| 1546 | RTW_PWR_CUT_ALL_MSK, |
| 1547 | RTW_PWR_INTF_USB_MSK, |
| 1548 | RTW_PWR_ADDR_MAC, |
| 1549 | RTW_PWR_CMD_WRITE, BIT(0), 0}, |
| 1550 | {0x0005, |
| 1551 | RTW_PWR_CUT_ALL_MSK, |
| 1552 | RTW_PWR_INTF_ALL_MSK, |
| 1553 | RTW_PWR_ADDR_MAC, |
| 1554 | RTW_PWR_CMD_WRITE, BIT(3) | BIT(4) | BIT(7), 0}, |
| 1555 | {0xFFFF, |
| 1556 | RTW_PWR_CUT_ALL_MSK, |
| 1557 | RTW_PWR_INTF_ALL_MSK, |
| 1558 | 0, |
| 1559 | RTW_PWR_CMD_END, 0, 0}, |
| 1560 | }; |
| 1561 | |
| 1562 | static struct rtw_pwr_seq_cmd trans_cardemu_to_act_8822c[] = { |
| 1563 | {0x0000, |
| 1564 | RTW_PWR_CUT_ALL_MSK, |
| 1565 | RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK, |
| 1566 | RTW_PWR_ADDR_MAC, |
| 1567 | RTW_PWR_CMD_WRITE, BIT(5), 0}, |
| 1568 | {0x0005, |
| 1569 | RTW_PWR_CUT_ALL_MSK, |
| 1570 | RTW_PWR_INTF_ALL_MSK, |
| 1571 | RTW_PWR_ADDR_MAC, |
| 1572 | RTW_PWR_CMD_WRITE, (BIT(4) | BIT(3) | BIT(2)), 0}, |
| 1573 | {0x0075, |
| 1574 | RTW_PWR_CUT_ALL_MSK, |
| 1575 | RTW_PWR_INTF_PCI_MSK, |
| 1576 | RTW_PWR_ADDR_MAC, |
| 1577 | RTW_PWR_CMD_WRITE, BIT(0), BIT(0)}, |
| 1578 | {0x0006, |
| 1579 | RTW_PWR_CUT_ALL_MSK, |
| 1580 | RTW_PWR_INTF_ALL_MSK, |
| 1581 | RTW_PWR_ADDR_MAC, |
| 1582 | RTW_PWR_CMD_POLLING, BIT(1), BIT(1)}, |
| 1583 | {0x0075, |
| 1584 | RTW_PWR_CUT_ALL_MSK, |
| 1585 | RTW_PWR_INTF_PCI_MSK, |
| 1586 | RTW_PWR_ADDR_MAC, |
| 1587 | RTW_PWR_CMD_WRITE, BIT(0), 0}, |
| 1588 | {0xFF1A, |
| 1589 | RTW_PWR_CUT_ALL_MSK, |
| 1590 | RTW_PWR_INTF_USB_MSK, |
| 1591 | RTW_PWR_ADDR_MAC, |
| 1592 | RTW_PWR_CMD_WRITE, 0xFF, 0}, |
| 1593 | {0x002E, |
| 1594 | RTW_PWR_CUT_ALL_MSK, |
| 1595 | RTW_PWR_INTF_ALL_MSK, |
| 1596 | RTW_PWR_ADDR_MAC, |
| 1597 | RTW_PWR_CMD_WRITE, BIT(3), 0}, |
| 1598 | {0x0006, |
| 1599 | RTW_PWR_CUT_ALL_MSK, |
| 1600 | RTW_PWR_INTF_ALL_MSK, |
| 1601 | RTW_PWR_ADDR_MAC, |
| 1602 | RTW_PWR_CMD_WRITE, BIT(0), BIT(0)}, |
| 1603 | {0x0005, |
| 1604 | RTW_PWR_CUT_ALL_MSK, |
| 1605 | RTW_PWR_INTF_ALL_MSK, |
| 1606 | RTW_PWR_ADDR_MAC, |
| 1607 | RTW_PWR_CMD_WRITE, BIT(7), 0}, |
| 1608 | {0x0005, |
| 1609 | RTW_PWR_CUT_ALL_MSK, |
| 1610 | RTW_PWR_INTF_ALL_MSK, |
| 1611 | RTW_PWR_ADDR_MAC, |
| 1612 | RTW_PWR_CMD_WRITE, (BIT(4) | BIT(3)), 0}, |
| 1613 | {0x0005, |
| 1614 | RTW_PWR_CUT_ALL_MSK, |
| 1615 | RTW_PWR_INTF_ALL_MSK, |
| 1616 | RTW_PWR_ADDR_MAC, |
| 1617 | RTW_PWR_CMD_WRITE, BIT(0), BIT(0)}, |
| 1618 | {0x0005, |
| 1619 | RTW_PWR_CUT_ALL_MSK, |
| 1620 | RTW_PWR_INTF_ALL_MSK, |
| 1621 | RTW_PWR_ADDR_MAC, |
| 1622 | RTW_PWR_CMD_POLLING, BIT(0), 0}, |
| 1623 | {0x0074, |
| 1624 | RTW_PWR_CUT_ALL_MSK, |
| 1625 | RTW_PWR_INTF_PCI_MSK, |
| 1626 | RTW_PWR_ADDR_MAC, |
| 1627 | RTW_PWR_CMD_WRITE, BIT(5), BIT(5)}, |
| 1628 | {0x0071, |
| 1629 | RTW_PWR_CUT_ALL_MSK, |
| 1630 | RTW_PWR_INTF_PCI_MSK, |
| 1631 | RTW_PWR_ADDR_MAC, |
| 1632 | RTW_PWR_CMD_WRITE, BIT(4), 0}, |
| 1633 | {0x0062, |
| 1634 | RTW_PWR_CUT_ALL_MSK, |
| 1635 | RTW_PWR_INTF_PCI_MSK, |
| 1636 | RTW_PWR_ADDR_MAC, |
| 1637 | RTW_PWR_CMD_WRITE, (BIT(7) | BIT(6) | BIT(5)), |
| 1638 | (BIT(7) | BIT(6) | BIT(5))}, |
| 1639 | {0x0061, |
| 1640 | RTW_PWR_CUT_ALL_MSK, |
| 1641 | RTW_PWR_INTF_PCI_MSK, |
| 1642 | RTW_PWR_ADDR_MAC, |
| 1643 | RTW_PWR_CMD_WRITE, (BIT(7) | BIT(6) | BIT(5)), 0}, |
| 1644 | {0x001F, |
| 1645 | RTW_PWR_CUT_ALL_MSK, |
| 1646 | RTW_PWR_INTF_ALL_MSK, |
| 1647 | RTW_PWR_ADDR_MAC, |
| 1648 | RTW_PWR_CMD_WRITE, (BIT(7) | BIT(6)), BIT(7)}, |
| 1649 | {0x00EF, |
| 1650 | RTW_PWR_CUT_ALL_MSK, |
| 1651 | RTW_PWR_INTF_ALL_MSK, |
| 1652 | RTW_PWR_ADDR_MAC, |
| 1653 | RTW_PWR_CMD_WRITE, (BIT(7) | BIT(6)), BIT(7)}, |
| 1654 | {0x1045, |
| 1655 | RTW_PWR_CUT_ALL_MSK, |
| 1656 | RTW_PWR_INTF_ALL_MSK, |
| 1657 | RTW_PWR_ADDR_MAC, |
| 1658 | RTW_PWR_CMD_WRITE, BIT(4), BIT(4)}, |
| 1659 | {0x0010, |
| 1660 | RTW_PWR_CUT_ALL_MSK, |
| 1661 | RTW_PWR_INTF_ALL_MSK, |
| 1662 | RTW_PWR_ADDR_MAC, |
| 1663 | RTW_PWR_CMD_WRITE, BIT(2), BIT(2)}, |
| 1664 | {0xFFFF, |
| 1665 | RTW_PWR_CUT_ALL_MSK, |
| 1666 | RTW_PWR_INTF_ALL_MSK, |
| 1667 | 0, |
| 1668 | RTW_PWR_CMD_END, 0, 0}, |
| 1669 | }; |
| 1670 | |
| 1671 | static struct rtw_pwr_seq_cmd trans_act_to_cardemu_8822c[] = { |
| 1672 | {0x0093, |
| 1673 | RTW_PWR_CUT_ALL_MSK, |
| 1674 | RTW_PWR_INTF_ALL_MSK, |
| 1675 | RTW_PWR_ADDR_MAC, |
| 1676 | RTW_PWR_CMD_WRITE, BIT(3), 0}, |
| 1677 | {0x001F, |
| 1678 | RTW_PWR_CUT_ALL_MSK, |
| 1679 | RTW_PWR_INTF_ALL_MSK, |
| 1680 | RTW_PWR_ADDR_MAC, |
| 1681 | RTW_PWR_CMD_WRITE, 0xFF, 0}, |
| 1682 | {0x00EF, |
| 1683 | RTW_PWR_CUT_ALL_MSK, |
| 1684 | RTW_PWR_INTF_ALL_MSK, |
| 1685 | RTW_PWR_ADDR_MAC, |
| 1686 | RTW_PWR_CMD_WRITE, 0xFF, 0}, |
| 1687 | {0x1045, |
| 1688 | RTW_PWR_CUT_ALL_MSK, |
| 1689 | RTW_PWR_INTF_ALL_MSK, |
| 1690 | RTW_PWR_ADDR_MAC, |
| 1691 | RTW_PWR_CMD_WRITE, BIT(4), 0}, |
| 1692 | {0xFF1A, |
| 1693 | RTW_PWR_CUT_ALL_MSK, |
| 1694 | RTW_PWR_INTF_USB_MSK, |
| 1695 | RTW_PWR_ADDR_MAC, |
| 1696 | RTW_PWR_CMD_WRITE, 0xFF, 0x30}, |
| 1697 | {0x0049, |
| 1698 | RTW_PWR_CUT_ALL_MSK, |
| 1699 | RTW_PWR_INTF_ALL_MSK, |
| 1700 | RTW_PWR_ADDR_MAC, |
| 1701 | RTW_PWR_CMD_WRITE, BIT(1), 0}, |
| 1702 | {0x0006, |
| 1703 | RTW_PWR_CUT_ALL_MSK, |
| 1704 | RTW_PWR_INTF_ALL_MSK, |
| 1705 | RTW_PWR_ADDR_MAC, |
| 1706 | RTW_PWR_CMD_WRITE, BIT(0), BIT(0)}, |
| 1707 | {0x0002, |
| 1708 | RTW_PWR_CUT_ALL_MSK, |
| 1709 | RTW_PWR_INTF_ALL_MSK, |
| 1710 | RTW_PWR_ADDR_MAC, |
| 1711 | RTW_PWR_CMD_WRITE, BIT(1), 0}, |
| 1712 | {0x0005, |
| 1713 | RTW_PWR_CUT_ALL_MSK, |
| 1714 | RTW_PWR_INTF_ALL_MSK, |
| 1715 | RTW_PWR_ADDR_MAC, |
| 1716 | RTW_PWR_CMD_WRITE, BIT(1), BIT(1)}, |
| 1717 | {0x0005, |
| 1718 | RTW_PWR_CUT_ALL_MSK, |
| 1719 | RTW_PWR_INTF_ALL_MSK, |
| 1720 | RTW_PWR_ADDR_MAC, |
| 1721 | RTW_PWR_CMD_POLLING, BIT(1), 0}, |
| 1722 | {0x0000, |
| 1723 | RTW_PWR_CUT_ALL_MSK, |
| 1724 | RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK, |
| 1725 | RTW_PWR_ADDR_MAC, |
| 1726 | RTW_PWR_CMD_WRITE, BIT(5), BIT(5)}, |
| 1727 | {0xFFFF, |
| 1728 | RTW_PWR_CUT_ALL_MSK, |
| 1729 | RTW_PWR_INTF_ALL_MSK, |
| 1730 | 0, |
| 1731 | RTW_PWR_CMD_END, 0, 0}, |
| 1732 | }; |
| 1733 | |
| 1734 | static struct rtw_pwr_seq_cmd trans_cardemu_to_carddis_8822c[] = { |
| 1735 | {0x0005, |
| 1736 | RTW_PWR_CUT_ALL_MSK, |
| 1737 | RTW_PWR_INTF_SDIO_MSK, |
| 1738 | RTW_PWR_ADDR_MAC, |
| 1739 | RTW_PWR_CMD_WRITE, BIT(7), BIT(7)}, |
| 1740 | {0x0007, |
| 1741 | RTW_PWR_CUT_ALL_MSK, |
| 1742 | RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK, |
| 1743 | RTW_PWR_ADDR_MAC, |
| 1744 | RTW_PWR_CMD_WRITE, 0xFF, 0x00}, |
| 1745 | {0x0067, |
| 1746 | RTW_PWR_CUT_ALL_MSK, |
| 1747 | RTW_PWR_INTF_ALL_MSK, |
| 1748 | RTW_PWR_ADDR_MAC, |
| 1749 | RTW_PWR_CMD_WRITE, BIT(5), 0}, |
| 1750 | {0x004A, |
| 1751 | RTW_PWR_CUT_ALL_MSK, |
| 1752 | RTW_PWR_INTF_USB_MSK, |
| 1753 | RTW_PWR_ADDR_MAC, |
| 1754 | RTW_PWR_CMD_WRITE, BIT(0), 0}, |
| 1755 | {0x0081, |
| 1756 | RTW_PWR_CUT_ALL_MSK, |
| 1757 | RTW_PWR_INTF_ALL_MSK, |
| 1758 | RTW_PWR_ADDR_MAC, |
| 1759 | RTW_PWR_CMD_WRITE, BIT(7) | BIT(6), 0}, |
| 1760 | {0x0090, |
| 1761 | RTW_PWR_CUT_ALL_MSK, |
| 1762 | RTW_PWR_INTF_ALL_MSK, |
| 1763 | RTW_PWR_ADDR_MAC, |
| 1764 | RTW_PWR_CMD_WRITE, BIT(1), 0}, |
| 1765 | {0x0005, |
| 1766 | RTW_PWR_CUT_ALL_MSK, |
| 1767 | RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK, |
| 1768 | RTW_PWR_ADDR_MAC, |
| 1769 | RTW_PWR_CMD_WRITE, BIT(3) | BIT(4), BIT(3)}, |
| 1770 | {0x0005, |
| 1771 | RTW_PWR_CUT_ALL_MSK, |
| 1772 | RTW_PWR_INTF_PCI_MSK, |
| 1773 | RTW_PWR_ADDR_MAC, |
| 1774 | RTW_PWR_CMD_WRITE, BIT(2), BIT(2)}, |
| 1775 | {0x0086, |
| 1776 | RTW_PWR_CUT_ALL_MSK, |
| 1777 | RTW_PWR_INTF_SDIO_MSK, |
| 1778 | RTW_PWR_ADDR_SDIO, |
| 1779 | RTW_PWR_CMD_WRITE, BIT(0), BIT(0)}, |
| 1780 | {0xFFFF, |
| 1781 | RTW_PWR_CUT_ALL_MSK, |
| 1782 | RTW_PWR_INTF_ALL_MSK, |
| 1783 | 0, |
| 1784 | RTW_PWR_CMD_END, 0, 0}, |
| 1785 | }; |
| 1786 | |
| 1787 | static struct rtw_pwr_seq_cmd *card_enable_flow_8822c[] = { |
| 1788 | trans_carddis_to_cardemu_8822c, |
| 1789 | trans_cardemu_to_act_8822c, |
| 1790 | NULL |
| 1791 | }; |
| 1792 | |
| 1793 | static struct rtw_pwr_seq_cmd *card_disable_flow_8822c[] = { |
| 1794 | trans_act_to_cardemu_8822c, |
| 1795 | trans_cardemu_to_carddis_8822c, |
| 1796 | NULL |
| 1797 | }; |
| 1798 | |
| 1799 | static struct rtw_intf_phy_para usb2_param_8822c[] = { |
| 1800 | {0xFFFF, 0x00, |
| 1801 | RTW_IP_SEL_PHY, |
| 1802 | RTW_INTF_PHY_CUT_ALL, |
| 1803 | RTW_INTF_PHY_PLATFORM_ALL}, |
| 1804 | }; |
| 1805 | |
| 1806 | static struct rtw_intf_phy_para usb3_param_8822c[] = { |
| 1807 | {0xFFFF, 0x0000, |
| 1808 | RTW_IP_SEL_PHY, |
| 1809 | RTW_INTF_PHY_CUT_ALL, |
| 1810 | RTW_INTF_PHY_PLATFORM_ALL}, |
| 1811 | }; |
| 1812 | |
| 1813 | static struct rtw_intf_phy_para pcie_gen1_param_8822c[] = { |
| 1814 | {0xFFFF, 0x0000, |
| 1815 | RTW_IP_SEL_PHY, |
| 1816 | RTW_INTF_PHY_CUT_ALL, |
| 1817 | RTW_INTF_PHY_PLATFORM_ALL}, |
| 1818 | }; |
| 1819 | |
| 1820 | static struct rtw_intf_phy_para pcie_gen2_param_8822c[] = { |
| 1821 | {0xFFFF, 0x0000, |
| 1822 | RTW_IP_SEL_PHY, |
| 1823 | RTW_INTF_PHY_CUT_ALL, |
| 1824 | RTW_INTF_PHY_PLATFORM_ALL}, |
| 1825 | }; |
| 1826 | |
| 1827 | static struct rtw_intf_phy_para_table phy_para_table_8822c = { |
| 1828 | .usb2_para = usb2_param_8822c, |
| 1829 | .usb3_para = usb3_param_8822c, |
| 1830 | .gen1_para = pcie_gen1_param_8822c, |
| 1831 | .gen2_para = pcie_gen2_param_8822c, |
| 1832 | .n_usb2_para = ARRAY_SIZE(usb2_param_8822c), |
| 1833 | .n_usb3_para = ARRAY_SIZE(usb2_param_8822c), |
| 1834 | .n_gen1_para = ARRAY_SIZE(pcie_gen1_param_8822c), |
| 1835 | .n_gen2_para = ARRAY_SIZE(pcie_gen2_param_8822c), |
| 1836 | }; |
| 1837 | |
| 1838 | static const struct rtw_rfe_def rtw8822c_rfe_defs[] = { |
| 1839 | [0] = RTW_DEF_RFE(8822c, 0, 0), |
| 1840 | [1] = RTW_DEF_RFE(8822c, 0, 0), |
| 1841 | [2] = RTW_DEF_RFE(8822c, 0, 0), |
| 1842 | }; |
| 1843 | |
| 1844 | static struct rtw_hw_reg rtw8822c_dig[] = { |
| 1845 | [0] = { .addr = 0x1d70, .mask = 0x7f }, |
| 1846 | [1] = { .addr = 0x1d70, .mask = 0x7f00 }, |
| 1847 | }; |
| 1848 | |
| 1849 | static struct rtw_page_table page_table_8822c[] = { |
| 1850 | {64, 64, 64, 64, 1}, |
| 1851 | {64, 64, 64, 64, 1}, |
| 1852 | {64, 64, 0, 0, 1}, |
| 1853 | {64, 64, 64, 0, 1}, |
| 1854 | {64, 64, 64, 64, 1}, |
| 1855 | }; |
| 1856 | |
| 1857 | static struct rtw_rqpn rqpn_table_8822c[] = { |
| 1858 | {RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_NORMAL, |
| 1859 | RTW_DMA_MAPPING_LOW, RTW_DMA_MAPPING_LOW, |
| 1860 | RTW_DMA_MAPPING_EXTRA, RTW_DMA_MAPPING_HIGH}, |
| 1861 | {RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_NORMAL, |
| 1862 | RTW_DMA_MAPPING_LOW, RTW_DMA_MAPPING_LOW, |
| 1863 | RTW_DMA_MAPPING_EXTRA, RTW_DMA_MAPPING_HIGH}, |
| 1864 | {RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_NORMAL, |
| 1865 | RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_HIGH, |
| 1866 | RTW_DMA_MAPPING_HIGH, RTW_DMA_MAPPING_HIGH}, |
| 1867 | {RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_NORMAL, |
| 1868 | RTW_DMA_MAPPING_LOW, RTW_DMA_MAPPING_LOW, |
| 1869 | RTW_DMA_MAPPING_HIGH, RTW_DMA_MAPPING_HIGH}, |
| 1870 | {RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_NORMAL, |
| 1871 | RTW_DMA_MAPPING_LOW, RTW_DMA_MAPPING_LOW, |
| 1872 | RTW_DMA_MAPPING_EXTRA, RTW_DMA_MAPPING_HIGH}, |
| 1873 | }; |
| 1874 | |
| 1875 | static struct rtw_chip_ops rtw8822c_ops = { |
| 1876 | .phy_set_param = rtw8822c_phy_set_param, |
| 1877 | .read_efuse = rtw8822c_read_efuse, |
| 1878 | .query_rx_desc = rtw8822c_query_rx_desc, |
| 1879 | .set_channel = rtw8822c_set_channel, |
| 1880 | .mac_init = rtw8822c_mac_init, |
| 1881 | .read_rf = rtw_phy_read_rf, |
| 1882 | .write_rf = rtw_phy_write_rf_reg_mix, |
| 1883 | .set_tx_power_index = rtw8822c_set_tx_power_index, |
| 1884 | .cfg_ldo25 = rtw8822c_cfg_ldo25, |
| 1885 | .false_alarm_statistics = rtw8822c_false_alarm_statistics, |
| 1886 | .do_iqk = rtw8822c_do_iqk, |
| 1887 | }; |
| 1888 | |
| 1889 | struct rtw_chip_info rtw8822c_hw_spec = { |
| 1890 | .ops = &rtw8822c_ops, |
| 1891 | .id = RTW_CHIP_TYPE_8822C, |
| 1892 | .fw_name = "rtw88/rtw8822c_fw.bin", |
| 1893 | .tx_pkt_desc_sz = 48, |
| 1894 | .tx_buf_desc_sz = 16, |
| 1895 | .rx_pkt_desc_sz = 24, |
| 1896 | .rx_buf_desc_sz = 8, |
| 1897 | .phy_efuse_size = 512, |
| 1898 | .log_efuse_size = 768, |
| 1899 | .ptct_efuse_size = 124, |
| 1900 | .txff_size = 262144, |
| 1901 | .rxff_size = 24576, |
| 1902 | .txgi_factor = 2, |
| 1903 | .is_pwr_by_rate_dec = false, |
| 1904 | .max_power_index = 0x7f, |
| 1905 | .csi_buf_pg_num = 50, |
| 1906 | .band = RTW_BAND_2G | RTW_BAND_5G, |
| 1907 | .page_size = 128, |
| 1908 | .dig_min = 0x20, |
| 1909 | .ht_supported = true, |
| 1910 | .vht_supported = true, |
| 1911 | .sys_func_en = 0xD8, |
| 1912 | .pwr_on_seq = card_enable_flow_8822c, |
| 1913 | .pwr_off_seq = card_disable_flow_8822c, |
| 1914 | .page_table = page_table_8822c, |
| 1915 | .rqpn_table = rqpn_table_8822c, |
| 1916 | .intf_table = &phy_para_table_8822c, |
| 1917 | .dig = rtw8822c_dig, |
| 1918 | .rf_base_addr = {0x3c00, 0x4c00}, |
| 1919 | .rf_sipi_addr = {0x1808, 0x4108}, |
| 1920 | .mac_tbl = &rtw8822c_mac_tbl, |
| 1921 | .agc_tbl = &rtw8822c_agc_tbl, |
| 1922 | .bb_tbl = &rtw8822c_bb_tbl, |
| 1923 | .rfk_init_tbl = &rtw8822c_array_mp_cal_init_tbl, |
| 1924 | .rf_tbl = {&rtw8822c_rf_a_tbl, &rtw8822c_rf_b_tbl}, |
| 1925 | .rfe_defs = rtw8822c_rfe_defs, |
| 1926 | .rfe_defs_size = ARRAY_SIZE(rtw8822c_rfe_defs), |
| 1927 | }; |
| 1928 | EXPORT_SYMBOL(rtw8822c_hw_spec); |
| 1929 | |
| 1930 | MODULE_FIRMWARE("rtw88/rtw8822c_fw.bin"); |