16c92544dSBjoern A. Zeeb /* SPDX-License-Identifier: ISC */
26c92544dSBjoern A. Zeeb /* Copyright (C) 2019 MediaTek Inc. */
36c92544dSBjoern A. Zeeb
46c92544dSBjoern A. Zeeb #ifndef __MT7615_EEPROM_H
56c92544dSBjoern A. Zeeb #define __MT7615_EEPROM_H
66c92544dSBjoern A. Zeeb
76c92544dSBjoern A. Zeeb #include "mt7615.h"
86c92544dSBjoern A. Zeeb
96c92544dSBjoern A. Zeeb
106c92544dSBjoern A. Zeeb #define MT7615_EEPROM_DCOC_OFFSET MT7615_EEPROM_SIZE
116c92544dSBjoern A. Zeeb #define MT7615_EEPROM_DCOC_SIZE 256
126c92544dSBjoern A. Zeeb #define MT7615_EEPROM_DCOC_COUNT 34
136c92544dSBjoern A. Zeeb
146c92544dSBjoern A. Zeeb #define MT7615_EEPROM_TXDPD_OFFSET (MT7615_EEPROM_SIZE + \
156c92544dSBjoern A. Zeeb MT7615_EEPROM_DCOC_COUNT * \
166c92544dSBjoern A. Zeeb MT7615_EEPROM_DCOC_SIZE)
176c92544dSBjoern A. Zeeb #define MT7615_EEPROM_TXDPD_SIZE 216
186c92544dSBjoern A. Zeeb #define MT7615_EEPROM_TXDPD_COUNT (44 + 3)
196c92544dSBjoern A. Zeeb
206c92544dSBjoern A. Zeeb #define MT7615_EEPROM_FULL_SIZE (MT7615_EEPROM_TXDPD_OFFSET + \
216c92544dSBjoern A. Zeeb MT7615_EEPROM_TXDPD_COUNT * \
226c92544dSBjoern A. Zeeb MT7615_EEPROM_TXDPD_SIZE)
236c92544dSBjoern A. Zeeb
246c92544dSBjoern A. Zeeb enum mt7615_eeprom_field {
256c92544dSBjoern A. Zeeb MT_EE_CHIP_ID = 0x000,
266c92544dSBjoern A. Zeeb MT_EE_VERSION = 0x002,
276c92544dSBjoern A. Zeeb MT_EE_MAC_ADDR = 0x004,
286c92544dSBjoern A. Zeeb MT_EE_NIC_CONF_0 = 0x034,
296c92544dSBjoern A. Zeeb MT_EE_NIC_CONF_1 = 0x036,
306c92544dSBjoern A. Zeeb MT_EE_WIFI_CONF = 0x03e,
316c92544dSBjoern A. Zeeb MT_EE_CALDATA_FLASH = 0x052,
326c92544dSBjoern A. Zeeb MT_EE_TX0_2G_TARGET_POWER = 0x058,
336c92544dSBjoern A. Zeeb MT_EE_TX0_5G_G0_TARGET_POWER = 0x070,
346c92544dSBjoern A. Zeeb MT7663_EE_5G_RATE_POWER = 0x089,
356c92544dSBjoern A. Zeeb MT_EE_TX1_5G_G0_TARGET_POWER = 0x098,
366c92544dSBjoern A. Zeeb MT_EE_2G_RATE_POWER = 0x0be,
376c92544dSBjoern A. Zeeb MT_EE_5G_RATE_POWER = 0x0d5,
386c92544dSBjoern A. Zeeb MT7663_EE_TX0_2G_TARGET_POWER = 0x0e3,
396c92544dSBjoern A. Zeeb MT_EE_EXT_PA_2G_TARGET_POWER = 0x0f2,
406c92544dSBjoern A. Zeeb MT_EE_EXT_PA_5G_TARGET_POWER = 0x0f3,
416c92544dSBjoern A. Zeeb MT_EE_TX2_5G_G0_TARGET_POWER = 0x142,
426c92544dSBjoern A. Zeeb MT_EE_TX3_5G_G0_TARGET_POWER = 0x16a,
436c92544dSBjoern A. Zeeb MT7663_EE_HW_CONF1 = 0x1b0,
446c92544dSBjoern A. Zeeb MT7663_EE_TX0_5G_G0_TARGET_POWER = 0x245,
456c92544dSBjoern A. Zeeb MT7663_EE_TX1_5G_G0_TARGET_POWER = 0x2b5,
466c92544dSBjoern A. Zeeb
476c92544dSBjoern A. Zeeb MT7615_EE_MAX = 0x3bf,
486c92544dSBjoern A. Zeeb MT7622_EE_MAX = 0x3db,
49*cbb3ec25SBjoern A. Zeeb MT7663_EE_MAX = 0x600,
506c92544dSBjoern A. Zeeb };
516c92544dSBjoern A. Zeeb
526c92544dSBjoern A. Zeeb #define MT_EE_RATE_POWER_MASK GENMASK(5, 0)
536c92544dSBjoern A. Zeeb #define MT_EE_RATE_POWER_SIGN BIT(6)
546c92544dSBjoern A. Zeeb #define MT_EE_RATE_POWER_EN BIT(7)
556c92544dSBjoern A. Zeeb
566c92544dSBjoern A. Zeeb #define MT_EE_CALDATA_FLASH_TX_DPD BIT(0)
576c92544dSBjoern A. Zeeb #define MT_EE_CALDATA_FLASH_RX_CAL BIT(1)
586c92544dSBjoern A. Zeeb
596c92544dSBjoern A. Zeeb #define MT_EE_NIC_CONF_TX_MASK GENMASK(7, 4)
606c92544dSBjoern A. Zeeb #define MT_EE_NIC_CONF_RX_MASK GENMASK(3, 0)
616c92544dSBjoern A. Zeeb
626c92544dSBjoern A. Zeeb #define MT_EE_HW_CONF1_TX_MASK GENMASK(2, 0)
636c92544dSBjoern A. Zeeb
646c92544dSBjoern A. Zeeb #define MT_EE_NIC_CONF_TSSI_2G BIT(5)
656c92544dSBjoern A. Zeeb #define MT_EE_NIC_CONF_TSSI_5G BIT(6)
666c92544dSBjoern A. Zeeb
676c92544dSBjoern A. Zeeb #define MT_EE_NIC_WIFI_CONF_BAND_SEL GENMASK(5, 4)
686c92544dSBjoern A. Zeeb enum mt7615_eeprom_band {
696c92544dSBjoern A. Zeeb MT_EE_DUAL_BAND,
706c92544dSBjoern A. Zeeb MT_EE_5GHZ,
716c92544dSBjoern A. Zeeb MT_EE_2GHZ,
726c92544dSBjoern A. Zeeb MT_EE_DBDC,
736c92544dSBjoern A. Zeeb };
746c92544dSBjoern A. Zeeb
756c92544dSBjoern A. Zeeb enum mt7615_channel_group {
766c92544dSBjoern A. Zeeb MT_CH_5G_JAPAN,
776c92544dSBjoern A. Zeeb MT_CH_5G_UNII_1,
786c92544dSBjoern A. Zeeb MT_CH_5G_UNII_2A,
796c92544dSBjoern A. Zeeb MT_CH_5G_UNII_2B,
806c92544dSBjoern A. Zeeb MT_CH_5G_UNII_2E_1,
816c92544dSBjoern A. Zeeb MT_CH_5G_UNII_2E_2,
826c92544dSBjoern A. Zeeb MT_CH_5G_UNII_2E_3,
836c92544dSBjoern A. Zeeb MT_CH_5G_UNII_3,
846c92544dSBjoern A. Zeeb __MT_CH_MAX
856c92544dSBjoern A. Zeeb };
866c92544dSBjoern A. Zeeb
876c92544dSBjoern A. Zeeb static inline enum mt7615_channel_group
mt7615_get_channel_group(int channel)886c92544dSBjoern A. Zeeb mt7615_get_channel_group(int channel)
896c92544dSBjoern A. Zeeb {
906c92544dSBjoern A. Zeeb if (channel >= 184 && channel <= 196)
916c92544dSBjoern A. Zeeb return MT_CH_5G_JAPAN;
926c92544dSBjoern A. Zeeb if (channel <= 48)
936c92544dSBjoern A. Zeeb return MT_CH_5G_UNII_1;
946c92544dSBjoern A. Zeeb if (channel <= 64)
956c92544dSBjoern A. Zeeb return MT_CH_5G_UNII_2A;
966c92544dSBjoern A. Zeeb if (channel <= 114)
976c92544dSBjoern A. Zeeb return MT_CH_5G_UNII_2E_1;
986c92544dSBjoern A. Zeeb if (channel <= 144)
996c92544dSBjoern A. Zeeb return MT_CH_5G_UNII_2E_2;
1006c92544dSBjoern A. Zeeb if (channel <= 161)
1016c92544dSBjoern A. Zeeb return MT_CH_5G_UNII_2E_3;
1026c92544dSBjoern A. Zeeb return MT_CH_5G_UNII_3;
1036c92544dSBjoern A. Zeeb }
1046c92544dSBjoern A. Zeeb
1056c92544dSBjoern A. Zeeb static inline bool
mt7615_ext_pa_enabled(struct mt7615_dev * dev,enum nl80211_band band)1066c92544dSBjoern A. Zeeb mt7615_ext_pa_enabled(struct mt7615_dev *dev, enum nl80211_band band)
1076c92544dSBjoern A. Zeeb {
1086c92544dSBjoern A. Zeeb u8 *eep = dev->mt76.eeprom.data;
1096c92544dSBjoern A. Zeeb
1106c92544dSBjoern A. Zeeb if (band == NL80211_BAND_5GHZ)
1116c92544dSBjoern A. Zeeb return !(eep[MT_EE_NIC_CONF_1 + 1] & MT_EE_NIC_CONF_TSSI_5G);
1126c92544dSBjoern A. Zeeb else
1136c92544dSBjoern A. Zeeb return !(eep[MT_EE_NIC_CONF_1 + 1] & MT_EE_NIC_CONF_TSSI_2G);
1146c92544dSBjoern A. Zeeb }
1156c92544dSBjoern A. Zeeb
1166c92544dSBjoern A. Zeeb #endif
117