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 
10 #define MT7615_EEPROM_DCOC_OFFSET		MT7615_EEPROM_SIZE
11 #define MT7615_EEPROM_DCOC_SIZE			256
12 #define MT7615_EEPROM_DCOC_COUNT		34
13 
14 #define MT7615_EEPROM_TXDPD_OFFSET		(MT7615_EEPROM_SIZE + \
15 						 MT7615_EEPROM_DCOC_COUNT * \
16 						 MT7615_EEPROM_DCOC_SIZE)
17 #define MT7615_EEPROM_TXDPD_SIZE		216
18 #define MT7615_EEPROM_TXDPD_COUNT		(44 + 3)
19 
20 #define MT7615_EEPROM_FULL_SIZE			(MT7615_EEPROM_TXDPD_OFFSET + \
21 						 MT7615_EEPROM_TXDPD_COUNT * \
22 						 MT7615_EEPROM_TXDPD_SIZE)
23 
24 enum mt7615_eeprom_field {
25 	MT_EE_CHIP_ID =				0x000,
26 	MT_EE_VERSION =				0x002,
27 	MT_EE_MAC_ADDR =			0x004,
28 	MT_EE_NIC_CONF_0 =			0x034,
29 	MT_EE_NIC_CONF_1 =			0x036,
30 	MT_EE_WIFI_CONF =			0x03e,
31 	MT_EE_CALDATA_FLASH =			0x052,
32 	MT_EE_TX0_2G_TARGET_POWER =		0x058,
33 	MT_EE_TX0_5G_G0_TARGET_POWER =		0x070,
34 	MT7663_EE_5G_RATE_POWER =		0x089,
35 	MT_EE_TX1_5G_G0_TARGET_POWER =		0x098,
36 	MT_EE_2G_RATE_POWER =			0x0be,
37 	MT_EE_5G_RATE_POWER =			0x0d5,
38 	MT7663_EE_TX0_2G_TARGET_POWER =		0x0e3,
39 	MT_EE_EXT_PA_2G_TARGET_POWER =		0x0f2,
40 	MT_EE_EXT_PA_5G_TARGET_POWER =		0x0f3,
41 	MT_EE_TX2_5G_G0_TARGET_POWER =		0x142,
42 	MT_EE_TX3_5G_G0_TARGET_POWER =		0x16a,
43 	MT7663_EE_HW_CONF1 =			0x1b0,
44 	MT7663_EE_TX0_5G_G0_TARGET_POWER =	0x245,
45 	MT7663_EE_TX1_5G_G0_TARGET_POWER =	0x2b5,
46 
47 	MT7615_EE_MAX =				0x3bf,
48 	MT7622_EE_MAX =				0x3db,
49 	MT7663_EE_MAX =				0x400,
50 };
51 
52 #define MT_EE_RATE_POWER_MASK			GENMASK(5, 0)
53 #define MT_EE_RATE_POWER_SIGN			BIT(6)
54 #define MT_EE_RATE_POWER_EN			BIT(7)
55 
56 #define MT_EE_CALDATA_FLASH_TX_DPD		BIT(0)
57 #define MT_EE_CALDATA_FLASH_RX_CAL		BIT(1)
58 
59 #define MT_EE_NIC_CONF_TX_MASK			GENMASK(7, 4)
60 #define MT_EE_NIC_CONF_RX_MASK			GENMASK(3, 0)
61 
62 #define MT_EE_HW_CONF1_TX_MASK			GENMASK(2, 0)
63 
64 #define MT_EE_NIC_CONF_TSSI_2G			BIT(5)
65 #define MT_EE_NIC_CONF_TSSI_5G			BIT(6)
66 
67 #define MT_EE_NIC_WIFI_CONF_BAND_SEL		GENMASK(5, 4)
68 enum mt7615_eeprom_band {
69 	MT_EE_DUAL_BAND,
70 	MT_EE_5GHZ,
71 	MT_EE_2GHZ,
72 	MT_EE_DBDC,
73 };
74 
75 enum mt7615_channel_group {
76 	MT_CH_5G_JAPAN,
77 	MT_CH_5G_UNII_1,
78 	MT_CH_5G_UNII_2A,
79 	MT_CH_5G_UNII_2B,
80 	MT_CH_5G_UNII_2E_1,
81 	MT_CH_5G_UNII_2E_2,
82 	MT_CH_5G_UNII_2E_3,
83 	MT_CH_5G_UNII_3,
84 	__MT_CH_MAX
85 };
86 
87 static inline enum mt7615_channel_group
88 mt7615_get_channel_group(int channel)
89 {
90 	if (channel >= 184 && channel <= 196)
91 		return MT_CH_5G_JAPAN;
92 	if (channel <= 48)
93 		return MT_CH_5G_UNII_1;
94 	if (channel <= 64)
95 		return MT_CH_5G_UNII_2A;
96 	if (channel <= 114)
97 		return MT_CH_5G_UNII_2E_1;
98 	if (channel <= 144)
99 		return MT_CH_5G_UNII_2E_2;
100 	if (channel <= 161)
101 		return MT_CH_5G_UNII_2E_3;
102 	return MT_CH_5G_UNII_3;
103 }
104 
105 static inline bool
106 mt7615_ext_pa_enabled(struct mt7615_dev *dev, enum nl80211_band band)
107 {
108 	u8 *eep = dev->mt76.eeprom.data;
109 
110 	if (band == NL80211_BAND_5GHZ)
111 		return !(eep[MT_EE_NIC_CONF_1 + 1] & MT_EE_NIC_CONF_TSSI_5G);
112 	else
113 		return !(eep[MT_EE_NIC_CONF_1 + 1] & MT_EE_NIC_CONF_TSSI_2G);
114 }
115 
116 #endif
117