1 /* SPDX-License-Identifier: ISC */
2 /*
3  * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
4  */
5 
6 #ifndef __MT76x2_EEPROM_H
7 #define __MT76x2_EEPROM_H
8 
9 #include "../mt76x02_eeprom.h"
10 
11 enum mt76x2_cal_channel_group {
12 	MT_CH_5G_JAPAN,
13 	MT_CH_5G_UNII_1,
14 	MT_CH_5G_UNII_2,
15 	MT_CH_5G_UNII_2E_1,
16 	MT_CH_5G_UNII_2E_2,
17 	MT_CH_5G_UNII_3,
18 	__MT_CH_MAX
19 };
20 
21 struct mt76x2_tx_power_info {
22 	u8 target_power;
23 
24 	s8 delta_bw40;
25 	s8 delta_bw80;
26 
27 	struct {
28 		s8 tssi_slope;
29 		s8 tssi_offset;
30 		s8 target_power;
31 		s8 delta;
32 	} chain[MT_MAX_CHAINS];
33 };
34 
35 struct mt76x2_temp_comp {
36 	u8 temp_25_ref;
37 	int lower_bound; /* J */
38 	int upper_bound; /* J */
39 	unsigned int high_slope; /* J / dB */
40 	unsigned int low_slope; /* J / dB */
41 };
42 
43 void mt76x2_get_rate_power(struct mt76x02_dev *dev, struct mt76_rate_power *t,
44 			   struct ieee80211_channel *chan);
45 void mt76x2_get_power_info(struct mt76x02_dev *dev,
46 			   struct mt76x2_tx_power_info *t,
47 			   struct ieee80211_channel *chan);
48 int mt76x2_get_temp_comp(struct mt76x02_dev *dev, struct mt76x2_temp_comp *t);
49 void mt76x2_read_rx_gain(struct mt76x02_dev *dev);
50 
51 static inline bool
52 mt76x2_has_ext_lna(struct mt76x02_dev *dev)
53 {
54 	u32 val = mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1);
55 
56 	if (dev->mphy.chandef.chan->band == NL80211_BAND_2GHZ)
57 		return val & MT_EE_NIC_CONF_1_LNA_EXT_2G;
58 	else
59 		return val & MT_EE_NIC_CONF_1_LNA_EXT_5G;
60 }
61 
62 static inline bool
63 mt76x2_temp_tx_alc_enabled(struct mt76x02_dev *dev)
64 {
65 	u16 val;
66 
67 	val = mt76x02_eeprom_get(dev, MT_EE_TX_POWER_EXT_PA_5G);
68 	if (!(val & BIT(15)))
69 		return false;
70 
71 	return mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1) &
72 	       MT_EE_NIC_CONF_1_TEMP_TX_ALC;
73 }
74 
75 static inline bool
76 mt76x2_tssi_enabled(struct mt76x02_dev *dev)
77 {
78 	return !mt76x2_temp_tx_alc_enabled(dev) &&
79 	       (mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1) &
80 		MT_EE_NIC_CONF_1_TX_ALC_EN);
81 }
82 
83 #endif
84