Linux-libre 5.3.12-gnu
[librecmc/linux-libre.git] / drivers / net / wireless / mediatek / mt76 / mt76x2 / eeprom.h
1 /*
2  * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
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
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #ifndef __MT76x2_EEPROM_H
18 #define __MT76x2_EEPROM_H
19
20 #include "../mt76x02_eeprom.h"
21
22 enum mt76x2_cal_channel_group {
23         MT_CH_5G_JAPAN,
24         MT_CH_5G_UNII_1,
25         MT_CH_5G_UNII_2,
26         MT_CH_5G_UNII_2E_1,
27         MT_CH_5G_UNII_2E_2,
28         MT_CH_5G_UNII_3,
29         __MT_CH_MAX
30 };
31
32 struct mt76x2_tx_power_info {
33         u8 target_power;
34
35         s8 delta_bw40;
36         s8 delta_bw80;
37
38         struct {
39                 s8 tssi_slope;
40                 s8 tssi_offset;
41                 s8 target_power;
42                 s8 delta;
43         } chain[MT_MAX_CHAINS];
44 };
45
46 struct mt76x2_temp_comp {
47         u8 temp_25_ref;
48         int lower_bound; /* J */
49         int upper_bound; /* J */
50         unsigned int high_slope; /* J / dB */
51         unsigned int low_slope; /* J / dB */
52 };
53
54 void mt76x2_get_rate_power(struct mt76x02_dev *dev, struct mt76_rate_power *t,
55                            struct ieee80211_channel *chan);
56 void mt76x2_get_power_info(struct mt76x02_dev *dev,
57                            struct mt76x2_tx_power_info *t,
58                            struct ieee80211_channel *chan);
59 int mt76x2_get_temp_comp(struct mt76x02_dev *dev, struct mt76x2_temp_comp *t);
60 void mt76x2_read_rx_gain(struct mt76x02_dev *dev);
61
62 static inline bool
63 mt76x2_has_ext_lna(struct mt76x02_dev *dev)
64 {
65         u32 val = mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1);
66
67         if (dev->mt76.chandef.chan->band == NL80211_BAND_2GHZ)
68                 return val & MT_EE_NIC_CONF_1_LNA_EXT_2G;
69         else
70                 return val & MT_EE_NIC_CONF_1_LNA_EXT_5G;
71 }
72
73 static inline bool
74 mt76x2_temp_tx_alc_enabled(struct mt76x02_dev *dev)
75 {
76         u16 val;
77
78         val = mt76x02_eeprom_get(dev, MT_EE_TX_POWER_EXT_PA_5G);
79         if (!(val & BIT(15)))
80                 return false;
81
82         return mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1) &
83                MT_EE_NIC_CONF_1_TEMP_TX_ALC;
84 }
85
86 static inline bool
87 mt76x2_tssi_enabled(struct mt76x02_dev *dev)
88 {
89         return !mt76x2_temp_tx_alc_enabled(dev) &&
90                (mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1) &
91                 MT_EE_NIC_CONF_1_TX_ALC_EN);
92 }
93
94 #endif