1 /* 2 * Copyright (C) 2014 Felix Fietkau <nbd@openwrt.org> 3 * Copyright (C) 2015 Jakub Kicinski <kubakici@wp.pl> 4 * Copyright (C) 2018 Stanislaw Gruszka <stf_xl@wp.pl> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 2 8 * as published by the Free Software Foundation 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 */ 15 16 #ifndef __MT76X0U_EEPROM_H 17 #define __MT76X0U_EEPROM_H 18 19 #include "../mt76x02_eeprom.h" 20 21 struct mt76x0_dev; 22 23 #define MT76X0U_EE_MAX_VER 0x0c 24 #define MT76X0_EEPROM_SIZE 512 25 26 struct reg_channel_bounds { 27 u8 start; 28 u8 num; 29 }; 30 31 struct mt76x0_caldata { 32 s8 lna_gain; 33 }; 34 35 struct mt76x0_eeprom_params { 36 u8 rf_freq_off; 37 s16 temp_off; 38 s8 rssi_offset_2ghz[2]; 39 s8 rssi_offset_5ghz[3]; 40 41 /* TX_PWR_CFG_* values from EEPROM for 20 and 40 Mhz bandwidths. */ 42 u32 tx_pwr_cfg_2g[5][2]; 43 u32 tx_pwr_cfg_5g[5][2]; 44 45 u8 tx_pwr_per_chan[58]; 46 }; 47 48 int mt76x0_eeprom_init(struct mt76x0_dev *dev); 49 void mt76x0_read_rx_gain(struct mt76x0_dev *dev); 50 51 static inline u32 s6_validate(u32 reg) 52 { 53 WARN_ON(reg & ~GENMASK(5, 0)); 54 return reg & GENMASK(5, 0); 55 } 56 57 static inline int s6_to_int(u32 reg) 58 { 59 int s6; 60 61 s6 = s6_validate(reg); 62 if (s6 & BIT(5)) 63 s6 -= BIT(6); 64 65 return s6; 66 } 67 68 static inline u32 int_to_s6(int val) 69 { 70 if (val < -0x20) 71 return 0x20; 72 if (val > 0x1f) 73 return 0x1f; 74 75 return val & 0x3f; 76 } 77 78 #endif 79