1 // SPDX-License-Identifier: ISC
7 mt7603_efuse_read(struct mt7603_dev
*dev
, u32 base
, u16 addr
, u8
*data
)
12 val
= mt76_rr(dev
, base
+ MT_EFUSE_CTRL
);
13 val
&= ~(MT_EFUSE_CTRL_AIN
|
15 val
|= FIELD_PREP(MT_EFUSE_CTRL_AIN
, addr
& ~0xf);
16 val
|= MT_EFUSE_CTRL_KICK
;
17 mt76_wr(dev
, base
+ MT_EFUSE_CTRL
, val
);
19 if (!mt76_poll(dev
, base
+ MT_EFUSE_CTRL
, MT_EFUSE_CTRL_KICK
, 0, 1000))
24 val
= mt76_rr(dev
, base
+ MT_EFUSE_CTRL
);
25 if ((val
& MT_EFUSE_CTRL_AOUT
) == MT_EFUSE_CTRL_AOUT
||
26 WARN_ON_ONCE(!(val
& MT_EFUSE_CTRL_VALID
))) {
27 memset(data
, 0xff, 16);
31 for (i
= 0; i
< 4; i
++) {
32 val
= mt76_rr(dev
, base
+ MT_EFUSE_RDATA(i
));
33 put_unaligned_le32(val
, data
+ 4 * i
);
40 mt7603_efuse_init(struct mt7603_dev
*dev
)
42 u32 base
= mt7603_reg_map(dev
, MT_EFUSE_BASE
);
43 int len
= MT7603_EEPROM_SIZE
;
47 if (mt76_rr(dev
, base
+ MT_EFUSE_BASE_CTRL
) & MT_EFUSE_BASE_CTRL_EMPTY
)
50 dev
->mt76
.otp
.data
= devm_kzalloc(dev
->mt76
.dev
, len
, GFP_KERNEL
);
51 dev
->mt76
.otp
.size
= len
;
52 if (!dev
->mt76
.otp
.data
)
55 buf
= dev
->mt76
.otp
.data
;
56 for (i
= 0; i
+ 16 <= len
; i
+= 16) {
57 ret
= mt7603_efuse_read(dev
, base
, i
, buf
+ i
);
66 mt7603_has_cal_free_data(struct mt7603_dev
*dev
, u8
*efuse
)
68 if (!efuse
[MT_EE_TEMP_SENSOR_CAL
])
71 if (get_unaligned_le16(efuse
+ MT_EE_TX_POWER_0_START_2G
) == 0)
74 if (get_unaligned_le16(efuse
+ MT_EE_TX_POWER_1_START_2G
) == 0)
77 if (!efuse
[MT_EE_CP_FT_VERSION
])
80 if (!efuse
[MT_EE_XTAL_FREQ_OFFSET
])
83 if (!efuse
[MT_EE_XTAL_WF_RFCAL
])
90 mt7603_apply_cal_free_data(struct mt7603_dev
*dev
, u8
*efuse
)
92 static const u8 cal_free_bytes
[] = {
93 MT_EE_TEMP_SENSOR_CAL
,
95 MT_EE_XTAL_FREQ_OFFSET
,
98 MT_EE_TX_POWER_0_START_2G
,
99 MT_EE_TX_POWER_0_START_2G
+ 1,
100 MT_EE_TX_POWER_1_START_2G
,
101 MT_EE_TX_POWER_1_START_2G
+ 1,
103 u8
*eeprom
= dev
->mt76
.eeprom
.data
;
104 int n
= ARRAY_SIZE(cal_free_bytes
);
107 if (!mt7603_has_cal_free_data(dev
, efuse
))
113 for (i
= 0; i
< n
; i
++) {
114 int offset
= cal_free_bytes
[i
];
116 eeprom
[offset
] = efuse
[offset
];
121 mt7603_eeprom_load(struct mt7603_dev
*dev
)
125 ret
= mt76_eeprom_init(&dev
->mt76
, MT7603_EEPROM_SIZE
);
129 return mt7603_efuse_init(dev
);
132 static int mt7603_check_eeprom(struct mt76_dev
*dev
)
134 u16 val
= get_unaligned_le16(dev
->eeprom
.data
);
145 int mt7603_eeprom_init(struct mt7603_dev
*dev
)
149 ret
= mt7603_eeprom_load(dev
);
153 if (dev
->mt76
.otp
.data
) {
154 if (mt7603_check_eeprom(&dev
->mt76
) == 0)
155 mt7603_apply_cal_free_data(dev
, dev
->mt76
.otp
.data
);
157 memcpy(dev
->mt76
.eeprom
.data
, dev
->mt76
.otp
.data
,
161 dev
->mt76
.cap
.has_2ghz
= true;
162 memcpy(dev
->mt76
.macaddr
, dev
->mt76
.eeprom
.data
+ MT_EE_MAC_ADDR
,
165 mt76_eeprom_override(&dev
->mt76
);