Lines Matching +full:eeprom +full:- +full:data

1 // SPDX-License-Identifier: GPL-2.0-only
13 #include "eeprom.h"
32 mt7601u_efuse_read(struct mt7601u_dev *dev, u16 addr, u8 *data, in mt7601u_efuse_read() argument
47 return -ETIMEDOUT; in mt7601u_efuse_read()
51 /* Parts of eeprom not in the usage map (0x80-0xc0,0xf0) in mt7601u_efuse_read()
52 * will not return valid data but it's ok. in mt7601u_efuse_read()
54 memset(data, 0xff, 16); in mt7601u_efuse_read()
60 put_unaligned_le32(val, data + 4 * i); in mt7601u_efuse_read()
70 u8 data[round_up(MT_EFUSE_USAGE_MAP_SIZE, 16)]; in mt7601u_efuse_physical_size_check() local
76 data + i * 16, MT_EE_PHYSICAL_READ); in mt7601u_efuse_physical_size_check()
82 if (!data[i]) { in mt7601u_efuse_physical_size_check()
87 cnt_free = end - start + 1; in mt7601u_efuse_physical_size_check()
89 if (MT_EFUSE_USAGE_MAP_SIZE - cnt_free < 5) { in mt7601u_efuse_physical_size_check()
90 …dev_err(dev->dev, "Error: your device needs default EEPROM file and this driver doesn't support it… in mt7601u_efuse_physical_size_check()
91 return -EINVAL; in mt7601u_efuse_physical_size_check()
98 mt7601u_has_tssi(struct mt7601u_dev *dev, u8 *eeprom) in mt7601u_has_tssi() argument
100 u16 nic_conf1 = get_unaligned_le16(eeprom + MT_EE_NIC_CONF_1); in mt7601u_has_tssi()
106 mt7601u_set_chip_cap(struct mt7601u_dev *dev, u8 *eeprom) in mt7601u_set_chip_cap() argument
108 u16 nic_conf0 = get_unaligned_le16(eeprom + MT_EE_NIC_CONF_0); in mt7601u_set_chip_cap()
109 u16 nic_conf1 = get_unaligned_le16(eeprom + MT_EE_NIC_CONF_1); in mt7601u_set_chip_cap()
114 dev->ee->tssi_enabled = mt7601u_has_tssi(dev, eeprom) && in mt7601u_set_chip_cap()
118 dev_err(dev->dev, in mt7601u_set_chip_cap()
126 dev_err(dev->dev, in mt7601u_set_chip_cap()
131 u8 *eeprom, u8 max_pwr) in mt7601u_set_channel_target_power() argument
133 u8 trgt_pwr = eeprom[MT_EE_TX_TSSI_TARGET_POWER]; in mt7601u_set_channel_target_power()
136 dev_warn(dev->dev, "Error: EEPROM trgt power invalid %hhx!\n", in mt7601u_set_channel_target_power()
141 memset(dev->ee->chan_pwr, trgt_pwr, sizeof(dev->ee->chan_pwr)); in mt7601u_set_channel_target_power()
145 mt7601u_set_channel_power(struct mt7601u_dev *dev, u8 *eeprom) in mt7601u_set_channel_power() argument
153 if (mt7601u_has_tssi(dev, eeprom)) { in mt7601u_set_channel_power()
154 mt7601u_set_channel_target_power(dev, eeprom, max_pwr); in mt7601u_set_channel_power()
159 s8 power = field_validate(eeprom[MT_EE_TX_POWER_OFFSET + i]); in mt7601u_set_channel_power()
164 dev->ee->chan_pwr[i] = power; in mt7601u_set_channel_power()
169 mt7601u_set_country_reg(struct mt7601u_dev *dev, u8 *eeprom) in mt7601u_set_country_reg() argument
171 /* Note: - region 31 is not valid for mt7601u (see rtmp_init.c) in mt7601u_set_country_reg()
172 * - comments in rtmp_def.h are incorrect (see rt_channel.c) in mt7601u_set_country_reg()
175 /* EEPROM country regions 0 - 7 */ in mt7601u_set_country_reg()
178 /* EEPROM country regions 32 - 33 */ in mt7601u_set_country_reg()
181 u8 val = eeprom[MT_EE_COUNTRY_REGION]; in mt7601u_set_country_reg()
182 int idx = -1; in mt7601u_set_country_reg()
187 idx = val - 32 + 8; in mt7601u_set_country_reg()
189 if (idx != -1) in mt7601u_set_country_reg()
190 dev_info(dev->dev, in mt7601u_set_country_reg()
191 "EEPROM country region %02x (channels %d-%d)\n", in mt7601u_set_country_reg()
193 chan_bounds[idx].start + chan_bounds[idx].num - 1); in mt7601u_set_country_reg()
195 idx = 5; /* channels 1 - 14 */ in mt7601u_set_country_reg()
197 dev->ee->reg = chan_bounds[idx]; in mt7601u_set_country_reg()
199 /* TODO: country region 33 is special - phy should be set to B-mode in mt7601u_set_country_reg()
205 mt7601u_set_rf_freq_off(struct mt7601u_dev *dev, u8 *eeprom) in mt7601u_set_rf_freq_off() argument
209 dev->ee->rf_freq_off = field_validate(eeprom[MT_EE_FREQ_OFFSET]); in mt7601u_set_rf_freq_off()
210 comp = field_validate(eeprom[MT_EE_FREQ_OFFSET_COMPENSATION]); in mt7601u_set_rf_freq_off()
213 dev->ee->rf_freq_off -= comp & 0x7f; in mt7601u_set_rf_freq_off()
215 dev->ee->rf_freq_off += comp; in mt7601u_set_rf_freq_off()
219 mt7601u_set_rssi_offset(struct mt7601u_dev *dev, u8 *eeprom) in mt7601u_set_rssi_offset() argument
222 s8 *rssi_offset = dev->ee->rssi_offset; in mt7601u_set_rssi_offset()
225 rssi_offset[i] = eeprom[MT_EE_RSSI_OFFSET + i]; in mt7601u_set_rssi_offset()
227 if (rssi_offset[i] < -10 || rssi_offset[i] > 10) { in mt7601u_set_rssi_offset()
228 dev_warn(dev->dev, in mt7601u_set_rssi_offset()
229 "Warning: EEPROM RSSI is invalid %02hhx\n", in mt7601u_set_rssi_offset()
256 rate->raw = s6_validate(value); in mt7601u_set_power_rate()
257 rate->bw20 = s6_to_int(value); in mt7601u_set_power_rate()
259 rate->bw40 = rate->bw20 + delta; in mt7601u_set_power_rate()
265 struct mt7601u_rate_power *t = &dev->ee->power_rate_table; in mt7601u_save_power_rate()
269 mt7601u_set_power_rate(&t->cck[0], delta, (val >> 0) & 0xff); in mt7601u_save_power_rate()
270 mt7601u_set_power_rate(&t->cck[1], delta, (val >> 8) & 0xff); in mt7601u_save_power_rate()
272 dev->ee->real_cck_bw20[0] = t->cck[0].bw20; in mt7601u_save_power_rate()
273 dev->ee->real_cck_bw20[1] = t->cck[1].bw20; in mt7601u_save_power_rate()
275 mt7601u_set_power_rate(&t->ofdm[0], delta, (val >> 16) & 0xff); in mt7601u_save_power_rate()
276 mt7601u_set_power_rate(&t->ofdm[1], delta, (val >> 24) & 0xff); in mt7601u_save_power_rate()
279 mt7601u_set_power_rate(&t->ofdm[2], delta, (val >> 0) & 0xff); in mt7601u_save_power_rate()
280 mt7601u_set_power_rate(&t->ofdm[3], delta, (val >> 8) & 0xff); in mt7601u_save_power_rate()
281 mt7601u_set_power_rate(&t->ht[0], delta, (val >> 16) & 0xff); in mt7601u_save_power_rate()
282 mt7601u_set_power_rate(&t->ht[1], delta, (val >> 24) & 0xff); in mt7601u_save_power_rate()
285 mt7601u_set_power_rate(&t->ht[2], delta, (val >> 0) & 0xff); in mt7601u_save_power_rate()
286 mt7601u_set_power_rate(&t->ht[3], delta, (val >> 8) & 0xff); in mt7601u_save_power_rate()
303 ret = -ret; in get_delta()
309 mt7601u_config_tx_power_per_rate(struct mt7601u_dev *dev, u8 *eeprom) in mt7601u_config_tx_power_per_rate() argument
315 bw40_delta = get_delta(eeprom[MT_EE_TX_POWER_DELTA_BW40]); in mt7601u_config_tx_power_per_rate()
318 val = get_unaligned_le32(eeprom + MT_EE_TX_POWER_BYRATE(i)); in mt7601u_config_tx_power_per_rate()
330 mt7601u_init_tssi_params(struct mt7601u_dev *dev, u8 *eeprom) in mt7601u_init_tssi_params() argument
332 struct tssi_data *d = &dev->ee->tssi_data; in mt7601u_init_tssi_params()
334 if (!dev->ee->tssi_enabled) in mt7601u_init_tssi_params()
337 d->slope = eeprom[MT_EE_TX_TSSI_SLOPE]; in mt7601u_init_tssi_params()
338 d->tx0_delta_offset = eeprom[MT_EE_TX_TSSI_OFFSET] * 1024; in mt7601u_init_tssi_params()
339 d->offset[0] = eeprom[MT_EE_TX_TSSI_OFFSET_GROUP]; in mt7601u_init_tssi_params()
340 d->offset[1] = eeprom[MT_EE_TX_TSSI_OFFSET_GROUP + 1]; in mt7601u_init_tssi_params()
341 d->offset[2] = eeprom[MT_EE_TX_TSSI_OFFSET_GROUP + 2]; in mt7601u_init_tssi_params()
347 u8 *eeprom; in mt7601u_eeprom_init() local
354 dev->ee = devm_kzalloc(dev->dev, sizeof(*dev->ee), GFP_KERNEL); in mt7601u_eeprom_init()
355 if (!dev->ee) in mt7601u_eeprom_init()
356 return -ENOMEM; in mt7601u_eeprom_init()
358 eeprom = kmalloc(MT7601U_EEPROM_SIZE, GFP_KERNEL); in mt7601u_eeprom_init()
359 if (!eeprom) in mt7601u_eeprom_init()
360 return -ENOMEM; in mt7601u_eeprom_init()
363 ret = mt7601u_efuse_read(dev, i, eeprom + i, MT_EE_READ); in mt7601u_eeprom_init()
368 if (eeprom[MT_EE_VERSION_EE] > MT7601U_EE_MAX_VER) in mt7601u_eeprom_init()
369 dev_warn(dev->dev, in mt7601u_eeprom_init()
370 "Warning: unsupported EEPROM version %02hhx\n", in mt7601u_eeprom_init()
371 eeprom[MT_EE_VERSION_EE]); in mt7601u_eeprom_init()
372 dev_info(dev->dev, "EEPROM ver:%02hhx fae:%02hhx\n", in mt7601u_eeprom_init()
373 eeprom[MT_EE_VERSION_EE], eeprom[MT_EE_VERSION_FAE]); in mt7601u_eeprom_init()
375 mt7601u_set_macaddr(dev, eeprom + MT_EE_MAC_ADDR); in mt7601u_eeprom_init()
376 mt7601u_set_chip_cap(dev, eeprom); in mt7601u_eeprom_init()
377 mt7601u_set_channel_power(dev, eeprom); in mt7601u_eeprom_init()
378 mt7601u_set_country_reg(dev, eeprom); in mt7601u_eeprom_init()
379 mt7601u_set_rf_freq_off(dev, eeprom); in mt7601u_eeprom_init()
380 mt7601u_set_rssi_offset(dev, eeprom); in mt7601u_eeprom_init()
381 dev->ee->ref_temp = eeprom[MT_EE_REF_TEMP]; in mt7601u_eeprom_init()
382 dev->ee->lna_gain = eeprom[MT_EE_LNA_GAIN]; in mt7601u_eeprom_init()
384 mt7601u_config_tx_power_per_rate(dev, eeprom); in mt7601u_eeprom_init()
386 mt7601u_init_tssi_params(dev, eeprom); in mt7601u_eeprom_init()
388 kfree(eeprom); in mt7601u_eeprom_init()