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_eeprom_params {
32 	u8 rf_freq_off;
33 	s16 temp_off;
34 	s8 rssi_offset_2ghz[2];
35 	s8 rssi_offset_5ghz[3];
36 	s8 lna_gain_2ghz;
37 	s8 lna_gain_5ghz[3];
38 
39 	/* TX_PWR_CFG_* values from EEPROM for 20 and 40 Mhz bandwidths. */
40 	u32 tx_pwr_cfg_2g[5][2];
41 	u32 tx_pwr_cfg_5g[5][2];
42 
43 	u8 tx_pwr_per_chan[58];
44 };
45 
46 int mt76x0_eeprom_init(struct mt76x0_dev *dev);
47 
48 static inline u32 s6_validate(u32 reg)
49 {
50 	WARN_ON(reg & ~GENMASK(5, 0));
51 	return reg & GENMASK(5, 0);
52 }
53 
54 static inline int s6_to_int(u32 reg)
55 {
56 	int s6;
57 
58 	s6 = s6_validate(reg);
59 	if (s6 & BIT(5))
60 		s6 -= BIT(6);
61 
62 	return s6;
63 }
64 
65 static inline u32 int_to_s6(int val)
66 {
67 	if (val < -0x20)
68 		return 0x20;
69 	if (val > 0x1f)
70 		return 0x1f;
71 
72 	return val & 0x3f;
73 }
74 
75 #endif
76