1 /* SPDX-License-Identifier: ISC */
2 /* Copyright (C) 2019 MediaTek Inc. */
3 
4 #ifndef __MT7615_EEPROM_H
5 #define __MT7615_EEPROM_H
6 
7 #include "mt7615.h"
8 
9 enum mt7615_eeprom_field {
10 	MT_EE_CHIP_ID =				0x000,
11 	MT_EE_VERSION =				0x002,
12 	MT_EE_MAC_ADDR =			0x004,
13 	MT_EE_NIC_CONF_0 =			0x034,
14 	MT_EE_NIC_CONF_1 =			0x036,
15 	MT_EE_WIFI_CONF =			0x03e,
16 	MT_EE_TX0_2G_TARGET_POWER =		0x058,
17 	MT_EE_TX0_5G_G0_TARGET_POWER =		0x070,
18 	MT_EE_TX1_5G_G0_TARGET_POWER =		0x098,
19 	MT_EE_EXT_PA_2G_TARGET_POWER =		0x0f2,
20 	MT_EE_EXT_PA_5G_TARGET_POWER =		0x0f3,
21 	MT_EE_TX2_5G_G0_TARGET_POWER =		0x142,
22 	MT_EE_TX3_5G_G0_TARGET_POWER =		0x16a,
23 
24 	__MT_EE_MAX =				0x3bf
25 };
26 
27 #define MT_EE_NIC_CONF_TSSI_2G			BIT(5)
28 #define MT_EE_NIC_CONF_TSSI_5G			BIT(6)
29 
30 #define MT_EE_NIC_WIFI_CONF_BAND_SEL		GENMASK(5, 4)
31 enum mt7615_eeprom_band {
32 	MT_EE_DUAL_BAND,
33 	MT_EE_5GHZ,
34 	MT_EE_2GHZ,
35 	MT_EE_DBDC,
36 };
37 
38 enum mt7615_channel_group {
39 	MT_CH_5G_JAPAN,
40 	MT_CH_5G_UNII_1,
41 	MT_CH_5G_UNII_2A,
42 	MT_CH_5G_UNII_2B,
43 	MT_CH_5G_UNII_2E_1,
44 	MT_CH_5G_UNII_2E_2,
45 	MT_CH_5G_UNII_2E_3,
46 	MT_CH_5G_UNII_3,
47 	__MT_CH_MAX
48 };
49 
50 static inline enum mt7615_channel_group
51 mt7615_get_channel_group(int channel)
52 {
53 	if (channel >= 184 && channel <= 196)
54 		return MT_CH_5G_JAPAN;
55 	if (channel <= 48)
56 		return MT_CH_5G_UNII_1;
57 	if (channel <= 64)
58 		return MT_CH_5G_UNII_2A;
59 	if (channel <= 114)
60 		return MT_CH_5G_UNII_2E_1;
61 	if (channel <= 144)
62 		return MT_CH_5G_UNII_2E_2;
63 	if (channel <= 161)
64 		return MT_CH_5G_UNII_2E_3;
65 	return MT_CH_5G_UNII_3;
66 }
67 
68 static inline bool
69 mt7615_ext_pa_enabled(struct mt7615_dev *dev, enum nl80211_band band)
70 {
71 	u8 *eep = dev->mt76.eeprom.data;
72 
73 	if (band == NL80211_BAND_5GHZ)
74 		return !(eep[MT_EE_NIC_CONF_1 + 1] & MT_EE_NIC_CONF_TSSI_5G);
75 	else
76 		return !(eep[MT_EE_NIC_CONF_1 + 1] & MT_EE_NIC_CONF_TSSI_2G);
77 }
78 
79 #endif
80