Lines Matching +full:tx +full:- +full:d +full:- +full:cal
1 // SPDX-License-Identifier: GPL-2.0-only
3 * (c) Copyright 2002-2010, Ralink Technology, Inc.
26 if (test_bit(MT76_REMOVED, &dev->mphy.state)) in mt76x0_rf_csr_wr()
27 return -ENODEV; in mt76x0_rf_csr_wr()
33 return -EINVAL; in mt76x0_rf_csr_wr()
35 mutex_lock(&dev->phy_mutex); in mt76x0_rf_csr_wr()
38 ret = -ETIMEDOUT; in mt76x0_rf_csr_wr()
50 mutex_unlock(&dev->phy_mutex); in mt76x0_rf_csr_wr()
53 dev_err(dev->mt76.dev, "Error: RF write %d:%d failed:%d!!\n", in mt76x0_rf_csr_wr()
61 int ret = -ETIMEDOUT; in mt76x0_rf_csr_rr()
65 if (test_bit(MT76_REMOVED, &dev->mphy.state)) in mt76x0_rf_csr_rr()
66 return -ENODEV; in mt76x0_rf_csr_rr()
72 return -EINVAL; in mt76x0_rf_csr_rr()
74 mutex_lock(&dev->phy_mutex); in mt76x0_rf_csr_rr()
93 mutex_unlock(&dev->phy_mutex); in mt76x0_rf_csr_rr()
96 dev_err(dev->mt76.dev, "Error: RF read %d:%d failed:%d!!\n", in mt76x0_rf_csr_rr()
105 if (mt76_is_usb(&dev->mt76)) { in mt76x0_rf_wr()
112 &dev->mphy.state)); in mt76x0_rf_wr()
124 if (mt76_is_usb(&dev->mt76)) { in mt76x0_rf_rr()
130 &dev->mphy.state)); in mt76x0_rf_rr()
172 while (n-- > 0) { in mt76x0_phy_rf_csr_wr_rp()
173 mt76x0_rf_csr_wr(dev, data->reg, data->value); in mt76x0_phy_rf_csr_wr_rp()
179 if (mt76_is_mmio(&dev->mt76)) \
194 } while (--i); in mt76x0_phy_wait_bbp_ready()
197 dev_err(dev->mt76.dev, "Error: BBP is not ready\n"); in mt76x0_phy_wait_bbp_ready()
198 return -EIO; in mt76x0_phy_wait_bbp_ready()
201 dev_dbg(dev->mt76.dev, "BBP version %08x\n", val); in mt76x0_phy_wait_bbp_ready()
260 mt76x0_rf_wr(dev, MT_RF(0, 37), freq_item->pllR37); in mt76x0_phy_set_chan_rf_params()
261 mt76x0_rf_wr(dev, MT_RF(0, 36), freq_item->pllR36); in mt76x0_phy_set_chan_rf_params()
262 mt76x0_rf_wr(dev, MT_RF(0, 35), freq_item->pllR35); in mt76x0_phy_set_chan_rf_params()
263 mt76x0_rf_wr(dev, MT_RF(0, 34), freq_item->pllR34); in mt76x0_phy_set_chan_rf_params()
264 mt76x0_rf_wr(dev, MT_RF(0, 33), freq_item->pllR33); in mt76x0_phy_set_chan_rf_params()
267 freq_item->pllR32_b7b5); in mt76x0_phy_set_chan_rf_params()
269 /* R32<4:0> pll_den: (Denomina - 8) */ in mt76x0_phy_set_chan_rf_params()
271 freq_item->pllR32_b4b0); in mt76x0_phy_set_chan_rf_params()
275 freq_item->pllR31_b7b5); in mt76x0_phy_set_chan_rf_params()
279 freq_item->pllR31_b4b0); in mt76x0_phy_set_chan_rf_params()
290 freq_item->pllR30_b7); in mt76x0_phy_set_chan_rf_params()
296 freq_item->pllR30_b6b2); in mt76x0_phy_set_chan_rf_params()
300 freq_item->pllR30_b1 << 1); in mt76x0_phy_set_chan_rf_params()
304 freq_item->pll_n & 0xff); in mt76x0_phy_set_chan_rf_params()
307 (freq_item->pll_n >> 8) & 0x1); in mt76x0_phy_set_chan_rf_params()
311 freq_item->pllR28_b7b6); in mt76x0_phy_set_chan_rf_params()
315 freq_item->pllR28_b5b4); in mt76x0_phy_set_chan_rf_params()
319 freq_item->pllR28_b3b2); in mt76x0_phy_set_chan_rf_params()
323 freq_item->pll_sdm_k & 0xff); in mt76x0_phy_set_chan_rf_params()
325 (freq_item->pll_sdm_k >> 8) & 0xff); in mt76x0_phy_set_chan_rf_params()
328 (freq_item->pll_sdm_k >> 16) & 0x3); in mt76x0_phy_set_chan_rf_params()
332 freq_item->pllR24_b1b0); in mt76x0_phy_set_chan_rf_params()
384 /* Set Atten mode = 2 For G band, Disable Tx Inc dcoc. */ in mt76x0_phy_set_chan_rf_params()
391 * For Ext A band, Disable Tx Inc dcoc Cal. in mt76x0_phy_set_chan_rf_params()
406 const struct mt76_reg_pair *pair = &item->reg_pair; in mt76x0_phy_set_chan_bbp_params()
408 if ((rf_bw_band & item->bw_band) != rf_bw_band) in mt76x0_phy_set_chan_bbp_params()
411 if (pair->reg == MT_BBP(AGC, 8)) { in mt76x0_phy_set_chan_bbp_params()
412 u32 val = pair->value; in mt76x0_phy_set_chan_bbp_params()
416 gain -= dev->cal.rx.lna_gain * 2; in mt76x0_phy_set_chan_bbp_params()
419 mt76_wr(dev, pair->reg, val); in mt76x0_phy_set_chan_bbp_params()
421 mt76_wr(dev, pair->reg, pair->value); in mt76x0_phy_set_chan_bbp_params()
450 if (dev->mphy.cap.has_2ghz) in mt76x0_phy_ant_select()
454 if (dev->mphy.cap.has_5ghz) { in mt76x0_phy_ant_select()
505 struct ieee80211_channel *chan = dev->mphy.chandef.chan; in mt76x0_phy_tssi_dc_calibrate()
508 if (chan->band == NL80211_BAND_5GHZ) in mt76x0_phy_tssi_dc_calibrate()
520 val = (chan->band == NL80211_BAND_5GHZ) ? 0x80055 : 0x80050; in mt76x0_phy_tssi_dc_calibrate()
523 /* enable TX with DAC0 input */ in mt76x0_phy_tssi_dc_calibrate()
527 dev->cal.tssi_dc = mt76_rr(dev, MT_BBP(CORE, 35)) & 0xff; in mt76x0_phy_tssi_dc_calibrate()
531 /* stop TX */ in mt76x0_phy_tssi_dc_calibrate()
538 if (chan->band == NL80211_BAND_5GHZ) in mt76x0_phy_tssi_dc_calibrate()
546 struct ieee80211_channel *chan = dev->mphy.chandef.chan; in mt76x0_phy_tssi_adc_calibrate()
549 val = (chan->band == NL80211_BAND_5GHZ) ? 0x80055 : 0x80050; in mt76x0_phy_tssi_adc_calibrate()
554 return -ETIMEDOUT; in mt76x0_phy_tssi_adc_calibrate()
558 if (chan->band == NL80211_BAND_5GHZ) in mt76x0_phy_tssi_adc_calibrate()
598 *target_power = cur_power + dev->rate_power.cck[tx_rate]; in mt76x0_phy_get_target_power()
632 return -EINVAL; in mt76x0_phy_get_target_power()
635 *target_power = cur_power + dev->rate_power.ofdm[index]; in mt76x0_phy_get_target_power()
643 return -EINVAL; in mt76x0_phy_get_target_power()
647 *target_power += dev->rate_power.vht[tx_rate - 8]; in mt76x0_phy_get_target_power()
649 *target_power += dev->rate_power.ht[tx_rate]; in mt76x0_phy_get_target_power()
657 return -EINVAL; in mt76x0_phy_get_target_power()
659 *target_power = cur_power + dev->rate_power.ht[tx_rate]; in mt76x0_phy_get_target_power()
671 s16 exp = -4; in mt76x0_phy_lin2db()
675 if (--exp < -20) in mt76x0_phy_lin2db()
676 return -10000; in mt76x0_phy_lin2db()
681 return -10000; in mt76x0_phy_lin2db()
686 data = mantissa + (mantissa >> 3) + (mantissa >> 4) - 38400; in mt76x0_phy_lin2db()
688 data = mantissa - (mantissa >> 3) - (mantissa >> 6) - 23040; in mt76x0_phy_lin2db()
701 struct ieee80211_channel *chan = dev->mphy.chandef.chan; in mt76x0_phy_get_delta_power()
707 if (chan->band == NL80211_BAND_5GHZ) { in mt76x0_phy_get_delta_power()
717 if (chan->hw_value <= bound[i] || !bound[i]) in mt76x0_phy_get_delta_power()
725 tssi_offset -= BIT(8); in mt76x0_phy_get_delta_power()
731 tssi_offset -= BIT(8); in mt76x0_phy_get_delta_power()
737 if (chan->band == NL80211_BAND_2GHZ) in mt76x0_phy_get_delta_power()
749 if (is_mt7630(dev) && mt76_is_mmio(&dev->mt76)) { in mt76x0_phy_get_delta_power()
764 tssi_target -= 49152; /* -6db * 8192 */ in mt76x0_phy_get_delta_power()
767 tssi_target -= 98304; /* -12db * 8192 */ in mt76x0_phy_get_delta_power()
776 tssi_db = mt76x0_phy_lin2db(ltssi - dev->cal.tssi_dc) * tssi_slope; in mt76x0_phy_get_delta_power()
777 if (chan->band == NL80211_BAND_5GHZ) { in mt76x0_phy_get_delta_power()
778 tssi_db += ((tssi_offset - 50) << 10); /* offset s4.3 */ in mt76x0_phy_get_delta_power()
779 tssi_target -= tssi_db; in mt76x0_phy_get_delta_power()
786 tssi_target -= tssi_db; in mt76x0_phy_get_delta_power()
787 /* upper-lower saturate */ in mt76x0_phy_get_delta_power()
789 ((ltssi - dev->cal.tssi_dc) < 1 && tssi_target < 0)) { in mt76x0_phy_get_delta_power()
794 if ((dev->cal.tssi_target ^ tssi_target) < 0 && in mt76x0_phy_get_delta_power()
795 dev->cal.tssi_target > -4096 && dev->cal.tssi_target < 4096 && in mt76x0_phy_get_delta_power()
796 tssi_target > -4096 && tssi_target < 4096) { in mt76x0_phy_get_delta_power()
798 tssi_target + dev->cal.tssi_target > 0) || in mt76x0_phy_get_delta_power()
800 tssi_target + dev->cal.tssi_target <= 0)) in mt76x0_phy_get_delta_power()
803 dev->cal.tssi_target = tssi_target; in mt76x0_phy_get_delta_power()
805 dev->cal.tssi_target = tssi_target; in mt76x0_phy_get_delta_power()
812 tssi_target -= 2048; in mt76x0_phy_get_delta_power()
817 ret -= BIT(6); in mt76x0_phy_get_delta_power()
821 return max_t(int, -32, ret); in mt76x0_phy_get_delta_power()
846 struct mt76x02_rate_power *t = &dev->rate_power; in mt76x0_phy_set_txpower()
849 mt76x0_get_tx_power_per_rate(dev, dev->mphy.chandef.chan, t); in mt76x0_phy_set_txpower()
850 mt76x0_get_power_info(dev, dev->mphy.chandef.chan, &info); in mt76x0_phy_set_txpower()
853 mt76x02_limit_rate_power(t, dev->txpower_conf); in mt76x0_phy_set_txpower()
854 dev->mphy.txpower_cur = mt76x02_get_max_rate_power(t); in mt76x0_phy_set_txpower()
855 mt76x02_add_rate_power_offset(t, -info); in mt76x0_phy_set_txpower()
857 dev->target_power = info; in mt76x0_phy_set_txpower()
863 struct ieee80211_channel *chan = dev->mphy.chandef.chan; in mt76x0_phy_calibrate()
864 int is_5ghz = (chan->band == NL80211_BAND_5GHZ) ? 1 : 0; in mt76x0_phy_calibrate()
872 mt76x02_mcu_calibrate(dev, MCU_CAL_VCO, chan->hw_value); in mt76x0_phy_calibrate()
893 if (chan->hw_value < 100) in mt76x0_phy_calibrate()
895 else if (chan->hw_value < 140) in mt76x0_phy_calibrate()
938 bool scan = test_bit(MT76_SCANNING, &dev->mphy.state); in mt76x0_phy_set_channel()
944 freq = chandef->chan->center_freq; in mt76x0_phy_set_channel()
945 freq1 = chandef->center_freq1; in mt76x0_phy_set_channel()
946 channel = chandef->chan->hw_value; in mt76x0_phy_set_channel()
949 switch (chandef->width) { in mt76x0_phy_set_channel()
955 channel += 2 - ch_group_index * 4; in mt76x0_phy_set_channel()
959 ch_group_index = (freq - freq1 + 30) / 20; in mt76x0_phy_set_channel()
962 channel += 6 - ch_group_index * 4; in mt76x0_phy_set_channel()
971 if (mt76_is_usb(&dev->mt76)) { in mt76x0_phy_set_channel()
972 mt76x0_phy_bbp_set_bw(dev, chandef->width); in mt76x0_phy_set_channel()
974 if (chandef->width == NL80211_CHAN_WIDTH_80 || in mt76x0_phy_set_channel()
975 chandef->width == NL80211_CHAN_WIDTH_40) in mt76x0_phy_set_channel()
981 mt76x02_phy_set_bw(dev, chandef->width, ch_group_index); in mt76x0_phy_set_channel()
982 mt76x02_phy_set_band(dev, chandef->chan->band, in mt76x0_phy_set_channel()
993 mt76x0_phy_set_band(dev, chandef->chan->band); in mt76x0_phy_set_channel()
996 /* set Japan Tx filter at channel 14 */ in mt76x0_phy_set_channel()
1014 ieee80211_queue_delayed_work(dev->mt76.hw, &dev->cal_work, in mt76x0_phy_set_channel()
1038 val = (35 * (val - dev->cal.rx.temp_offset)) / 10 + 25; in mt76x0_phy_temp_sensor()
1040 if (abs(val - dev->cal.temp_vco) > 20) { in mt76x0_phy_temp_sensor()
1042 dev->mphy.chandef.chan->hw_value); in mt76x0_phy_temp_sensor()
1043 dev->cal.temp_vco = val; in mt76x0_phy_temp_sensor()
1045 if (abs(val - dev->cal.temp) > 30) { in mt76x0_phy_temp_sensor()
1047 dev->cal.temp = val; in mt76x0_phy_temp_sensor()
1058 u8 gain = dev->cal.agc_gain_cur[0] - dev->cal.agc_gain_adjust; in mt76x0_phy_set_gain_val()
1062 if ((dev->mphy.chandef.chan->flags & IEEE80211_CHAN_RADAR) && in mt76x0_phy_set_gain_val()
1074 dev->cal.avg_rssi_all = mt76_get_min_avg_rssi(&dev->mt76, false); in mt76x0_phy_update_channel_gain()
1075 if (!dev->cal.avg_rssi_all) in mt76x0_phy_update_channel_gain()
1076 dev->cal.avg_rssi_all = -75; in mt76x0_phy_update_channel_gain()
1078 low_gain = (dev->cal.avg_rssi_all > mt76x02_get_rssi_gain_thresh(dev)) + in mt76x0_phy_update_channel_gain()
1079 (dev->cal.avg_rssi_all > mt76x02_get_low_rssi_gain_thresh(dev)); in mt76x0_phy_update_channel_gain()
1081 gain_change = dev->cal.low_gain < 0 || in mt76x0_phy_update_channel_gain()
1082 (dev->cal.low_gain & 2) ^ (low_gain & 2); in mt76x0_phy_update_channel_gain()
1083 dev->cal.low_gain = low_gain; in mt76x0_phy_update_channel_gain()
1091 dev->cal.agc_gain_adjust = (low_gain == 2) ? 0 : 10; in mt76x0_phy_update_channel_gain()
1094 dev->cal.agc_gain_cur[0] = dev->cal.agc_gain_init[0] - gain_delta; in mt76x0_phy_update_channel_gain()
1112 ieee80211_queue_delayed_work(dev->mt76.hw, &dev->cal_work, in mt76x0_phy_calibration_work()
1127 if (mt76_is_mmio(&dev->mt76)) { in mt76x0_rf_patch_reg_array()
1171 if (item->bw_band == RF_BW_20) in mt76x0_phy_rf_init()
1172 mt76x0_rf_wr(dev, item->rf_bank_reg, item->value); in mt76x0_phy_rf_init()
1173 else if (((RF_G_BAND | RF_BW_20) & item->bw_band) == in mt76x0_phy_rf_init()
1175 mt76x0_rf_wr(dev, item->rf_bank_reg, item->value); in mt76x0_phy_rf_init()
1191 min_t(u8, dev->cal.rx.freq_offset, 0xbf)); in mt76x0_phy_rf_init()
1194 /* Reset procedure DAC during power-up: in mt76x0_phy_rf_init()
1195 * - set B0.R73<7> in mt76x0_phy_rf_init()
1196 * - clear B0.R73<7> in mt76x0_phy_rf_init()
1197 * - set B0.R73<7> in mt76x0_phy_rf_init()
1209 INIT_DELAYED_WORK(&dev->cal_work, mt76x0_phy_calibration_work); in mt76x0_phy_init()