xref: /freebsd/sys/contrib/dev/mediatek/mt76/mt7915/eeprom.h (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
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 enum mt7915_adie_sku {
62 	MT7976_ONE_ADIE_DBDC = 0x7,
63 	MT7975_ONE_ADIE	= 0x8,
64 	MT7976_ONE_ADIE	= 0xa,
65 	MT7975_DUAL_ADIE = 0xd,
66 	MT7976_DUAL_ADIE = 0xf,
67 };
68 
69 enum mt7915_eeprom_band {
70 	MT_EE_BAND_SEL_DEFAULT,
71 	MT_EE_BAND_SEL_5GHZ,
72 	MT_EE_BAND_SEL_2GHZ,
73 	MT_EE_BAND_SEL_DUAL,
74 };
75 
76 enum {
77 	MT_EE_V2_BAND_SEL_2GHZ,
78 	MT_EE_V2_BAND_SEL_5GHZ,
79 	MT_EE_V2_BAND_SEL_6GHZ,
80 	MT_EE_V2_BAND_SEL_5GHZ_6GHZ,
81 };
82 
83 enum mt7915_sku_rate_group {
84 	SKU_CCK,
85 	SKU_OFDM,
86 	SKU_HT_BW20,
87 	SKU_HT_BW40,
88 	SKU_VHT_BW20,
89 	SKU_VHT_BW40,
90 	SKU_VHT_BW80,
91 	SKU_VHT_BW160,
92 	SKU_HE_RU26,
93 	SKU_HE_RU52,
94 	SKU_HE_RU106,
95 	SKU_HE_RU242,
96 	SKU_HE_RU484,
97 	SKU_HE_RU996,
98 	SKU_HE_RU2x996,
99 	MAX_SKU_RATE_GROUP_NUM,
100 };
101 
102 static inline int
103 mt7915_get_channel_group_5g(int channel, bool is_7976)
104 {
105 	if (is_7976) {
106 		if (channel <= 64)
107 			return 0;
108 		if (channel <= 96)
109 			return 1;
110 		if (channel <= 128)
111 			return 2;
112 		if (channel <= 144)
113 			return 3;
114 		return 4;
115 	}
116 
117 	if (channel >= 184 && channel <= 196)
118 		return 0;
119 	if (channel <= 48)
120 		return 1;
121 	if (channel <= 64)
122 		return 2;
123 	if (channel <= 96)
124 		return 3;
125 	if (channel <= 112)
126 		return 4;
127 	if (channel <= 128)
128 		return 5;
129 	if (channel <= 144)
130 		return 6;
131 	return 7;
132 }
133 
134 static inline int
135 mt7915_get_channel_group_6g(int channel)
136 {
137 	if (channel <= 29)
138 		return 0;
139 
140 	return DIV_ROUND_UP(channel - 29, 32);
141 }
142 
143 static inline bool
144 mt7915_tssi_enabled(struct mt7915_dev *dev, enum nl80211_band band)
145 {
146 	u8 *eep = dev->mt76.eeprom.data;
147 	u8 val = eep[MT_EE_WIFI_CONF + 7];
148 
149 	if (band == NL80211_BAND_2GHZ)
150 		return val & MT_EE_WIFI_CONF7_TSSI0_2G;
151 
152 	if (dev->dbdc_support)
153 		return val & MT_EE_WIFI_CONF7_TSSI1_5G;
154 	else
155 		return val & MT_EE_WIFI_CONF7_TSSI0_5G;
156 }
157 
158 extern const u8 mt7915_sku_group_len[MAX_SKU_RATE_GROUP_NUM];
159 
160 #endif
161