| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: ISC |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (c) 2010 Broadcom Corporation |
|---|
| 3 | | - * |
|---|
| 4 | | - * Permission to use, copy, modify, and/or distribute this software for any |
|---|
| 5 | | - * purpose with or without fee is hereby granted, provided that the above |
|---|
| 6 | | - * copyright notice and this permission notice appear in all copies. |
|---|
| 7 | | - * |
|---|
| 8 | | - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|---|
| 9 | | - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|---|
| 10 | | - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
|---|
| 11 | | - * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|---|
| 12 | | - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
|---|
| 13 | | - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
|---|
| 14 | | - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|---|
| 15 | 4 | */ |
|---|
| 16 | 5 | |
|---|
| 17 | 6 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
|---|
| .. | .. |
|---|
| 17759 | 17748 | num = 8 * |
|---|
| 17760 | 17749 | (16 * b0[tbl_id - 26] + b1[tbl_id - 26] * idx); |
|---|
| 17761 | 17750 | den = 32768 + a1[tbl_id - 26] * idx; |
|---|
| 17762 | | - pwr_est = max(((4 * num + den / 2) / den), -8); |
|---|
| 17751 | + pwr_est = max(DIV_ROUND_CLOSEST(4 * num, den), -8); |
|---|
| 17763 | 17752 | if (NREV_LT(pi->pubpi.phy_rev, 3)) { |
|---|
| 17764 | 17753 | if (idx <= |
|---|
| 17765 | 17754 | (uint) (31 - idle_tssi[tbl_id - 26] + 1)) |
|---|
| .. | .. |
|---|
| 19044 | 19033 | u32 nphy_adj_noise_var_buf[] = { 0x3ff, 0x3ff }; |
|---|
| 19045 | 19034 | bool isAdjustNoiseVar = false; |
|---|
| 19046 | 19035 | uint numTonesAdjust = 0; |
|---|
| 19047 | | - u32 tempval = 0; |
|---|
| 19048 | 19036 | |
|---|
| 19049 | 19037 | if (NREV_GE(pi->pubpi.phy_rev, 3)) { |
|---|
| 19050 | 19038 | if (pi->phyhang_avoid) |
|---|
| .. | .. |
|---|
| 19150 | 19138 | numTonesAdjust, |
|---|
| 19151 | 19139 | nphy_adj_tone_id_buf, |
|---|
| 19152 | 19140 | nphy_adj_noise_var_buf); |
|---|
| 19153 | | - |
|---|
| 19154 | | - tempval = 0; |
|---|
| 19155 | | - |
|---|
| 19156 | 19141 | } else { |
|---|
| 19157 | 19142 | wlc_phy_adjust_min_noisevar_nphy(pi, 0, NULL, |
|---|
| 19158 | 19143 | NULL); |
|---|
| .. | .. |
|---|
| 20046 | 20031 | break; |
|---|
| 20047 | 20032 | |
|---|
| 20048 | 20033 | default: |
|---|
| 20049 | | - break; |
|---|
| 20034 | + return; |
|---|
| 20050 | 20035 | } |
|---|
| 20051 | 20036 | } |
|---|
| 20052 | 20037 | |
|---|
| .. | .. |
|---|
| 21991 | 21976 | u16 auxADC_rssi_ctrlL, auxADC_rssi_ctrlH; |
|---|
| 21992 | 21977 | s32 auxADC_Vl; |
|---|
| 21993 | 21978 | u16 RfctrlOverride5_save, RfctrlOverride6_save; |
|---|
| 21994 | | - u16 RfctrlMiscReg5_save, RfctrlMiscReg6_save; |
|---|
| 21979 | + u16 RfctrlMiscReg5_save; |
|---|
| 21995 | 21980 | u16 RSSIMultCoef0QPowerDet_save; |
|---|
| 21996 | 21981 | u16 tempsense_Rcal; |
|---|
| 21997 | 21982 | |
|---|
| .. | .. |
|---|
| 22006 | 21991 | RfctrlOverride5_save = read_phy_reg(pi, 0x346); |
|---|
| 22007 | 21992 | RfctrlOverride6_save = read_phy_reg(pi, 0x347); |
|---|
| 22008 | 21993 | RfctrlMiscReg5_save = read_phy_reg(pi, 0x344); |
|---|
| 22009 | | - RfctrlMiscReg6_save = read_phy_reg(pi, 0x345); |
|---|
| 21994 | + read_phy_reg(pi, 0x345); /* RfctrlMiscReg6_save */ |
|---|
| 22010 | 21995 | |
|---|
| 22011 | 21996 | wlc_phy_table_read_nphy(pi, NPHY_TBL_ID_AFECTRL, 1, 0x0A, 16, |
|---|
| 22012 | 21997 | &auxADC_Vmid_save); |
|---|
| .. | .. |
|---|
| 22994 | 22979 | wlc_phy_rssi_compute_nphy(struct brcms_phy *pi, struct d11rxhdr *rxh) |
|---|
| 22995 | 22980 | { |
|---|
| 22996 | 22981 | s16 rxpwr, rxpwr0, rxpwr1; |
|---|
| 22997 | | - s16 phyRx0_l, phyRx2_l; |
|---|
| 22982 | + s16 phyRx2_l; |
|---|
| 22998 | 22983 | |
|---|
| 22999 | 22984 | rxpwr = 0; |
|---|
| 23000 | 22985 | rxpwr0 = rxh->PhyRxStatus_1 & PRXS1_nphy_PWR0_MASK; |
|---|
| .. | .. |
|---|
| 23005 | 22990 | if (rxpwr1 > 127) |
|---|
| 23006 | 22991 | rxpwr1 -= 256; |
|---|
| 23007 | 22992 | |
|---|
| 23008 | | - phyRx0_l = rxh->PhyRxStatus_0 & 0x00ff; |
|---|
| 23009 | 22993 | phyRx2_l = rxh->PhyRxStatus_2 & 0x00ff; |
|---|
| 23010 | 22994 | if (phyRx2_l > 127) |
|---|
| 23011 | 22995 | phyRx2_l -= 256; |
|---|
| .. | .. |
|---|
| 23089 | 23073 | |
|---|
| 23090 | 23074 | theta += rot; |
|---|
| 23091 | 23075 | |
|---|
| 23092 | | - tone_buf[t].q = (s32) FLOAT(tone_buf[t].q * max_val); |
|---|
| 23093 | | - tone_buf[t].i = (s32) FLOAT(tone_buf[t].i * max_val); |
|---|
| 23076 | + tone_buf[t].q = (s32)CORDIC_FLOAT(tone_buf[t].q * max_val); |
|---|
| 23077 | + tone_buf[t].i = (s32)CORDIC_FLOAT(tone_buf[t].i * max_val); |
|---|
| 23094 | 23078 | } |
|---|
| 23095 | 23079 | |
|---|
| 23096 | 23080 | wlc_phy_loadsampletable_nphy(pi, tone_buf, num_samps); |
|---|
| .. | .. |
|---|
| 23108 | 23092 | u16 bb_mult; |
|---|
| 23109 | 23093 | u8 phy_bw, sample_cmd; |
|---|
| 23110 | 23094 | u16 orig_RfseqCoreActv; |
|---|
| 23111 | | - u16 lpf_bw_ctl_override3, lpf_bw_ctl_override4, lpf_bw_ctl_miscreg3, |
|---|
| 23112 | | - lpf_bw_ctl_miscreg4; |
|---|
| 23095 | + u16 lpf_bw_ctl_override3, lpf_bw_ctl_override4; |
|---|
| 23113 | 23096 | |
|---|
| 23114 | 23097 | if (pi->phyhang_avoid) |
|---|
| 23115 | 23098 | wlc_phy_stay_in_carriersearch_nphy(pi, true); |
|---|
| .. | .. |
|---|
| 23122 | 23105 | |
|---|
| 23123 | 23106 | lpf_bw_ctl_override3 = read_phy_reg(pi, 0x342) & (0x1 << 7); |
|---|
| 23124 | 23107 | lpf_bw_ctl_override4 = read_phy_reg(pi, 0x343) & (0x1 << 7); |
|---|
| 23125 | | - if (lpf_bw_ctl_override3 | lpf_bw_ctl_override4) { |
|---|
| 23126 | | - lpf_bw_ctl_miscreg3 = read_phy_reg(pi, 0x340) & |
|---|
| 23127 | | - (0x7 << 8); |
|---|
| 23128 | | - lpf_bw_ctl_miscreg4 = read_phy_reg(pi, 0x341) & |
|---|
| 23129 | | - (0x7 << 8); |
|---|
| 23130 | | - } else { |
|---|
| 23108 | + if (!(lpf_bw_ctl_override3 | lpf_bw_ctl_override4)) { |
|---|
| 23131 | 23109 | wlc_phy_rfctrl_override_nphy_rev7( |
|---|
| 23132 | 23110 | pi, |
|---|
| 23133 | 23111 | (0x1 << 7), |
|---|
| .. | .. |
|---|
| 23137 | 23115 | NPHY_REV7_RFCTRLOVERRIDE_ID1); |
|---|
| 23138 | 23116 | |
|---|
| 23139 | 23117 | pi->nphy_sample_play_lpf_bw_ctl_ovr = true; |
|---|
| 23140 | | - |
|---|
| 23141 | | - lpf_bw_ctl_miscreg3 = read_phy_reg(pi, 0x340) & |
|---|
| 23142 | | - (0x7 << 8); |
|---|
| 23143 | | - lpf_bw_ctl_miscreg4 = read_phy_reg(pi, 0x341) & |
|---|
| 23144 | | - (0x7 << 8); |
|---|
| 23145 | 23118 | } |
|---|
| 23119 | + read_phy_reg(pi, 0x340); /* lpf_bw_ctl_miscreg3 */ |
|---|
| 23120 | + read_phy_reg(pi, 0x341); /* lpf_bw_ctl_miscreg4 */ |
|---|
| 23146 | 23121 | } |
|---|
| 23147 | 23122 | |
|---|
| 23148 | 23123 | if ((pi->nphy_bb_mult_save & BB_MULT_VALID_MASK) == 0) { |
|---|
| .. | .. |
|---|
| 23414 | 23389 | struct nphy_iqcal_params *params) |
|---|
| 23415 | 23390 | { |
|---|
| 23416 | 23391 | u8 k; |
|---|
| 23417 | | - int idx; |
|---|
| 23418 | 23392 | u16 gain_index; |
|---|
| 23419 | 23393 | u8 band_idx = (CHSPEC_IS5G(pi->radio_chanspec) ? 1 : 0); |
|---|
| 23420 | 23394 | |
|---|
| .. | .. |
|---|
| 23447 | 23421 | (target_gain.pga[core_no] << 4) | |
|---|
| 23448 | 23422 | (target_gain.txgm[core_no] << 8)); |
|---|
| 23449 | 23423 | |
|---|
| 23450 | | - idx = -1; |
|---|
| 23451 | 23424 | for (k = 0; k < NPHY_IQCAL_NUMGAINS; k++) { |
|---|
| 23452 | 23425 | if (tbl_iqcal_gainparams_nphy[band_idx][k][0] == |
|---|
| 23453 | | - gain_index) { |
|---|
| 23454 | | - idx = k; |
|---|
| 23426 | + gain_index) |
|---|
| 23455 | 23427 | break; |
|---|
| 23456 | | - } |
|---|
| 23457 | 23428 | } |
|---|
| 23458 | 23429 | |
|---|
| 23459 | 23430 | params->txgm = tbl_iqcal_gainparams_nphy[band_idx][k][1]; |
|---|
| .. | .. |
|---|
| 24715 | 24686 | { |
|---|
| 24716 | 24687 | u16 phy_a1, phy_a2, phy_a3; |
|---|
| 24717 | 24688 | u16 phy_a4, phy_a5; |
|---|
| 24718 | | - bool phy_a6; |
|---|
| 24719 | 24689 | u8 phy_a7, m[2]; |
|---|
| 24720 | 24690 | u32 phy_a8 = 0; |
|---|
| 24721 | 24691 | struct nphy_txgains phy_a9; |
|---|
| .. | .. |
|---|
| 24724 | 24694 | return; |
|---|
| 24725 | 24695 | |
|---|
| 24726 | 24696 | phy_a7 = (core == PHY_CORE_0) ? 1 : 0; |
|---|
| 24727 | | - |
|---|
| 24728 | | - phy_a6 = ((cal_mode == CAL_GCTRL) |
|---|
| 24729 | | - || (cal_mode == CAL_SOFT)) ? true : false; |
|---|
| 24730 | 24697 | |
|---|
| 24731 | 24698 | if (NREV_GE(pi->pubpi.phy_rev, 7)) { |
|---|
| 24732 | 24699 | |
|---|
| .. | .. |
|---|
| 25007 | 24974 | s32 phy_a7, phy_a8; |
|---|
| 25008 | 24975 | u32 phy_a9; |
|---|
| 25009 | 24976 | int phy_a10; |
|---|
| 25010 | | - bool phy_a11 = false; |
|---|
| 25011 | 24977 | int phy_a12; |
|---|
| 25012 | 24978 | u8 phy_a13 = 0; |
|---|
| 25013 | 24979 | u8 phy_a14; |
|---|
| .. | .. |
|---|
| 25075 | 25041 | if (!phy_a6 && (phy_a3 != phy_a5)) { |
|---|
| 25076 | 25042 | if (!phy_a3) |
|---|
| 25077 | 25043 | phy_a12 -= (u8) phy_a1; |
|---|
| 25078 | | - |
|---|
| 25079 | | - phy_a11 = true; |
|---|
| 25080 | 25044 | break; |
|---|
| 25081 | 25045 | } |
|---|
| 25082 | 25046 | |
|---|
| .. | .. |
|---|
| 25090 | 25054 | phy_a12 = phy_a14; |
|---|
| 25091 | 25055 | else |
|---|
| 25092 | 25056 | phy_a12 = phy_a13; |
|---|
| 25093 | | - |
|---|
| 25094 | | - phy_a11 = true; |
|---|
| 25095 | 25057 | break; |
|---|
| 25096 | 25058 | } |
|---|
| 25097 | 25059 | |
|---|
| .. | .. |
|---|
| 25121 | 25083 | if (!phy_a6 && (phy_a3 != phy_a5)) { |
|---|
| 25122 | 25084 | if (!phy_a3) |
|---|
| 25123 | 25085 | phy_a12 -= (u8) phy_a1; |
|---|
| 25124 | | - |
|---|
| 25125 | | - phy_a11 = true; |
|---|
| 25126 | 25086 | break; |
|---|
| 25127 | 25087 | } |
|---|
| 25128 | 25088 | |
|---|
| .. | .. |
|---|
| 25136 | 25096 | phy_a12 = 0; |
|---|
| 25137 | 25097 | else |
|---|
| 25138 | 25098 | phy_a12 = 127; |
|---|
| 25139 | | - |
|---|
| 25140 | | - phy_a11 = true; |
|---|
| 25141 | 25099 | break; |
|---|
| 25142 | 25100 | } |
|---|
| 25143 | 25101 | |
|---|
| .. | .. |
|---|
| 25453 | 25411 | (pi->cal_type_override == |
|---|
| 25454 | 25412 | PHY_PERICAL_FULL) ? true : false; |
|---|
| 25455 | 25413 | |
|---|
| 25456 | | - if ((pi->mphase_cal_phase_id > MPHASE_CAL_STATE_INIT)) { |
|---|
| 25414 | + if (pi->mphase_cal_phase_id > MPHASE_CAL_STATE_INIT) { |
|---|
| 25457 | 25415 | if (pi->nphy_txiqlocal_chanspec != pi->radio_chanspec) |
|---|
| 25458 | 25416 | wlc_phy_cal_perical_mphase_restart(pi); |
|---|
| 25459 | 25417 | } |
|---|
| 25460 | 25418 | |
|---|
| 25461 | | - if ((pi->mphase_cal_phase_id == MPHASE_CAL_STATE_RXCAL)) |
|---|
| 25419 | + if (pi->mphase_cal_phase_id == MPHASE_CAL_STATE_RXCAL) |
|---|
| 25462 | 25420 | wlapi_bmac_write_shm(pi->sh->physhim, M_CTS_DURATION, 10000); |
|---|
| 25463 | 25421 | |
|---|
| 25464 | 25422 | wlapi_suspend_mac_and_wait(pi->sh->physhim); |
|---|
| .. | .. |
|---|
| 27001 | 26959 | NPHY_RXCAL_TONEAMP, 0, cal_type, false); |
|---|
| 27002 | 26960 | |
|---|
| 27003 | 26961 | wlc_phy_rx_iq_est_nphy(pi, est, num_samps, 32, 0); |
|---|
| 27004 | | - i_pwr = (est[rx_core].i_pwr + num_samps / 2) / num_samps; |
|---|
| 27005 | | - q_pwr = (est[rx_core].q_pwr + num_samps / 2) / num_samps; |
|---|
| 26962 | + i_pwr = DIV_ROUND_CLOSEST(est[rx_core].i_pwr, num_samps); |
|---|
| 26963 | + q_pwr = DIV_ROUND_CLOSEST(est[rx_core].q_pwr, num_samps); |
|---|
| 27006 | 26964 | curr_pwr = i_pwr + q_pwr; |
|---|
| 27007 | 26965 | |
|---|
| 27008 | 26966 | switch (gainctrl_dirn) { |
|---|
| .. | .. |
|---|
| 27684 | 27642 | wlc_phy_rx_iq_est_nphy(pi, est, |
|---|
| 27685 | 27643 | num_samps, 32, |
|---|
| 27686 | 27644 | 0); |
|---|
| 27687 | | - i_pwr = (est[rx_core].i_pwr + |
|---|
| 27688 | | - num_samps / 2) / num_samps; |
|---|
| 27689 | | - q_pwr = (est[rx_core].q_pwr + |
|---|
| 27690 | | - num_samps / 2) / num_samps; |
|---|
| 27645 | + i_pwr = DIV_ROUND_CLOSEST(est[rx_core].i_pwr, |
|---|
| 27646 | + num_samps); |
|---|
| 27647 | + q_pwr = DIV_ROUND_CLOSEST(est[rx_core].q_pwr, |
|---|
| 27648 | + num_samps); |
|---|
| 27691 | 27649 | tot_pwr[gain_pass] = i_pwr + q_pwr; |
|---|
| 27692 | 27650 | } else { |
|---|
| 27693 | 27651 | |
|---|