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_WIFI_CONF =	0x190,
21 	MT_EE_TX0_POWER_2G =	0x2fc,
22 	MT_EE_TX0_POWER_5G =	0x34b,
23 	MT_EE_ADIE_FT_VERSION =	0x9a0,
24 
25 	__MT_EE_MAX =		0xe00
26 };
27 
28 #define MT_EE_WIFI_CONF0_TX_PATH		GENMASK(2, 0)
29 #define MT_EE_WIFI_CONF0_BAND_SEL		GENMASK(7, 6)
30 #define MT_EE_WIFI_CONF1_BAND_SEL		GENMASK(7, 6)
31 #define MT_EE_WIFI_CONF3_TX_PATH_B0		GENMASK(1, 0)
32 #define MT_EE_WIFI_CONF3_TX_PATH_B1		GENMASK(5, 4)
33 #define MT_EE_WIFI_CONF7_TSSI0_2G		BIT(0)
34 #define MT_EE_WIFI_CONF7_TSSI0_5G		BIT(2)
35 #define MT_EE_WIFI_CONF7_TSSI1_5G		BIT(4)
36 
37 enum mt7915_eeprom_band {
38 	MT_EE_BAND_SEL_DEFAULT,
39 	MT_EE_BAND_SEL_5GHZ,
40 	MT_EE_BAND_SEL_2GHZ,
41 	MT_EE_BAND_SEL_DUAL,
42 };
43 
44 #define SKU_DELTA_VAL		GENMASK(5, 0)
45 #define SKU_DELTA_ADD		BIT(6)
46 #define SKU_DELTA_EN		BIT(7)
47 
48 enum mt7915_sku_delta_group {
49 	SKU_CCK_GROUP0,
50 	SKU_CCK_GROUP1,
51 
52 	SKU_OFDM_GROUP0 = 0,
53 	SKU_OFDM_GROUP1,
54 	SKU_OFDM_GROUP2,
55 	SKU_OFDM_GROUP3,
56 	SKU_OFDM_GROUP4,
57 
58 	SKU_MCS_GROUP0 = 0,
59 	SKU_MCS_GROUP1,
60 	SKU_MCS_GROUP2,
61 	SKU_MCS_GROUP3,
62 	SKU_MCS_GROUP4,
63 	SKU_MCS_GROUP5,
64 	SKU_MCS_GROUP6,
65 	SKU_MCS_GROUP7,
66 	SKU_MCS_GROUP8,
67 	SKU_MCS_GROUP9,
68 };
69 
70 enum mt7915_sku_rate_group {
71 	SKU_CCK,
72 	SKU_OFDM,
73 	SKU_HT_BW20,
74 	SKU_HT_BW40,
75 	SKU_VHT_BW20,
76 	SKU_VHT_BW40,
77 	SKU_VHT_BW80,
78 	SKU_VHT_BW160,
79 	SKU_HE_RU26,
80 	SKU_HE_RU52,
81 	SKU_HE_RU106,
82 	SKU_HE_RU242,
83 	SKU_HE_RU484,
84 	SKU_HE_RU996,
85 	SKU_HE_RU2x996,
86 	MAX_SKU_RATE_GROUP_NUM,
87 };
88 
89 struct sku_group {
90 	u8 len;
91 	u16 offset[2];
92 	const u8 *delta_map;
93 };
94 
95 static inline int
96 mt7915_get_channel_group(int channel)
97 {
98 	if (channel >= 184 && channel <= 196)
99 		return 0;
100 	if (channel <= 48)
101 		return 1;
102 	if (channel <= 64)
103 		return 2;
104 	if (channel <= 96)
105 		return 3;
106 	if (channel <= 112)
107 		return 4;
108 	if (channel <= 128)
109 		return 5;
110 	if (channel <= 144)
111 		return 6;
112 	return 7;
113 }
114 
115 static inline bool
116 mt7915_tssi_enabled(struct mt7915_dev *dev, enum nl80211_band band)
117 {
118 	u8 *eep = dev->mt76.eeprom.data;
119 
120 	/* TODO: DBDC */
121 	if (band == NL80211_BAND_5GHZ)
122 		return eep[MT_EE_WIFI_CONF + 7] & MT_EE_WIFI_CONF7_TSSI0_5G;
123 	else
124 		return eep[MT_EE_WIFI_CONF + 7] & MT_EE_WIFI_CONF7_TSSI0_2G;
125 }
126 
127 extern const struct sku_group mt7915_sku_groups[];
128 
129 #endif
130