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