1 /*
2 
3   Broadcom B43 wireless driver
4   IEEE 802.11n PHY data tables
5 
6   Copyright (c) 2008 Michael Buesch <m@bues.ch>
7   Copyright (c) 2010 Rafał Miłecki <zajec5@gmail.com>
8 
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; either version 2 of the License, or
12   (at your option) any later version.
13 
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License for more details.
18 
19   You should have received a copy of the GNU General Public License
20   along with this program; see the file COPYING.  If not, write to
21   the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
22   Boston, MA 02110-1301, USA.
23 
24 */
25 
26 /*
27  */
28 
29 #ifndef	__IF_BWN_TABLES_NPHY_H__
30 #define	__IF_BWN_TABLES_NPHY_H__
31 
32 struct bwn_phy_n_sfo_cfg {
33 	uint16_t phy_bw1a;
34 	uint16_t phy_bw2;
35 	uint16_t phy_bw3;
36 	uint16_t phy_bw4;
37 	uint16_t phy_bw5;
38 	uint16_t phy_bw6;
39 };
40 
41 struct bwn_mac;
42 
43 struct bwn_nphy_txiqcal_ladder {
44 	uint8_t percent;
45 	uint8_t g_env;
46 };
47 
48 struct bwn_nphy_rf_control_override_rev2 {
49 	uint8_t addr0;
50 	uint8_t addr1;
51 	uint16_t bmask;
52 	uint8_t shift;
53 };
54 
55 struct bwn_nphy_rf_control_override_rev3 {
56 	uint16_t val_mask;
57 	uint8_t val_shift;
58 	uint8_t en_addr0;
59 	uint8_t val_addr0;
60 	uint8_t en_addr1;
61 	uint8_t val_addr1;
62 };
63 
64 struct bwn_nphy_rf_control_override_rev7 {
65 	uint16_t field;
66 	uint16_t val_addr_core0;
67 	uint16_t val_addr_core1;
68 	uint16_t val_mask;
69 	uint8_t val_shift;
70 };
71 
72 struct bwn_nphy_gain_ctl_workaround_entry {
73 	int8_t lna1_gain[4];
74 	int8_t lna2_gain[4];
75 	uint8_t gain_db[10];
76 	uint8_t gain_bits[10];
77 
78 	uint16_t init_gain;
79 	uint16_t rfseq_init[4];
80 
81 	uint16_t cliphi_gain;
82 	uint16_t clipmd_gain;
83 	uint16_t cliplo_gain;
84 
85 	uint16_t crsmin;
86 	uint16_t crsminl;
87 	uint16_t crsminu;
88 
89 	uint16_t nbclip;
90 	uint16_t wlclip;
91 };
92 
93 /* Get entry with workaround values for gain ctl. Does not return NULL. */
94 struct bwn_nphy_gain_ctl_workaround_entry *bwn_nphy_get_gain_ctl_workaround_ent(
95 	struct bwn_mac *mac, bool ghz5, bool ext_lna);
96 
97 
98 /* The N-PHY tables. */
99 #define BWN_NTAB_TYPEMASK		0xF0000000
100 #define BWN_NTAB_8BIT			0x10000000
101 #define BWN_NTAB_16BIT			0x20000000
102 #define BWN_NTAB_32BIT			0x30000000
103 #define BWN_NTAB8(table, offset)	(((table) << 10) | (offset) | BWN_NTAB_8BIT)
104 #define BWN_NTAB16(table, offset)	(((table) << 10) | (offset) | BWN_NTAB_16BIT)
105 #define BWN_NTAB32(table, offset)	(((table) << 10) | (offset) | BWN_NTAB_32BIT)
106 
107 /* Static N-PHY tables */
108 #define BWN_NTAB_FRAMESTRUCT		BWN_NTAB32(0x0A, 0x000) /* Frame Struct Table */
109 #define BWN_NTAB_FRAMESTRUCT_SIZE	832
110 #define BWN_NTAB_FRAMELT		BWN_NTAB8 (0x18, 0x000) /* Frame Lookup Table */
111 #define BWN_NTAB_FRAMELT_SIZE		32
112 #define BWN_NTAB_TMAP			BWN_NTAB32(0x0C, 0x000) /* T Map Table */
113 #define BWN_NTAB_TMAP_SIZE		448
114 #define BWN_NTAB_TDTRN			BWN_NTAB32(0x0E, 0x000) /* TDTRN Table */
115 #define BWN_NTAB_TDTRN_SIZE		704
116 #define BWN_NTAB_INTLEVEL		BWN_NTAB32(0x0D, 0x000) /* Int Level Table */
117 #define BWN_NTAB_INTLEVEL_SIZE		7
118 #define BWN_NTAB_PILOT			BWN_NTAB16(0x0B, 0x000) /* Pilot Table */
119 #define BWN_NTAB_PILOT_SIZE		88
120 #define BWN_NTAB_PILOTLT		BWN_NTAB32(0x14, 0x000) /* Pilot Lookup Table */
121 #define BWN_NTAB_PILOTLT_SIZE		6
122 #define BWN_NTAB_TDI20A0		BWN_NTAB32(0x13, 0x080) /* TDI Table 20 Antenna 0 */
123 #define BWN_NTAB_TDI20A0_SIZE		55
124 #define BWN_NTAB_TDI20A1		BWN_NTAB32(0x13, 0x100) /* TDI Table 20 Antenna 1 */
125 #define BWN_NTAB_TDI20A1_SIZE		55
126 #define BWN_NTAB_TDI40A0		BWN_NTAB32(0x13, 0x280) /* TDI Table 40 Antenna 0 */
127 #define BWN_NTAB_TDI40A0_SIZE		110
128 #define BWN_NTAB_TDI40A1		BWN_NTAB32(0x13, 0x300) /* TDI Table 40 Antenna 1 */
129 #define BWN_NTAB_TDI40A1_SIZE		110
130 #define BWN_NTAB_BDI			BWN_NTAB16(0x15, 0x000) /* BDI Table */
131 #define BWN_NTAB_BDI_SIZE		6
132 #define BWN_NTAB_CHANEST		BWN_NTAB32(0x16, 0x000) /* Channel Estimate Table */
133 #define BWN_NTAB_CHANEST_SIZE		96
134 #define BWN_NTAB_MCS			BWN_NTAB8 (0x12, 0x000) /* MCS Table */
135 #define BWN_NTAB_MCS_SIZE		128
136 
137 /* Volatile N-PHY tables */
138 #define BWN_NTAB_NOISEVAR10		BWN_NTAB32(0x10, 0x000) /* Noise Var Table 10 */
139 #define BWN_NTAB_NOISEVAR10_SIZE	256
140 #define BWN_NTAB_NOISEVAR11		BWN_NTAB32(0x10, 0x080) /* Noise Var Table 11 */
141 #define BWN_NTAB_NOISEVAR11_SIZE	256
142 #define BWN_NTAB_C0_ESTPLT		BWN_NTAB8 (0x1A, 0x000) /* Estimate Power Lookup Table Core 0 */
143 #define BWN_NTAB_C0_ESTPLT_SIZE		64
144 #define BWN_NTAB_C0_ADJPLT		BWN_NTAB8 (0x1A, 0x040) /* Adjust Power Lookup Table Core 0 */
145 #define BWN_NTAB_C0_ADJPLT_SIZE		128
146 #define BWN_NTAB_C0_GAINCTL		BWN_NTAB32(0x1A, 0x0C0) /* Gain Control Lookup Table Core 0 */
147 #define BWN_NTAB_C0_GAINCTL_SIZE	128
148 #define BWN_NTAB_C0_IQLT		BWN_NTAB32(0x1A, 0x140) /* IQ Lookup Table Core 0 */
149 #define BWN_NTAB_C0_IQLT_SIZE		128
150 #define BWN_NTAB_C0_LOFEEDTH		BWN_NTAB16(0x1A, 0x1C0) /* Local Oscillator Feed Through Lookup Table Core 0 */
151 #define BWN_NTAB_C0_LOFEEDTH_SIZE	128
152 #define BWN_NTAB_C1_ESTPLT		BWN_NTAB8 (0x1B, 0x000) /* Estimate Power Lookup Table Core 1 */
153 #define BWN_NTAB_C1_ESTPLT_SIZE		64
154 #define BWN_NTAB_C1_ADJPLT		BWN_NTAB8 (0x1B, 0x040) /* Adjust Power Lookup Table Core 1 */
155 #define BWN_NTAB_C1_ADJPLT_SIZE		128
156 #define BWN_NTAB_C1_GAINCTL		BWN_NTAB32(0x1B, 0x0C0) /* Gain Control Lookup Table Core 1 */
157 #define BWN_NTAB_C1_GAINCTL_SIZE	128
158 #define BWN_NTAB_C1_IQLT		BWN_NTAB32(0x1B, 0x140) /* IQ Lookup Table Core 1 */
159 #define BWN_NTAB_C1_IQLT_SIZE		128
160 #define BWN_NTAB_C1_LOFEEDTH		BWN_NTAB16(0x1B, 0x1C0) /* Local Oscillator Feed Through Lookup Table Core 1 */
161 #define BWN_NTAB_C1_LOFEEDTH_SIZE	128
162 
163 /* Volatile N-PHY tables, PHY revision >= 3 */
164 #define BWN_NTAB_ANT_SW_CTL_R3		BWN_NTAB16( 9,   0) /* antenna software control */
165 
166 /* Static N-PHY tables, PHY revision >= 3 */
167 #define BWN_NTAB_FRAMESTRUCT_R3		BWN_NTAB32(10,   0) /* frame struct  */
168 #define BWN_NTAB_PILOT_R3		BWN_NTAB16(11,   0) /* pilot  */
169 #define BWN_NTAB_TMAP_R3		BWN_NTAB32(12,   0) /* TM AP  */
170 #define BWN_NTAB_INTLEVEL_R3		BWN_NTAB32(13,   0) /* INT LV  */
171 #define BWN_NTAB_TDTRN_R3		BWN_NTAB32(14,   0) /* TD TRN  */
172 #define BWN_NTAB_NOISEVAR_R3		BWN_NTAB32(16,   0) /* noise variance */
173 #define BWN_NTAB_MCS_R3			BWN_NTAB16(18,   0) /* MCS  */
174 #define BWN_NTAB_TDI20A0_R3		BWN_NTAB32(19, 128) /* TDI 20/0  */
175 #define BWN_NTAB_TDI20A1_R3		BWN_NTAB32(19, 256) /* TDI 20/1  */
176 #define BWN_NTAB_TDI40A0_R3		BWN_NTAB32(19, 640) /* TDI 40/0  */
177 #define BWN_NTAB_TDI40A1_R3		BWN_NTAB32(19, 768) /* TDI 40/1  */
178 #define BWN_NTAB_PILOTLT_R3		BWN_NTAB32(20,   0) /* PLT lookup  */
179 #define BWN_NTAB_CHANEST_R3		BWN_NTAB32(22,   0) /* channel estimate  */
180 #define BWN_NTAB_FRAMELT_R3		 BWN_NTAB8(24,   0) /* frame lookup  */
181 #define BWN_NTAB_C0_ESTPLT_R3		 BWN_NTAB8(26,   0) /* estimated power lookup 0  */
182 #define BWN_NTAB_C0_ADJPLT_R3		 BWN_NTAB8(26,  64) /* adjusted power lookup 0  */
183 #define BWN_NTAB_C0_GAINCTL_R3		BWN_NTAB32(26, 192) /* gain control lookup 0  */
184 #define BWN_NTAB_C0_IQLT_R3		BWN_NTAB32(26, 320) /* I/Q lookup 0  */
185 #define BWN_NTAB_C0_LOFEEDTH_R3		BWN_NTAB16(26, 448) /* Local Oscillator Feed Through lookup 0  */
186 #define BWN_NTAB_C0_PAPD_COMP_R3	BWN_NTAB16(26, 576)
187 #define BWN_NTAB_C1_ESTPLT_R3		 BWN_NTAB8(27,   0) /* estimated power lookup 1  */
188 #define BWN_NTAB_C1_ADJPLT_R3		 BWN_NTAB8(27,  64) /* adjusted power lookup 1  */
189 #define BWN_NTAB_C1_GAINCTL_R3		BWN_NTAB32(27, 192) /* gain control lookup 1  */
190 #define BWN_NTAB_C1_IQLT_R3		BWN_NTAB32(27, 320) /* I/Q lookup 1  */
191 #define BWN_NTAB_C1_LOFEEDTH_R3		BWN_NTAB16(27, 448) /* Local Oscillator Feed Through lookup 1 */
192 #define BWN_NTAB_C1_PAPD_COMP_R3	BWN_NTAB16(27, 576)
193 
194 /* Static N-PHY tables, PHY revision >= 7 */
195 #define BWN_NTAB_TMAP_R7		BWN_NTAB32(12,   0) /* TM AP */
196 #define BWN_NTAB_NOISEVAR_R7		BWN_NTAB32(16,   0) /* noise variance */
197 
198 #define BWN_NTAB_TX_IQLO_CAL_LOFT_LADDER_40_SIZE	18
199 #define BWN_NTAB_TX_IQLO_CAL_LOFT_LADDER_20_SIZE	18
200 #define BWN_NTAB_TX_IQLO_CAL_IQIMB_LADDER_40_SIZE	18
201 #define BWN_NTAB_TX_IQLO_CAL_IQIMB_LADDER_20_SIZE	18
202 #define BWN_NTAB_TX_IQLO_CAL_STARTCOEFS_REV3		11
203 #define BWN_NTAB_TX_IQLO_CAL_STARTCOEFS			9
204 #define BWN_NTAB_TX_IQLO_CAL_CMDS_RECAL_REV3		12
205 #define BWN_NTAB_TX_IQLO_CAL_CMDS_RECAL			10
206 #define BWN_NTAB_TX_IQLO_CAL_CMDS_FULLCAL		10
207 #define BWN_NTAB_TX_IQLO_CAL_CMDS_FULLCAL_REV3		12
208 
209 uint32_t bwn_ntab_read(struct bwn_mac *mac, uint32_t offset);
210 void bwn_ntab_read_bulk(struct bwn_mac *mac, uint32_t offset,
211 			 unsigned int nr_elements, void *_data);
212 void bwn_ntab_write(struct bwn_mac *mac, uint32_t offset, uint32_t value);
213 void bwn_ntab_write_bulk(struct bwn_mac *mac, uint32_t offset,
214 			  unsigned int nr_elements, const void *_data);
215 
216 void bwn_nphy_tables_init(struct bwn_mac *mac);
217 
218 const uint32_t *bwn_nphy_get_tx_gain_table(struct bwn_mac *mac);
219 
220 const int16_t *bwn_ntab_get_rf_pwr_offset_table(struct bwn_mac *mac);
221 
222 extern const int8_t bwn_ntab_papd_pga_gain_delta_ipa_2g[];
223 
224 extern const uint16_t tbl_iqcal_gainparams[2][9][8];
225 extern const struct bwn_nphy_txiqcal_ladder ladder_lo[];
226 extern const struct bwn_nphy_txiqcal_ladder ladder_iq[];
227 extern const uint16_t loscale[];
228 
229 extern const uint16_t tbl_tx_iqlo_cal_loft_ladder_40[];
230 extern const uint16_t tbl_tx_iqlo_cal_loft_ladder_20[];
231 extern const uint16_t tbl_tx_iqlo_cal_iqimb_ladder_40[];
232 extern const uint16_t tbl_tx_iqlo_cal_iqimb_ladder_20[];
233 extern const uint16_t tbl_tx_iqlo_cal_startcoefs_nphyrev3[];
234 extern const uint16_t tbl_tx_iqlo_cal_startcoefs[];
235 extern const uint16_t tbl_tx_iqlo_cal_cmds_recal_nphyrev3[];
236 extern const uint16_t tbl_tx_iqlo_cal_cmds_recal[];
237 extern const uint16_t tbl_tx_iqlo_cal_cmds_fullcal[];
238 extern const uint16_t tbl_tx_iqlo_cal_cmds_fullcal_nphyrev3[];
239 extern const int16_t tbl_tx_filter_coef_rev4[7][15];
240 
241 extern const struct bwn_nphy_rf_control_override_rev2
242 	tbl_rf_control_override_rev2[];
243 extern const struct bwn_nphy_rf_control_override_rev3
244 	tbl_rf_control_override_rev3[];
245 const struct bwn_nphy_rf_control_override_rev7 *bwn_nphy_get_rf_ctl_over_rev7(
246 	struct bwn_mac *mac, uint16_t field, uint8_t override);
247 
248 #endif	/* __IF_BWN_PHY_TABLES_N_H__ */
249