1 /* SPDX-License-Identifier: ISC */
2 /* Copyright (C) 2020 MediaTek Inc. */
3 
4 #ifndef __MT7915_EEPROM_H
5 #define __MT7915_EEPROM_H
6 
7 #include "mt7915.h"
8 
9 struct cal_data {
10 	u8 count;
11 	u16 offset[60];
12 };
13 
14 enum mt7915_eeprom_field {
15 	MT_EE_CHIP_ID =		0x000,
16 	MT_EE_VERSION =		0x002,
17 	MT_EE_MAC_ADDR =	0x004,
18 	MT_EE_MAC_ADDR2 =	0x00a,
19 	MT_EE_DDIE_FT_VERSION =	0x050,
20 	MT_EE_DO_PRE_CAL =	0x062,
21 	MT_EE_WIFI_CONF =	0x190,
22 	MT_EE_RATE_DELTA_2G =	0x252,
23 	MT_EE_RATE_DELTA_5G =	0x29d,
24 	MT_EE_TX0_POWER_2G =	0x2fc,
25 	MT_EE_TX0_POWER_5G =	0x34b,
26 	MT_EE_RATE_DELTA_2G_V2 = 0x7d3,
27 	MT_EE_RATE_DELTA_5G_V2 = 0x81e,
28 	MT_EE_RATE_DELTA_6G_V2 = 0x884, /* 6g fields only appear in eeprom v2 */
29 	MT_EE_TX0_POWER_2G_V2 =	0x441,
30 	MT_EE_TX0_POWER_5G_V2 =	0x445,
31 	MT_EE_TX0_POWER_6G_V2 =	0x465,
32 	MT_EE_ADIE_FT_VERSION =	0x9a0,
33 
34 	__MT_EE_MAX =		0xe00,
35 	__MT_EE_MAX_V2 =	0x1000,
36 	/* 0xe10 ~ 0x5780 used to save group cal data */
37 	MT_EE_PRECAL =		0xe10,
38 	MT_EE_PRECAL_V2 =	0x1010
39 };
40 
41 #define MT_EE_WIFI_CAL_GROUP			BIT(0)
42 #define MT_EE_WIFI_CAL_DPD			GENMASK(2, 1)
43 #define MT_EE_CAL_UNIT				1024
44 #define MT_EE_CAL_GROUP_SIZE			(49 * MT_EE_CAL_UNIT + 16)
45 #define MT_EE_CAL_DPD_SIZE			(54 * MT_EE_CAL_UNIT)
46 
47 #define MT_EE_WIFI_CONF0_TX_PATH		GENMASK(2, 0)
48 #define MT_EE_WIFI_CONF0_BAND_SEL		GENMASK(7, 6)
49 #define MT_EE_WIFI_CONF1_BAND_SEL		GENMASK(7, 6)
50 #define MT_EE_WIFI_CONF_STREAM_NUM		GENMASK(7, 5)
51 #define MT_EE_WIFI_CONF3_TX_PATH_B0		GENMASK(1, 0)
52 #define MT_EE_WIFI_CONF3_TX_PATH_B1		GENMASK(5, 4)
53 #define MT_EE_WIFI_CONF7_TSSI0_2G		BIT(0)
54 #define MT_EE_WIFI_CONF7_TSSI0_5G		BIT(2)
55 #define MT_EE_WIFI_CONF7_TSSI1_5G		BIT(4)
56 
57 #define MT_EE_RATE_DELTA_MASK			GENMASK(5, 0)
58 #define MT_EE_RATE_DELTA_SIGN			BIT(6)
59 #define MT_EE_RATE_DELTA_EN			BIT(7)
60 
61 #define MT_EE_NSS_MAX_MA7915			4
62 #define MT_EE_NSS_MAX_DBDC_MA7915		2
63 #define MT_EE_NSS_MAX_MA7986			4
64 #define MT_EE_NSS_MAX_DBDC_MA7986		4
65 
66 enum mt7915_adie_sku {
67 	MT7976_ONE_ADIE_DBDC = 0x7,
68 	MT7975_ONE_ADIE	= 0x8,
69 	MT7976_ONE_ADIE	= 0xa,
70 	MT7975_DUAL_ADIE = 0xd,
71 	MT7976_DUAL_ADIE = 0xf,
72 };
73 
74 enum mt7915_eeprom_band {
75 	MT_EE_BAND_SEL_DEFAULT,
76 	MT_EE_BAND_SEL_5GHZ,
77 	MT_EE_BAND_SEL_2GHZ,
78 	MT_EE_BAND_SEL_DUAL,
79 };
80 
81 enum {
82 	MT_EE_V2_BAND_SEL_2GHZ,
83 	MT_EE_V2_BAND_SEL_5GHZ,
84 	MT_EE_V2_BAND_SEL_6GHZ,
85 	MT_EE_V2_BAND_SEL_5GHZ_6GHZ,
86 };
87 
88 enum mt7915_sku_rate_group {
89 	SKU_CCK,
90 	SKU_OFDM,
91 	SKU_HT_BW20,
92 	SKU_HT_BW40,
93 	SKU_VHT_BW20,
94 	SKU_VHT_BW40,
95 	SKU_VHT_BW80,
96 	SKU_VHT_BW160,
97 	SKU_HE_RU26,
98 	SKU_HE_RU52,
99 	SKU_HE_RU106,
100 	SKU_HE_RU242,
101 	SKU_HE_RU484,
102 	SKU_HE_RU996,
103 	SKU_HE_RU2x996,
104 	MAX_SKU_RATE_GROUP_NUM,
105 };
106 
107 static inline int
108 mt7915_get_channel_group_5g(int channel, bool is_7976)
109 {
110 	if (is_7976) {
111 		if (channel <= 64)
112 			return 0;
113 		if (channel <= 96)
114 			return 1;
115 		if (channel <= 128)
116 			return 2;
117 		if (channel <= 144)
118 			return 3;
119 		return 4;
120 	}
121 
122 	if (channel >= 184 && channel <= 196)
123 		return 0;
124 	if (channel <= 48)
125 		return 1;
126 	if (channel <= 64)
127 		return 2;
128 	if (channel <= 96)
129 		return 3;
130 	if (channel <= 112)
131 		return 4;
132 	if (channel <= 128)
133 		return 5;
134 	if (channel <= 144)
135 		return 6;
136 	return 7;
137 }
138 
139 static inline int
140 mt7915_get_channel_group_6g(int channel)
141 {
142 	if (channel <= 29)
143 		return 0;
144 
145 	return DIV_ROUND_UP(channel - 29, 32);
146 }
147 
148 static inline bool
149 mt7915_tssi_enabled(struct mt7915_dev *dev, enum nl80211_band band)
150 {
151 	u8 *eep = dev->mt76.eeprom.data;
152 	u8 val = eep[MT_EE_WIFI_CONF + 7];
153 
154 	if (band == NL80211_BAND_2GHZ)
155 		return val & MT_EE_WIFI_CONF7_TSSI0_2G;
156 
157 	if (dev->dbdc_support)
158 		return val & MT_EE_WIFI_CONF7_TSSI1_5G;
159 	else
160 		return val & MT_EE_WIFI_CONF7_TSSI0_5G;
161 }
162 
163 extern const u8 mt7915_sku_group_len[MAX_SKU_RATE_GROUP_NUM];
164 
165 #endif
166