1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2014 Felix Fietkau <nbd@openwrt.org>
4 * Copyright (C) 2015 Jakub Kicinski <kubakici@wp.pl>
7 #ifndef __MT7601U_EEPROM_H
8 #define __MT7601U_EEPROM_H
12 #define MT7601U_EE_MAX_VER 0x0d
13 #define MT7601U_EEPROM_SIZE 256
15 #define MT7601U_DEFAULT_TX_POWER 6
17 enum mt76_eeprom_field
{
19 MT_EE_VERSION_FAE
= 0x02,
20 MT_EE_VERSION_EE
= 0x03,
21 MT_EE_MAC_ADDR
= 0x04,
22 MT_EE_NIC_CONF_0
= 0x34,
23 MT_EE_NIC_CONF_1
= 0x36,
24 MT_EE_COUNTRY_REGION
= 0x39,
25 MT_EE_FREQ_OFFSET
= 0x3a,
26 MT_EE_NIC_CONF_2
= 0x42,
28 MT_EE_LNA_GAIN
= 0x44,
29 MT_EE_RSSI_OFFSET
= 0x46,
31 MT_EE_TX_POWER_DELTA_BW40
= 0x50,
32 MT_EE_TX_POWER_OFFSET
= 0x52,
34 MT_EE_TX_TSSI_SLOPE
= 0x6e,
35 MT_EE_TX_TSSI_OFFSET_GROUP
= 0x6f,
36 MT_EE_TX_TSSI_OFFSET
= 0x76,
38 MT_EE_TX_TSSI_TARGET_POWER
= 0xd0,
39 MT_EE_REF_TEMP
= 0xd1,
40 MT_EE_FREQ_OFFSET_COMPENSATION
= 0xdb,
41 MT_EE_TX_POWER_BYRATE_BASE
= 0xde,
43 MT_EE_USAGE_MAP_START
= 0x1e0,
44 MT_EE_USAGE_MAP_END
= 0x1fc,
47 #define MT_EE_NIC_CONF_0_RX_PATH GENMASK(3, 0)
48 #define MT_EE_NIC_CONF_0_TX_PATH GENMASK(7, 4)
49 #define MT_EE_NIC_CONF_0_BOARD_TYPE GENMASK(13, 12)
51 #define MT_EE_NIC_CONF_1_HW_RF_CTRL BIT(0)
52 #define MT_EE_NIC_CONF_1_TEMP_TX_ALC BIT(1)
53 #define MT_EE_NIC_CONF_1_LNA_EXT_2G BIT(2)
54 #define MT_EE_NIC_CONF_1_LNA_EXT_5G BIT(3)
55 #define MT_EE_NIC_CONF_1_TX_ALC_EN BIT(13)
57 #define MT_EE_NIC_CONF_2_RX_STREAM GENMASK(3, 0)
58 #define MT_EE_NIC_CONF_2_TX_STREAM GENMASK(7, 4)
59 #define MT_EE_NIC_CONF_2_HW_ANTDIV BIT(8)
60 #define MT_EE_NIC_CONF_2_XTAL_OPTION GENMASK(10, 9)
61 #define MT_EE_NIC_CONF_2_TEMP_DISABLE BIT(11)
62 #define MT_EE_NIC_CONF_2_COEX_METHOD GENMASK(15, 13)
64 #define MT_EE_TX_POWER_BYRATE(i) (MT_EE_TX_POWER_BYRATE_BASE + \
67 #define MT_EFUSE_USAGE_MAP_SIZE (MT_EE_USAGE_MAP_END - \
68 MT_EE_USAGE_MAP_START + 1)
70 enum mt7601u_eeprom_access_modes
{
72 MT_EE_PHYSICAL_READ
= 1,
75 struct power_per_rate
{
76 u8 raw
; /* validated s6 value */
77 s8 bw20
; /* sign-extended int */
78 s8 bw40
; /* sign-extended int */
81 /* Power per rate - one value per two rates */
82 struct mt7601u_rate_power
{
83 struct power_per_rate cck
[2];
84 struct power_per_rate ofdm
[4];
85 struct power_per_rate ht
[4];
88 struct reg_channel_bounds
{
93 struct mt7601u_eeprom_params
{
101 struct mt7601u_rate_power power_rate_table
;
104 /* TSSI stuff - only with internal TX ALC */
106 int tx0_delta_offset
;
111 struct reg_channel_bounds reg
;
114 int mt7601u_eeprom_init(struct mt7601u_dev
*dev
);
116 static inline u32
s6_validate(u32 reg
)
118 WARN_ON(reg
& ~GENMASK(5, 0));
119 return reg
& GENMASK(5, 0);
122 static inline int s6_to_int(u32 reg
)
126 s6
= s6_validate(reg
);
133 static inline u32
int_to_s6(int val
)