10e3d6777SRyder Lee /* SPDX-License-Identifier: ISC */
21613c621SLorenzo Bianconi /*
31613c621SLorenzo Bianconi * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
41613c621SLorenzo Bianconi */
51613c621SLorenzo Bianconi
61613c621SLorenzo Bianconi #ifndef __MT76x2_EEPROM_H
71613c621SLorenzo Bianconi #define __MT76x2_EEPROM_H
81613c621SLorenzo Bianconi
91613c621SLorenzo Bianconi #include "../mt76x02_eeprom.h"
101613c621SLorenzo Bianconi
111613c621SLorenzo Bianconi enum mt76x2_cal_channel_group {
121613c621SLorenzo Bianconi MT_CH_5G_JAPAN,
131613c621SLorenzo Bianconi MT_CH_5G_UNII_1,
141613c621SLorenzo Bianconi MT_CH_5G_UNII_2,
151613c621SLorenzo Bianconi MT_CH_5G_UNII_2E_1,
161613c621SLorenzo Bianconi MT_CH_5G_UNII_2E_2,
171613c621SLorenzo Bianconi MT_CH_5G_UNII_3,
181613c621SLorenzo Bianconi __MT_CH_MAX
191613c621SLorenzo Bianconi };
201613c621SLorenzo Bianconi
211613c621SLorenzo Bianconi struct mt76x2_tx_power_info {
221613c621SLorenzo Bianconi u8 target_power;
231613c621SLorenzo Bianconi
241613c621SLorenzo Bianconi s8 delta_bw40;
251613c621SLorenzo Bianconi s8 delta_bw80;
261613c621SLorenzo Bianconi
271613c621SLorenzo Bianconi struct {
281613c621SLorenzo Bianconi s8 tssi_slope;
291613c621SLorenzo Bianconi s8 tssi_offset;
301613c621SLorenzo Bianconi s8 target_power;
311613c621SLorenzo Bianconi s8 delta;
321613c621SLorenzo Bianconi } chain[MT_MAX_CHAINS];
331613c621SLorenzo Bianconi };
341613c621SLorenzo Bianconi
351613c621SLorenzo Bianconi struct mt76x2_temp_comp {
361613c621SLorenzo Bianconi u8 temp_25_ref;
371613c621SLorenzo Bianconi int lower_bound; /* J */
381613c621SLorenzo Bianconi int upper_bound; /* J */
391613c621SLorenzo Bianconi unsigned int high_slope; /* J / dB */
401613c621SLorenzo Bianconi unsigned int low_slope; /* J / dB */
411613c621SLorenzo Bianconi };
421613c621SLorenzo Bianconi
43*b376d963SFelix Fietkau void mt76x2_get_rate_power(struct mt76x02_dev *dev, struct mt76x02_rate_power *t,
441613c621SLorenzo Bianconi struct ieee80211_channel *chan);
45e40803f2SLorenzo Bianconi void mt76x2_get_power_info(struct mt76x02_dev *dev,
461613c621SLorenzo Bianconi struct mt76x2_tx_power_info *t,
471613c621SLorenzo Bianconi struct ieee80211_channel *chan);
48e40803f2SLorenzo Bianconi int mt76x2_get_temp_comp(struct mt76x02_dev *dev, struct mt76x2_temp_comp *t);
49e40803f2SLorenzo Bianconi void mt76x2_read_rx_gain(struct mt76x02_dev *dev);
501613c621SLorenzo Bianconi
511613c621SLorenzo Bianconi static inline bool
mt76x2_has_ext_lna(struct mt76x02_dev * dev)52e40803f2SLorenzo Bianconi mt76x2_has_ext_lna(struct mt76x02_dev *dev)
531613c621SLorenzo Bianconi {
5426a9daa6SLorenzo Bianconi u32 val = mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1);
551613c621SLorenzo Bianconi
5696747a51SFelix Fietkau if (dev->mphy.chandef.chan->band == NL80211_BAND_2GHZ)
571613c621SLorenzo Bianconi return val & MT_EE_NIC_CONF_1_LNA_EXT_2G;
581613c621SLorenzo Bianconi else
591613c621SLorenzo Bianconi return val & MT_EE_NIC_CONF_1_LNA_EXT_5G;
601613c621SLorenzo Bianconi }
611613c621SLorenzo Bianconi
624afeb396SLorenzo Bianconi static inline bool
mt76x2_temp_tx_alc_enabled(struct mt76x02_dev * dev)634afeb396SLorenzo Bianconi mt76x2_temp_tx_alc_enabled(struct mt76x02_dev *dev)
644afeb396SLorenzo Bianconi {
654afeb396SLorenzo Bianconi u16 val;
664afeb396SLorenzo Bianconi
674afeb396SLorenzo Bianconi val = mt76x02_eeprom_get(dev, MT_EE_TX_POWER_EXT_PA_5G);
684afeb396SLorenzo Bianconi if (!(val & BIT(15)))
694afeb396SLorenzo Bianconi return false;
704afeb396SLorenzo Bianconi
714afeb396SLorenzo Bianconi return mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1) &
724afeb396SLorenzo Bianconi MT_EE_NIC_CONF_1_TEMP_TX_ALC;
734afeb396SLorenzo Bianconi }
744afeb396SLorenzo Bianconi
754afeb396SLorenzo Bianconi static inline bool
mt76x2_tssi_enabled(struct mt76x02_dev * dev)764afeb396SLorenzo Bianconi mt76x2_tssi_enabled(struct mt76x02_dev *dev)
774afeb396SLorenzo Bianconi {
784afeb396SLorenzo Bianconi return !mt76x2_temp_tx_alc_enabled(dev) &&
794afeb396SLorenzo Bianconi (mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1) &
804afeb396SLorenzo Bianconi MT_EE_NIC_CONF_1_TX_ALC_EN);
814afeb396SLorenzo Bianconi }
824afeb396SLorenzo Bianconi
831613c621SLorenzo Bianconi #endif
84