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_ADIE_FT_VERSION =	0x9a0,
27 
28 	__MT_EE_MAX =		0xe00,
29 	/* 0xe10 ~ 0x5780 used to save group cal data */
30 	MT_EE_PRECAL =		0xe10
31 };
32 
33 #define MT_EE_WIFI_CAL_GROUP			BIT(0)
34 #define MT_EE_WIFI_CAL_DPD			GENMASK(2, 1)
35 #define MT_EE_CAL_UNIT				1024
36 #define MT_EE_CAL_GROUP_SIZE			(49 * MT_EE_CAL_UNIT + 16)
37 #define MT_EE_CAL_DPD_SIZE			(54 * MT_EE_CAL_UNIT)
38 
39 #define MT_EE_WIFI_CONF0_TX_PATH		GENMASK(2, 0)
40 #define MT_EE_WIFI_CONF0_BAND_SEL		GENMASK(7, 6)
41 #define MT_EE_WIFI_CONF1_BAND_SEL		GENMASK(7, 6)
42 #define MT_EE_WIFI_CONF3_TX_PATH_B0		GENMASK(1, 0)
43 #define MT_EE_WIFI_CONF3_TX_PATH_B1		GENMASK(5, 4)
44 #define MT_EE_WIFI_CONF7_TSSI0_2G		BIT(0)
45 #define MT_EE_WIFI_CONF7_TSSI0_5G		BIT(2)
46 #define MT_EE_WIFI_CONF7_TSSI1_5G		BIT(4)
47 
48 #define MT_EE_RATE_DELTA_MASK			GENMASK(5, 0)
49 #define MT_EE_RATE_DELTA_SIGN			BIT(6)
50 #define MT_EE_RATE_DELTA_EN			BIT(7)
51 
52 enum mt7915_eeprom_band {
53 	MT_EE_BAND_SEL_DEFAULT,
54 	MT_EE_BAND_SEL_5GHZ,
55 	MT_EE_BAND_SEL_2GHZ,
56 	MT_EE_BAND_SEL_DUAL,
57 };
58 
59 enum mt7915_sku_rate_group {
60 	SKU_CCK,
61 	SKU_OFDM,
62 	SKU_HT_BW20,
63 	SKU_HT_BW40,
64 	SKU_VHT_BW20,
65 	SKU_VHT_BW40,
66 	SKU_VHT_BW80,
67 	SKU_VHT_BW160,
68 	SKU_HE_RU26,
69 	SKU_HE_RU52,
70 	SKU_HE_RU106,
71 	SKU_HE_RU242,
72 	SKU_HE_RU484,
73 	SKU_HE_RU996,
74 	SKU_HE_RU2x996,
75 	MAX_SKU_RATE_GROUP_NUM,
76 };
77 
78 static inline int
mt7915_get_channel_group(int channel)79 mt7915_get_channel_group(int channel)
80 {
81 	if (channel >= 184 && channel <= 196)
82 		return 0;
83 	if (channel <= 48)
84 		return 1;
85 	if (channel <= 64)
86 		return 2;
87 	if (channel <= 96)
88 		return 3;
89 	if (channel <= 112)
90 		return 4;
91 	if (channel <= 128)
92 		return 5;
93 	if (channel <= 144)
94 		return 6;
95 	return 7;
96 }
97 
98 static inline bool
mt7915_tssi_enabled(struct mt7915_dev * dev,enum nl80211_band band)99 mt7915_tssi_enabled(struct mt7915_dev *dev, enum nl80211_band band)
100 {
101 	u8 *eep = dev->mt76.eeprom.data;
102 	u8 val = eep[MT_EE_WIFI_CONF + 7];
103 
104 	if (band == NL80211_BAND_2GHZ)
105 		return val & MT_EE_WIFI_CONF7_TSSI0_2G;
106 
107 	if (dev->dbdc_support)
108 		return val & MT_EE_WIFI_CONF7_TSSI1_5G;
109 	else
110 		return val & MT_EE_WIFI_CONF7_TSSI0_5G;
111 }
112 
113 extern const u8 mt7915_sku_group_len[MAX_SKU_RATE_GROUP_NUM];
114 
115 #endif
116