xref: /linux/drivers/net/wireless/ath/ath5k/eeprom.c (revision 6a2a0e738225fc9ec063f84b79f0adf5c0ed176c)
1203c4805SLuis R. Rodriguez /*
2203c4805SLuis R. Rodriguez  * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
3203c4805SLuis R. Rodriguez  * Copyright (c) 2006-2009 Nick Kossifidis <mickflemm@gmail.com>
4203c4805SLuis R. Rodriguez  * Copyright (c) 2008-2009 Felix Fietkau <nbd@openwrt.org>
5203c4805SLuis R. Rodriguez  *
6203c4805SLuis R. Rodriguez  * Permission to use, copy, modify, and distribute this software for any
7203c4805SLuis R. Rodriguez  * purpose with or without fee is hereby granted, provided that the above
8203c4805SLuis R. Rodriguez  * copyright notice and this permission notice appear in all copies.
9203c4805SLuis R. Rodriguez  *
10203c4805SLuis R. Rodriguez  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11203c4805SLuis R. Rodriguez  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12203c4805SLuis R. Rodriguez  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13203c4805SLuis R. Rodriguez  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14203c4805SLuis R. Rodriguez  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15203c4805SLuis R. Rodriguez  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16203c4805SLuis R. Rodriguez  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17203c4805SLuis R. Rodriguez  *
18203c4805SLuis R. Rodriguez  */
19203c4805SLuis R. Rodriguez 
20203c4805SLuis R. Rodriguez /*************************************\
21203c4805SLuis R. Rodriguez * EEPROM access functions and helpers *
22203c4805SLuis R. Rodriguez \*************************************/
23203c4805SLuis R. Rodriguez 
245a0e3ad6STejun Heo #include <linux/slab.h>
255a0e3ad6STejun Heo 
26203c4805SLuis R. Rodriguez #include "ath5k.h"
27203c4805SLuis R. Rodriguez #include "reg.h"
28203c4805SLuis R. Rodriguez #include "debug.h"
29203c4805SLuis R. Rodriguez #include "base.h"
30203c4805SLuis R. Rodriguez 
319320b5c4SNick Kossifidis 
329320b5c4SNick Kossifidis /******************\
339320b5c4SNick Kossifidis * Helper functions *
349320b5c4SNick Kossifidis \******************/
359320b5c4SNick Kossifidis 
369320b5c4SNick Kossifidis /*
379320b5c4SNick Kossifidis  * Translate binary channel representation in EEPROM to frequency
389320b5c4SNick Kossifidis  */
399320b5c4SNick Kossifidis static u16 ath5k_eeprom_bin2freq(struct ath5k_eeprom_info *ee, u16 bin,
409320b5c4SNick Kossifidis 							unsigned int mode)
419320b5c4SNick Kossifidis {
429320b5c4SNick Kossifidis 	u16 val;
439320b5c4SNick Kossifidis 
449320b5c4SNick Kossifidis 	if (bin == AR5K_EEPROM_CHANNEL_DIS)
459320b5c4SNick Kossifidis 		return bin;
469320b5c4SNick Kossifidis 
479320b5c4SNick Kossifidis 	if (mode == AR5K_EEPROM_MODE_11A) {
489320b5c4SNick Kossifidis 		if (ee->ee_version > AR5K_EEPROM_VERSION_3_2)
499320b5c4SNick Kossifidis 			val = (5 * bin) + 4800;
509320b5c4SNick Kossifidis 		else
519320b5c4SNick Kossifidis 			val = bin > 62 ? (10 * 62) + (5 * (bin - 62)) + 5100 :
529320b5c4SNick Kossifidis 				(bin * 10) + 5100;
539320b5c4SNick Kossifidis 	} else {
549320b5c4SNick Kossifidis 		if (ee->ee_version > AR5K_EEPROM_VERSION_3_2)
559320b5c4SNick Kossifidis 			val = bin + 2300;
569320b5c4SNick Kossifidis 		else
579320b5c4SNick Kossifidis 			val = bin + 2400;
589320b5c4SNick Kossifidis 	}
599320b5c4SNick Kossifidis 
609320b5c4SNick Kossifidis 	return val;
619320b5c4SNick Kossifidis }
629320b5c4SNick Kossifidis 
639320b5c4SNick Kossifidis 
649320b5c4SNick Kossifidis /*********\
659320b5c4SNick Kossifidis * Parsers *
669320b5c4SNick Kossifidis \*********/
679320b5c4SNick Kossifidis 
68203c4805SLuis R. Rodriguez /*
69203c4805SLuis R. Rodriguez  * Initialize eeprom & capabilities structs
70203c4805SLuis R. Rodriguez  */
71203c4805SLuis R. Rodriguez static int
72203c4805SLuis R. Rodriguez ath5k_eeprom_init_header(struct ath5k_hw *ah)
73203c4805SLuis R. Rodriguez {
74203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
75203c4805SLuis R. Rodriguez 	u16 val;
76359207c6SLuis R. Rodriguez 	u32 cksum, offset, eep_max = AR5K_EEPROM_INFO_MAX;
77203c4805SLuis R. Rodriguez 
78203c4805SLuis R. Rodriguez 	/*
79203c4805SLuis R. Rodriguez 	 * Read values from EEPROM and store them in the capability structure
80203c4805SLuis R. Rodriguez 	 */
81203c4805SLuis R. Rodriguez 	AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MAGIC, ee_magic);
82203c4805SLuis R. Rodriguez 	AR5K_EEPROM_READ_HDR(AR5K_EEPROM_PROTECT, ee_protect);
83203c4805SLuis R. Rodriguez 	AR5K_EEPROM_READ_HDR(AR5K_EEPROM_REG_DOMAIN, ee_regdomain);
84203c4805SLuis R. Rodriguez 	AR5K_EEPROM_READ_HDR(AR5K_EEPROM_VERSION, ee_version);
85203c4805SLuis R. Rodriguez 	AR5K_EEPROM_READ_HDR(AR5K_EEPROM_HDR, ee_header);
86203c4805SLuis R. Rodriguez 
87203c4805SLuis R. Rodriguez 	/* Return if we have an old EEPROM */
88203c4805SLuis R. Rodriguez 	if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_0)
89203c4805SLuis R. Rodriguez 		return 0;
90203c4805SLuis R. Rodriguez 
91203c4805SLuis R. Rodriguez 	/*
92203c4805SLuis R. Rodriguez 	 * Validate the checksum of the EEPROM date. There are some
93203c4805SLuis R. Rodriguez 	 * devices with invalid EEPROMs.
94203c4805SLuis R. Rodriguez 	 */
95359207c6SLuis R. Rodriguez 	AR5K_EEPROM_READ(AR5K_EEPROM_SIZE_UPPER, val);
96359207c6SLuis R. Rodriguez 	if (val) {
97359207c6SLuis R. Rodriguez 		eep_max = (val & AR5K_EEPROM_SIZE_UPPER_MASK) <<
98359207c6SLuis R. Rodriguez 			   AR5K_EEPROM_SIZE_ENDLOC_SHIFT;
99359207c6SLuis R. Rodriguez 		AR5K_EEPROM_READ(AR5K_EEPROM_SIZE_LOWER, val);
100359207c6SLuis R. Rodriguez 		eep_max = (eep_max | val) - AR5K_EEPROM_INFO_BASE;
101359207c6SLuis R. Rodriguez 
102359207c6SLuis R. Rodriguez 		/*
103359207c6SLuis R. Rodriguez 		 * Fail safe check to prevent stupid loops due
104359207c6SLuis R. Rodriguez 		 * to busted EEPROMs. XXX: This value is likely too
105359207c6SLuis R. Rodriguez 		 * big still, waiting on a better value.
106359207c6SLuis R. Rodriguez 		 */
107359207c6SLuis R. Rodriguez 		if (eep_max > (3 * AR5K_EEPROM_INFO_MAX)) {
108359207c6SLuis R. Rodriguez 			ATH5K_ERR(ah->ah_sc, "Invalid max custom EEPROM size: "
109359207c6SLuis R. Rodriguez 				  "%d (0x%04x) max expected: %d (0x%04x)\n",
110359207c6SLuis R. Rodriguez 				  eep_max, eep_max,
111359207c6SLuis R. Rodriguez 				  3 * AR5K_EEPROM_INFO_MAX,
112359207c6SLuis R. Rodriguez 				  3 * AR5K_EEPROM_INFO_MAX);
113359207c6SLuis R. Rodriguez 			return -EIO;
114359207c6SLuis R. Rodriguez 		}
115359207c6SLuis R. Rodriguez 	}
116359207c6SLuis R. Rodriguez 
117359207c6SLuis R. Rodriguez 	for (cksum = 0, offset = 0; offset < eep_max; offset++) {
118203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(AR5K_EEPROM_INFO(offset), val);
119203c4805SLuis R. Rodriguez 		cksum ^= val;
120203c4805SLuis R. Rodriguez 	}
121203c4805SLuis R. Rodriguez 	if (cksum != AR5K_EEPROM_INFO_CKSUM) {
122359207c6SLuis R. Rodriguez 		ATH5K_ERR(ah->ah_sc, "Invalid EEPROM "
123359207c6SLuis R. Rodriguez 			  "checksum: 0x%04x eep_max: 0x%04x (%s)\n",
124359207c6SLuis R. Rodriguez 			  cksum, eep_max,
125359207c6SLuis R. Rodriguez 			  eep_max == AR5K_EEPROM_INFO_MAX ?
126359207c6SLuis R. Rodriguez 				"default size" : "custom size");
127203c4805SLuis R. Rodriguez 		return -EIO;
128203c4805SLuis R. Rodriguez 	}
129203c4805SLuis R. Rodriguez 
130203c4805SLuis R. Rodriguez 	AR5K_EEPROM_READ_HDR(AR5K_EEPROM_ANT_GAIN(ah->ah_ee_version),
131203c4805SLuis R. Rodriguez 	    ee_ant_gain);
132203c4805SLuis R. Rodriguez 
133203c4805SLuis R. Rodriguez 	if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
134203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC0, ee_misc0);
135203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC1, ee_misc1);
136203c4805SLuis R. Rodriguez 
137203c4805SLuis R. Rodriguez 		/* XXX: Don't know which versions include these two */
138203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC2, ee_misc2);
139203c4805SLuis R. Rodriguez 
140203c4805SLuis R. Rodriguez 		if (ee->ee_version >= AR5K_EEPROM_VERSION_4_3)
141203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC3, ee_misc3);
142203c4805SLuis R. Rodriguez 
143203c4805SLuis R. Rodriguez 		if (ee->ee_version >= AR5K_EEPROM_VERSION_5_0) {
144203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC4, ee_misc4);
145203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC5, ee_misc5);
146203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC6, ee_misc6);
147203c4805SLuis R. Rodriguez 		}
148203c4805SLuis R. Rodriguez 	}
149203c4805SLuis R. Rodriguez 
150203c4805SLuis R. Rodriguez 	if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_3) {
151203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(AR5K_EEPROM_OBDB0_2GHZ, val);
152203c4805SLuis R. Rodriguez 		ee->ee_ob[AR5K_EEPROM_MODE_11B][0] = val & 0x7;
153203c4805SLuis R. Rodriguez 		ee->ee_db[AR5K_EEPROM_MODE_11B][0] = (val >> 3) & 0x7;
154203c4805SLuis R. Rodriguez 
155203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(AR5K_EEPROM_OBDB1_2GHZ, val);
156203c4805SLuis R. Rodriguez 		ee->ee_ob[AR5K_EEPROM_MODE_11G][0] = val & 0x7;
157203c4805SLuis R. Rodriguez 		ee->ee_db[AR5K_EEPROM_MODE_11G][0] = (val >> 3) & 0x7;
158203c4805SLuis R. Rodriguez 	}
159203c4805SLuis R. Rodriguez 
1601889ba0aSNick Kossifidis 	AR5K_EEPROM_READ(AR5K_EEPROM_IS_HB63, val);
1611889ba0aSNick Kossifidis 
1621889ba0aSNick Kossifidis 	if ((ah->ah_mac_version == (AR5K_SREV_AR2425 >> 4)) && val)
1631889ba0aSNick Kossifidis 		ee->ee_is_hb63 = true;
1641889ba0aSNick Kossifidis 	else
1651889ba0aSNick Kossifidis 		ee->ee_is_hb63 = false;
1661889ba0aSNick Kossifidis 
1671889ba0aSNick Kossifidis 	AR5K_EEPROM_READ(AR5K_EEPROM_RFKILL, val);
1681889ba0aSNick Kossifidis 	ee->ee_rfkill_pin = (u8) AR5K_REG_MS(val, AR5K_EEPROM_RFKILL_GPIO_SEL);
1691889ba0aSNick Kossifidis 	ee->ee_rfkill_pol = val & AR5K_EEPROM_RFKILL_POLARITY ? true : false;
1701889ba0aSNick Kossifidis 
171c38e7a93SNick Kossifidis 	/* Check if PCIE_OFFSET points to PCIE_SERDES_SECTION
172c38e7a93SNick Kossifidis 	 * and enable serdes programming if needed.
173c38e7a93SNick Kossifidis 	 *
174c38e7a93SNick Kossifidis 	 * XXX: Serdes values seem to be fixed so
175c38e7a93SNick Kossifidis 	 * no need to read them here, we write them
176132b1c3eSFelix Fietkau 	 * during ath5k_hw_init */
177c38e7a93SNick Kossifidis 	AR5K_EEPROM_READ(AR5K_EEPROM_PCIE_OFFSET, val);
178c38e7a93SNick Kossifidis 	ee->ee_serdes = (val == AR5K_EEPROM_PCIE_SERDES_SECTION) ?
179c38e7a93SNick Kossifidis 							true : false;
180c38e7a93SNick Kossifidis 
181203c4805SLuis R. Rodriguez 	return 0;
182203c4805SLuis R. Rodriguez }
183203c4805SLuis R. Rodriguez 
184203c4805SLuis R. Rodriguez 
185203c4805SLuis R. Rodriguez /*
186203c4805SLuis R. Rodriguez  * Read antenna infos from eeprom
187203c4805SLuis R. Rodriguez  */
188203c4805SLuis R. Rodriguez static int ath5k_eeprom_read_ants(struct ath5k_hw *ah, u32 *offset,
189203c4805SLuis R. Rodriguez 		unsigned int mode)
190203c4805SLuis R. Rodriguez {
191203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
192203c4805SLuis R. Rodriguez 	u32 o = *offset;
193203c4805SLuis R. Rodriguez 	u16 val;
194fda9b7afSWojciech Dubowik 	int i = 0;
195203c4805SLuis R. Rodriguez 
196203c4805SLuis R. Rodriguez 	AR5K_EEPROM_READ(o++, val);
197203c4805SLuis R. Rodriguez 	ee->ee_switch_settling[mode]	= (val >> 8) & 0x7f;
198203c4805SLuis R. Rodriguez 	ee->ee_atn_tx_rx[mode]		= (val >> 2) & 0x3f;
199203c4805SLuis R. Rodriguez 	ee->ee_ant_control[mode][i]	= (val << 4) & 0x3f;
200203c4805SLuis R. Rodriguez 
201203c4805SLuis R. Rodriguez 	AR5K_EEPROM_READ(o++, val);
202203c4805SLuis R. Rodriguez 	ee->ee_ant_control[mode][i++]	|= (val >> 12) & 0xf;
203203c4805SLuis R. Rodriguez 	ee->ee_ant_control[mode][i++]	= (val >> 6) & 0x3f;
204203c4805SLuis R. Rodriguez 	ee->ee_ant_control[mode][i++]	= val & 0x3f;
205203c4805SLuis R. Rodriguez 
206203c4805SLuis R. Rodriguez 	AR5K_EEPROM_READ(o++, val);
207203c4805SLuis R. Rodriguez 	ee->ee_ant_control[mode][i++]	= (val >> 10) & 0x3f;
208203c4805SLuis R. Rodriguez 	ee->ee_ant_control[mode][i++]	= (val >> 4) & 0x3f;
209203c4805SLuis R. Rodriguez 	ee->ee_ant_control[mode][i]	= (val << 2) & 0x3f;
210203c4805SLuis R. Rodriguez 
211203c4805SLuis R. Rodriguez 	AR5K_EEPROM_READ(o++, val);
212203c4805SLuis R. Rodriguez 	ee->ee_ant_control[mode][i++]	|= (val >> 14) & 0x3;
213203c4805SLuis R. Rodriguez 	ee->ee_ant_control[mode][i++]	= (val >> 8) & 0x3f;
214203c4805SLuis R. Rodriguez 	ee->ee_ant_control[mode][i++]	= (val >> 2) & 0x3f;
215203c4805SLuis R. Rodriguez 	ee->ee_ant_control[mode][i]	= (val << 4) & 0x3f;
216203c4805SLuis R. Rodriguez 
217203c4805SLuis R. Rodriguez 	AR5K_EEPROM_READ(o++, val);
218203c4805SLuis R. Rodriguez 	ee->ee_ant_control[mode][i++]	|= (val >> 12) & 0xf;
219203c4805SLuis R. Rodriguez 	ee->ee_ant_control[mode][i++]	= (val >> 6) & 0x3f;
220203c4805SLuis R. Rodriguez 	ee->ee_ant_control[mode][i++]	= val & 0x3f;
221203c4805SLuis R. Rodriguez 
2222bed03ebSNick Kossifidis 	/* Get antenna switch tables */
2232bed03ebSNick Kossifidis 	ah->ah_ant_ctl[mode][AR5K_ANT_CTL] =
224203c4805SLuis R. Rodriguez 	    (ee->ee_ant_control[mode][0] << 4);
2252bed03ebSNick Kossifidis 	ah->ah_ant_ctl[mode][AR5K_ANT_SWTABLE_A] =
226203c4805SLuis R. Rodriguez 	     ee->ee_ant_control[mode][1]	|
227203c4805SLuis R. Rodriguez 	    (ee->ee_ant_control[mode][2] << 6)	|
228203c4805SLuis R. Rodriguez 	    (ee->ee_ant_control[mode][3] << 12) |
229203c4805SLuis R. Rodriguez 	    (ee->ee_ant_control[mode][4] << 18) |
230203c4805SLuis R. Rodriguez 	    (ee->ee_ant_control[mode][5] << 24);
2312bed03ebSNick Kossifidis 	ah->ah_ant_ctl[mode][AR5K_ANT_SWTABLE_B] =
232203c4805SLuis R. Rodriguez 	     ee->ee_ant_control[mode][6]	|
233203c4805SLuis R. Rodriguez 	    (ee->ee_ant_control[mode][7] << 6)	|
234203c4805SLuis R. Rodriguez 	    (ee->ee_ant_control[mode][8] << 12) |
235203c4805SLuis R. Rodriguez 	    (ee->ee_ant_control[mode][9] << 18) |
236203c4805SLuis R. Rodriguez 	    (ee->ee_ant_control[mode][10] << 24);
237203c4805SLuis R. Rodriguez 
238203c4805SLuis R. Rodriguez 	/* return new offset */
239203c4805SLuis R. Rodriguez 	*offset = o;
240203c4805SLuis R. Rodriguez 
241203c4805SLuis R. Rodriguez 	return 0;
242203c4805SLuis R. Rodriguez }
243203c4805SLuis R. Rodriguez 
244203c4805SLuis R. Rodriguez /*
245203c4805SLuis R. Rodriguez  * Read supported modes and some mode-specific calibration data
246203c4805SLuis R. Rodriguez  * from eeprom
247203c4805SLuis R. Rodriguez  */
248203c4805SLuis R. Rodriguez static int ath5k_eeprom_read_modes(struct ath5k_hw *ah, u32 *offset,
249203c4805SLuis R. Rodriguez 		unsigned int mode)
250203c4805SLuis R. Rodriguez {
251203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
252203c4805SLuis R. Rodriguez 	u32 o = *offset;
253203c4805SLuis R. Rodriguez 	u16 val;
254203c4805SLuis R. Rodriguez 
255203c4805SLuis R. Rodriguez 	ee->ee_n_piers[mode] = 0;
256203c4805SLuis R. Rodriguez 	AR5K_EEPROM_READ(o++, val);
257203c4805SLuis R. Rodriguez 	ee->ee_adc_desired_size[mode]	= (s8)((val >> 8) & 0xff);
258203c4805SLuis R. Rodriguez 	switch (mode) {
259203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11A:
260203c4805SLuis R. Rodriguez 		ee->ee_ob[mode][3]	= (val >> 5) & 0x7;
261203c4805SLuis R. Rodriguez 		ee->ee_db[mode][3]	= (val >> 2) & 0x7;
262203c4805SLuis R. Rodriguez 		ee->ee_ob[mode][2]	= (val << 1) & 0x7;
263203c4805SLuis R. Rodriguez 
264203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(o++, val);
265203c4805SLuis R. Rodriguez 		ee->ee_ob[mode][2]	|= (val >> 15) & 0x1;
266203c4805SLuis R. Rodriguez 		ee->ee_db[mode][2]	= (val >> 12) & 0x7;
267203c4805SLuis R. Rodriguez 		ee->ee_ob[mode][1]	= (val >> 9) & 0x7;
268203c4805SLuis R. Rodriguez 		ee->ee_db[mode][1]	= (val >> 6) & 0x7;
269203c4805SLuis R. Rodriguez 		ee->ee_ob[mode][0]	= (val >> 3) & 0x7;
270203c4805SLuis R. Rodriguez 		ee->ee_db[mode][0]	= val & 0x7;
271203c4805SLuis R. Rodriguez 		break;
272203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11G:
273203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11B:
274203c4805SLuis R. Rodriguez 		ee->ee_ob[mode][1]	= (val >> 4) & 0x7;
275203c4805SLuis R. Rodriguez 		ee->ee_db[mode][1]	= val & 0x7;
276203c4805SLuis R. Rodriguez 		break;
277203c4805SLuis R. Rodriguez 	}
278203c4805SLuis R. Rodriguez 
279203c4805SLuis R. Rodriguez 	AR5K_EEPROM_READ(o++, val);
280203c4805SLuis R. Rodriguez 	ee->ee_tx_end2xlna_enable[mode]	= (val >> 8) & 0xff;
281203c4805SLuis R. Rodriguez 	ee->ee_thr_62[mode]		= val & 0xff;
282203c4805SLuis R. Rodriguez 
283203c4805SLuis R. Rodriguez 	if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
284203c4805SLuis R. Rodriguez 		ee->ee_thr_62[mode] = mode == AR5K_EEPROM_MODE_11A ? 15 : 28;
285203c4805SLuis R. Rodriguez 
286203c4805SLuis R. Rodriguez 	AR5K_EEPROM_READ(o++, val);
287203c4805SLuis R. Rodriguez 	ee->ee_tx_end2xpa_disable[mode]	= (val >> 8) & 0xff;
288203c4805SLuis R. Rodriguez 	ee->ee_tx_frm2xpa_enable[mode]	= val & 0xff;
289203c4805SLuis R. Rodriguez 
290203c4805SLuis R. Rodriguez 	AR5K_EEPROM_READ(o++, val);
291203c4805SLuis R. Rodriguez 	ee->ee_pga_desired_size[mode]	= (val >> 8) & 0xff;
292203c4805SLuis R. Rodriguez 
293203c4805SLuis R. Rodriguez 	if ((val & 0xff) & 0x80)
294203c4805SLuis R. Rodriguez 		ee->ee_noise_floor_thr[mode] = -((((val & 0xff) ^ 0xff)) + 1);
295203c4805SLuis R. Rodriguez 	else
296203c4805SLuis R. Rodriguez 		ee->ee_noise_floor_thr[mode] = val & 0xff;
297203c4805SLuis R. Rodriguez 
298203c4805SLuis R. Rodriguez 	if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
299203c4805SLuis R. Rodriguez 		ee->ee_noise_floor_thr[mode] =
300203c4805SLuis R. Rodriguez 		    mode == AR5K_EEPROM_MODE_11A ? -54 : -1;
301203c4805SLuis R. Rodriguez 
302203c4805SLuis R. Rodriguez 	AR5K_EEPROM_READ(o++, val);
303203c4805SLuis R. Rodriguez 	ee->ee_xlna_gain[mode]		= (val >> 5) & 0xff;
304203c4805SLuis R. Rodriguez 	ee->ee_x_gain[mode]		= (val >> 1) & 0xf;
305203c4805SLuis R. Rodriguez 	ee->ee_xpd[mode]		= val & 0x1;
306203c4805SLuis R. Rodriguez 
307687c8ff1SBruno Randolf 	if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0 &&
308687c8ff1SBruno Randolf 	    mode != AR5K_EEPROM_MODE_11B)
309203c4805SLuis R. Rodriguez 		ee->ee_fixed_bias[mode] = (val >> 13) & 0x1;
310203c4805SLuis R. Rodriguez 
311203c4805SLuis R. Rodriguez 	if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_3) {
312203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(o++, val);
313203c4805SLuis R. Rodriguez 		ee->ee_false_detect[mode] = (val >> 6) & 0x7f;
314203c4805SLuis R. Rodriguez 
315203c4805SLuis R. Rodriguez 		if (mode == AR5K_EEPROM_MODE_11A)
316203c4805SLuis R. Rodriguez 			ee->ee_xr_power[mode] = val & 0x3f;
317203c4805SLuis R. Rodriguez 		else {
318687c8ff1SBruno Randolf 			/* b_DB_11[bg] and b_OB_11[bg] */
319203c4805SLuis R. Rodriguez 			ee->ee_ob[mode][0] = val & 0x7;
320203c4805SLuis R. Rodriguez 			ee->ee_db[mode][0] = (val >> 3) & 0x7;
321203c4805SLuis R. Rodriguez 		}
322203c4805SLuis R. Rodriguez 	}
323203c4805SLuis R. Rodriguez 
324203c4805SLuis R. Rodriguez 	if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_4) {
325203c4805SLuis R. Rodriguez 		ee->ee_i_gain[mode] = AR5K_EEPROM_I_GAIN;
326203c4805SLuis R. Rodriguez 		ee->ee_cck_ofdm_power_delta = AR5K_EEPROM_CCK_OFDM_DELTA;
327203c4805SLuis R. Rodriguez 	} else {
328203c4805SLuis R. Rodriguez 		ee->ee_i_gain[mode] = (val >> 13) & 0x7;
329203c4805SLuis R. Rodriguez 
330203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(o++, val);
331203c4805SLuis R. Rodriguez 		ee->ee_i_gain[mode] |= (val << 3) & 0x38;
332203c4805SLuis R. Rodriguez 
333203c4805SLuis R. Rodriguez 		if (mode == AR5K_EEPROM_MODE_11G) {
334203c4805SLuis R. Rodriguez 			ee->ee_cck_ofdm_power_delta = (val >> 3) & 0xff;
335203c4805SLuis R. Rodriguez 			if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_6)
336203c4805SLuis R. Rodriguez 				ee->ee_scaled_cck_delta = (val >> 11) & 0x1f;
337203c4805SLuis R. Rodriguez 		}
338203c4805SLuis R. Rodriguez 	}
339203c4805SLuis R. Rodriguez 
340203c4805SLuis R. Rodriguez 	if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0 &&
341203c4805SLuis R. Rodriguez 			mode == AR5K_EEPROM_MODE_11A) {
342203c4805SLuis R. Rodriguez 		ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
343203c4805SLuis R. Rodriguez 		ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
344203c4805SLuis R. Rodriguez 	}
345203c4805SLuis R. Rodriguez 
346203c4805SLuis R. Rodriguez 	if (ah->ah_ee_version < AR5K_EEPROM_VERSION_4_0)
347203c4805SLuis R. Rodriguez 		goto done;
348203c4805SLuis R. Rodriguez 
349203c4805SLuis R. Rodriguez 	/* Note: >= v5 have bg freq piers on another location
350203c4805SLuis R. Rodriguez 	 * so these freq piers are ignored for >= v5 (should be 0xff
351203c4805SLuis R. Rodriguez 	 * anyway) */
352203c4805SLuis R. Rodriguez 	switch (mode) {
353203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11A:
354203c4805SLuis R. Rodriguez 		if (ah->ah_ee_version < AR5K_EEPROM_VERSION_4_1)
355203c4805SLuis R. Rodriguez 			break;
356203c4805SLuis R. Rodriguez 
357203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(o++, val);
358203c4805SLuis R. Rodriguez 		ee->ee_margin_tx_rx[mode] = val & 0x3f;
359203c4805SLuis R. Rodriguez 		break;
360203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11B:
361203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(o++, val);
362203c4805SLuis R. Rodriguez 
363203c4805SLuis R. Rodriguez 		ee->ee_pwr_cal_b[0].freq =
364203c4805SLuis R. Rodriguez 			ath5k_eeprom_bin2freq(ee, val & 0xff, mode);
365203c4805SLuis R. Rodriguez 		if (ee->ee_pwr_cal_b[0].freq != AR5K_EEPROM_CHANNEL_DIS)
366203c4805SLuis R. Rodriguez 			ee->ee_n_piers[mode]++;
367203c4805SLuis R. Rodriguez 
368203c4805SLuis R. Rodriguez 		ee->ee_pwr_cal_b[1].freq =
369203c4805SLuis R. Rodriguez 			ath5k_eeprom_bin2freq(ee, (val >> 8) & 0xff, mode);
370203c4805SLuis R. Rodriguez 		if (ee->ee_pwr_cal_b[1].freq != AR5K_EEPROM_CHANNEL_DIS)
371203c4805SLuis R. Rodriguez 			ee->ee_n_piers[mode]++;
372203c4805SLuis R. Rodriguez 
373203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(o++, val);
374203c4805SLuis R. Rodriguez 		ee->ee_pwr_cal_b[2].freq =
375203c4805SLuis R. Rodriguez 			ath5k_eeprom_bin2freq(ee, val & 0xff, mode);
376203c4805SLuis R. Rodriguez 		if (ee->ee_pwr_cal_b[2].freq != AR5K_EEPROM_CHANNEL_DIS)
377203c4805SLuis R. Rodriguez 			ee->ee_n_piers[mode]++;
378203c4805SLuis R. Rodriguez 
379203c4805SLuis R. Rodriguez 		if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
380203c4805SLuis R. Rodriguez 			ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
381203c4805SLuis R. Rodriguez 		break;
382203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11G:
383203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(o++, val);
384203c4805SLuis R. Rodriguez 
385203c4805SLuis R. Rodriguez 		ee->ee_pwr_cal_g[0].freq =
386203c4805SLuis R. Rodriguez 			ath5k_eeprom_bin2freq(ee, val & 0xff, mode);
387203c4805SLuis R. Rodriguez 		if (ee->ee_pwr_cal_g[0].freq != AR5K_EEPROM_CHANNEL_DIS)
388203c4805SLuis R. Rodriguez 			ee->ee_n_piers[mode]++;
389203c4805SLuis R. Rodriguez 
390203c4805SLuis R. Rodriguez 		ee->ee_pwr_cal_g[1].freq =
391203c4805SLuis R. Rodriguez 			ath5k_eeprom_bin2freq(ee, (val >> 8) & 0xff, mode);
392203c4805SLuis R. Rodriguez 		if (ee->ee_pwr_cal_g[1].freq != AR5K_EEPROM_CHANNEL_DIS)
393203c4805SLuis R. Rodriguez 			ee->ee_n_piers[mode]++;
394203c4805SLuis R. Rodriguez 
395203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(o++, val);
396203c4805SLuis R. Rodriguez 		ee->ee_turbo_max_power[mode] = val & 0x7f;
397203c4805SLuis R. Rodriguez 		ee->ee_xr_power[mode] = (val >> 7) & 0x3f;
398203c4805SLuis R. Rodriguez 
399203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(o++, val);
400203c4805SLuis R. Rodriguez 		ee->ee_pwr_cal_g[2].freq =
401203c4805SLuis R. Rodriguez 			ath5k_eeprom_bin2freq(ee, val & 0xff, mode);
402203c4805SLuis R. Rodriguez 		if (ee->ee_pwr_cal_g[2].freq != AR5K_EEPROM_CHANNEL_DIS)
403203c4805SLuis R. Rodriguez 			ee->ee_n_piers[mode]++;
404203c4805SLuis R. Rodriguez 
405203c4805SLuis R. Rodriguez 		if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
406203c4805SLuis R. Rodriguez 			ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
407203c4805SLuis R. Rodriguez 
408203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(o++, val);
4095f13bfacSBruno Randolf 		ee->ee_i_cal[mode] = (val >> 5) & 0x3f;
4105f13bfacSBruno Randolf 		ee->ee_q_cal[mode] = val & 0x1f;
411203c4805SLuis R. Rodriguez 
412203c4805SLuis R. Rodriguez 		if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_2) {
413203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(o++, val);
414203c4805SLuis R. Rodriguez 			ee->ee_cck_ofdm_gain_delta = val & 0xff;
415203c4805SLuis R. Rodriguez 		}
416203c4805SLuis R. Rodriguez 		break;
417203c4805SLuis R. Rodriguez 	}
418203c4805SLuis R. Rodriguez 
419203c4805SLuis R. Rodriguez 	/*
420203c4805SLuis R. Rodriguez 	 * Read turbo mode information on newer EEPROM versions
421203c4805SLuis R. Rodriguez 	 */
422203c4805SLuis R. Rodriguez 	if (ee->ee_version < AR5K_EEPROM_VERSION_5_0)
4233b3ee43dSPavel Roskin 		goto done;
424203c4805SLuis R. Rodriguez 
425203c4805SLuis R. Rodriguez 	switch (mode) {
426203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11A:
427203c4805SLuis R. Rodriguez 		ee->ee_switch_settling_turbo[mode] = (val >> 6) & 0x7f;
428203c4805SLuis R. Rodriguez 
429203c4805SLuis R. Rodriguez 		ee->ee_atn_tx_rx_turbo[mode] = (val >> 13) & 0x7;
430203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(o++, val);
431203c4805SLuis R. Rodriguez 		ee->ee_atn_tx_rx_turbo[mode] |= (val & 0x7) << 3;
432203c4805SLuis R. Rodriguez 		ee->ee_margin_tx_rx_turbo[mode] = (val >> 3) & 0x3f;
433203c4805SLuis R. Rodriguez 
434203c4805SLuis R. Rodriguez 		ee->ee_adc_desired_size_turbo[mode] = (val >> 9) & 0x7f;
435203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(o++, val);
436203c4805SLuis R. Rodriguez 		ee->ee_adc_desired_size_turbo[mode] |= (val & 0x1) << 7;
437203c4805SLuis R. Rodriguez 		ee->ee_pga_desired_size_turbo[mode] = (val >> 1) & 0xff;
438203c4805SLuis R. Rodriguez 
439203c4805SLuis R. Rodriguez 		if (AR5K_EEPROM_EEMAP(ee->ee_misc0) >= 2)
440203c4805SLuis R. Rodriguez 			ee->ee_pd_gain_overlap = (val >> 9) & 0xf;
441203c4805SLuis R. Rodriguez 		break;
442203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11G:
443203c4805SLuis R. Rodriguez 		ee->ee_switch_settling_turbo[mode] = (val >> 8) & 0x7f;
444203c4805SLuis R. Rodriguez 
445203c4805SLuis R. Rodriguez 		ee->ee_atn_tx_rx_turbo[mode] = (val >> 15) & 0x7;
446203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(o++, val);
447203c4805SLuis R. Rodriguez 		ee->ee_atn_tx_rx_turbo[mode] |= (val & 0x1f) << 1;
448203c4805SLuis R. Rodriguez 		ee->ee_margin_tx_rx_turbo[mode] = (val >> 5) & 0x3f;
449203c4805SLuis R. Rodriguez 
450203c4805SLuis R. Rodriguez 		ee->ee_adc_desired_size_turbo[mode] = (val >> 11) & 0x7f;
451203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(o++, val);
452203c4805SLuis R. Rodriguez 		ee->ee_adc_desired_size_turbo[mode] |= (val & 0x7) << 5;
453203c4805SLuis R. Rodriguez 		ee->ee_pga_desired_size_turbo[mode] = (val >> 3) & 0xff;
454203c4805SLuis R. Rodriguez 		break;
455203c4805SLuis R. Rodriguez 	}
456203c4805SLuis R. Rodriguez 
4573b3ee43dSPavel Roskin done:
458203c4805SLuis R. Rodriguez 	/* return new offset */
459203c4805SLuis R. Rodriguez 	*offset = o;
460203c4805SLuis R. Rodriguez 
461203c4805SLuis R. Rodriguez 	return 0;
462203c4805SLuis R. Rodriguez }
463203c4805SLuis R. Rodriguez 
464203c4805SLuis R. Rodriguez /* Read mode-specific data (except power calibration data) */
465203c4805SLuis R. Rodriguez static int
466203c4805SLuis R. Rodriguez ath5k_eeprom_init_modes(struct ath5k_hw *ah)
467203c4805SLuis R. Rodriguez {
468203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
469203c4805SLuis R. Rodriguez 	u32 mode_offset[3];
470203c4805SLuis R. Rodriguez 	unsigned int mode;
471203c4805SLuis R. Rodriguez 	u32 offset;
472203c4805SLuis R. Rodriguez 	int ret;
473203c4805SLuis R. Rodriguez 
474203c4805SLuis R. Rodriguez 	/*
475203c4805SLuis R. Rodriguez 	 * Get values for all modes
476203c4805SLuis R. Rodriguez 	 */
477203c4805SLuis R. Rodriguez 	mode_offset[AR5K_EEPROM_MODE_11A] = AR5K_EEPROM_MODES_11A(ah->ah_ee_version);
478203c4805SLuis R. Rodriguez 	mode_offset[AR5K_EEPROM_MODE_11B] = AR5K_EEPROM_MODES_11B(ah->ah_ee_version);
479203c4805SLuis R. Rodriguez 	mode_offset[AR5K_EEPROM_MODE_11G] = AR5K_EEPROM_MODES_11G(ah->ah_ee_version);
480203c4805SLuis R. Rodriguez 
481203c4805SLuis R. Rodriguez 	ee->ee_turbo_max_power[AR5K_EEPROM_MODE_11A] =
482203c4805SLuis R. Rodriguez 		AR5K_EEPROM_HDR_T_5GHZ_DBM(ee->ee_header);
483203c4805SLuis R. Rodriguez 
484203c4805SLuis R. Rodriguez 	for (mode = AR5K_EEPROM_MODE_11A; mode <= AR5K_EEPROM_MODE_11G; mode++) {
485203c4805SLuis R. Rodriguez 		offset = mode_offset[mode];
486203c4805SLuis R. Rodriguez 
487203c4805SLuis R. Rodriguez 		ret = ath5k_eeprom_read_ants(ah, &offset, mode);
488203c4805SLuis R. Rodriguez 		if (ret)
489203c4805SLuis R. Rodriguez 			return ret;
490203c4805SLuis R. Rodriguez 
491203c4805SLuis R. Rodriguez 		ret = ath5k_eeprom_read_modes(ah, &offset, mode);
492203c4805SLuis R. Rodriguez 		if (ret)
493203c4805SLuis R. Rodriguez 			return ret;
494203c4805SLuis R. Rodriguez 	}
495203c4805SLuis R. Rodriguez 
496203c4805SLuis R. Rodriguez 	/* override for older eeprom versions for better performance */
497203c4805SLuis R. Rodriguez 	if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2) {
498203c4805SLuis R. Rodriguez 		ee->ee_thr_62[AR5K_EEPROM_MODE_11A] = 15;
499203c4805SLuis R. Rodriguez 		ee->ee_thr_62[AR5K_EEPROM_MODE_11B] = 28;
500203c4805SLuis R. Rodriguez 		ee->ee_thr_62[AR5K_EEPROM_MODE_11G] = 28;
501203c4805SLuis R. Rodriguez 	}
502203c4805SLuis R. Rodriguez 
503203c4805SLuis R. Rodriguez 	return 0;
504203c4805SLuis R. Rodriguez }
505203c4805SLuis R. Rodriguez 
506203c4805SLuis R. Rodriguez /* Read the frequency piers for each mode (mostly used on newer eeproms with 0xff
507203c4805SLuis R. Rodriguez  * frequency mask) */
508203c4805SLuis R. Rodriguez static inline int
509203c4805SLuis R. Rodriguez ath5k_eeprom_read_freq_list(struct ath5k_hw *ah, int *offset, int max,
510203c4805SLuis R. Rodriguez 			struct ath5k_chan_pcal_info *pc, unsigned int mode)
511203c4805SLuis R. Rodriguez {
512203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
513203c4805SLuis R. Rodriguez 	int o = *offset;
514203c4805SLuis R. Rodriguez 	int i = 0;
515203c4805SLuis R. Rodriguez 	u8 freq1, freq2;
516203c4805SLuis R. Rodriguez 	u16 val;
517203c4805SLuis R. Rodriguez 
518203c4805SLuis R. Rodriguez 	ee->ee_n_piers[mode] = 0;
519203c4805SLuis R. Rodriguez 	while (i < max) {
520203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(o++, val);
521203c4805SLuis R. Rodriguez 
522203c4805SLuis R. Rodriguez 		freq1 = val & 0xff;
523203c4805SLuis R. Rodriguez 		if (!freq1)
524203c4805SLuis R. Rodriguez 			break;
525203c4805SLuis R. Rodriguez 
526203c4805SLuis R. Rodriguez 		pc[i++].freq = ath5k_eeprom_bin2freq(ee,
527203c4805SLuis R. Rodriguez 				freq1, mode);
528203c4805SLuis R. Rodriguez 		ee->ee_n_piers[mode]++;
529203c4805SLuis R. Rodriguez 
530203c4805SLuis R. Rodriguez 		freq2 = (val >> 8) & 0xff;
531203c4805SLuis R. Rodriguez 		if (!freq2)
532203c4805SLuis R. Rodriguez 			break;
533203c4805SLuis R. Rodriguez 
534203c4805SLuis R. Rodriguez 		pc[i++].freq = ath5k_eeprom_bin2freq(ee,
535203c4805SLuis R. Rodriguez 				freq2, mode);
536203c4805SLuis R. Rodriguez 		ee->ee_n_piers[mode]++;
537203c4805SLuis R. Rodriguez 	}
538203c4805SLuis R. Rodriguez 
539203c4805SLuis R. Rodriguez 	/* return new offset */
540203c4805SLuis R. Rodriguez 	*offset = o;
541203c4805SLuis R. Rodriguez 
542203c4805SLuis R. Rodriguez 	return 0;
543203c4805SLuis R. Rodriguez }
544203c4805SLuis R. Rodriguez 
545203c4805SLuis R. Rodriguez /* Read frequency piers for 802.11a */
546203c4805SLuis R. Rodriguez static int
547203c4805SLuis R. Rodriguez ath5k_eeprom_init_11a_pcal_freq(struct ath5k_hw *ah, int offset)
548203c4805SLuis R. Rodriguez {
549203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
550203c4805SLuis R. Rodriguez 	struct ath5k_chan_pcal_info *pcal = ee->ee_pwr_cal_a;
551fda9b7afSWojciech Dubowik 	int i;
552203c4805SLuis R. Rodriguez 	u16 val;
553203c4805SLuis R. Rodriguez 	u8 mask;
554203c4805SLuis R. Rodriguez 
555203c4805SLuis R. Rodriguez 	if (ee->ee_version >= AR5K_EEPROM_VERSION_3_3) {
556203c4805SLuis R. Rodriguez 		ath5k_eeprom_read_freq_list(ah, &offset,
557203c4805SLuis R. Rodriguez 			AR5K_EEPROM_N_5GHZ_CHAN, pcal,
558203c4805SLuis R. Rodriguez 			AR5K_EEPROM_MODE_11A);
559203c4805SLuis R. Rodriguez 	} else {
560203c4805SLuis R. Rodriguez 		mask = AR5K_EEPROM_FREQ_M(ah->ah_ee_version);
561203c4805SLuis R. Rodriguez 
562203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
563203c4805SLuis R. Rodriguez 		pcal[0].freq  = (val >> 9) & mask;
564203c4805SLuis R. Rodriguez 		pcal[1].freq  = (val >> 2) & mask;
565203c4805SLuis R. Rodriguez 		pcal[2].freq  = (val << 5) & mask;
566203c4805SLuis R. Rodriguez 
567203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
568203c4805SLuis R. Rodriguez 		pcal[2].freq |= (val >> 11) & 0x1f;
569203c4805SLuis R. Rodriguez 		pcal[3].freq  = (val >> 4) & mask;
570203c4805SLuis R. Rodriguez 		pcal[4].freq  = (val << 3) & mask;
571203c4805SLuis R. Rodriguez 
572203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
573203c4805SLuis R. Rodriguez 		pcal[4].freq |= (val >> 13) & 0x7;
574203c4805SLuis R. Rodriguez 		pcal[5].freq  = (val >> 6) & mask;
575203c4805SLuis R. Rodriguez 		pcal[6].freq  = (val << 1) & mask;
576203c4805SLuis R. Rodriguez 
577203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
578203c4805SLuis R. Rodriguez 		pcal[6].freq |= (val >> 15) & 0x1;
579203c4805SLuis R. Rodriguez 		pcal[7].freq  = (val >> 8) & mask;
580203c4805SLuis R. Rodriguez 		pcal[8].freq  = (val >> 1) & mask;
581203c4805SLuis R. Rodriguez 		pcal[9].freq  = (val << 6) & mask;
582203c4805SLuis R. Rodriguez 
583203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
584203c4805SLuis R. Rodriguez 		pcal[9].freq |= (val >> 10) & 0x3f;
585203c4805SLuis R. Rodriguez 
586203c4805SLuis R. Rodriguez 		/* Fixed number of piers */
587203c4805SLuis R. Rodriguez 		ee->ee_n_piers[AR5K_EEPROM_MODE_11A] = 10;
588203c4805SLuis R. Rodriguez 
589203c4805SLuis R. Rodriguez 		for (i = 0; i < AR5K_EEPROM_N_5GHZ_CHAN; i++) {
590203c4805SLuis R. Rodriguez 			pcal[i].freq = ath5k_eeprom_bin2freq(ee,
591203c4805SLuis R. Rodriguez 				pcal[i].freq, AR5K_EEPROM_MODE_11A);
592203c4805SLuis R. Rodriguez 		}
593203c4805SLuis R. Rodriguez 	}
594203c4805SLuis R. Rodriguez 
595203c4805SLuis R. Rodriguez 	return 0;
596203c4805SLuis R. Rodriguez }
597203c4805SLuis R. Rodriguez 
598203c4805SLuis R. Rodriguez /* Read frequency piers for 802.11bg on eeprom versions >= 5 and eemap >= 2 */
599203c4805SLuis R. Rodriguez static inline int
600203c4805SLuis R. Rodriguez ath5k_eeprom_init_11bg_2413(struct ath5k_hw *ah, unsigned int mode, int offset)
601203c4805SLuis R. Rodriguez {
602203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
603203c4805SLuis R. Rodriguez 	struct ath5k_chan_pcal_info *pcal;
604203c4805SLuis R. Rodriguez 
605203c4805SLuis R. Rodriguez 	switch (mode) {
606203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11B:
607203c4805SLuis R. Rodriguez 		pcal = ee->ee_pwr_cal_b;
608203c4805SLuis R. Rodriguez 		break;
609203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11G:
610203c4805SLuis R. Rodriguez 		pcal = ee->ee_pwr_cal_g;
611203c4805SLuis R. Rodriguez 		break;
612203c4805SLuis R. Rodriguez 	default:
613203c4805SLuis R. Rodriguez 		return -EINVAL;
614203c4805SLuis R. Rodriguez 	}
615203c4805SLuis R. Rodriguez 
616203c4805SLuis R. Rodriguez 	ath5k_eeprom_read_freq_list(ah, &offset,
617203c4805SLuis R. Rodriguez 		AR5K_EEPROM_N_2GHZ_CHAN_2413, pcal,
618203c4805SLuis R. Rodriguez 		mode);
619203c4805SLuis R. Rodriguez 
620203c4805SLuis R. Rodriguez 	return 0;
621203c4805SLuis R. Rodriguez }
622203c4805SLuis R. Rodriguez 
6239320b5c4SNick Kossifidis 
624203c4805SLuis R. Rodriguez /*
625203c4805SLuis R. Rodriguez  * Read power calibration for RF5111 chips
626203c4805SLuis R. Rodriguez  *
627203c4805SLuis R. Rodriguez  * For RF5111 we have an XPD -eXternal Power Detector- curve
628203c4805SLuis R. Rodriguez  * for each calibrated channel. Each curve has 0,5dB Power steps
629203c4805SLuis R. Rodriguez  * on x axis and PCDAC steps (offsets) on y axis and looks like an
630203c4805SLuis R. Rodriguez  * exponential function. To recreate the curve we read 11 points
631203c4805SLuis R. Rodriguez  * here and interpolate later.
632203c4805SLuis R. Rodriguez  */
633203c4805SLuis R. Rodriguez 
634203c4805SLuis R. Rodriguez /* Used to match PCDAC steps with power values on RF5111 chips
635203c4805SLuis R. Rodriguez  * (eeprom versions < 4). For RF5111 we have 11 pre-defined PCDAC
636203c4805SLuis R. Rodriguez  * steps that match with the power values we read from eeprom. On
637*6a2a0e73SPavel Roskin  * older eeprom versions (< 3.2) these steps are equally spaced at
638a180a130SBob Copeland  * 10% of the pcdac curve -until the curve reaches its maximum-
639203c4805SLuis R. Rodriguez  * (11 steps from 0 to 100%) but on newer eeprom versions (>= 3.2)
640203c4805SLuis R. Rodriguez  * these 11 steps are spaced in a different way. This function returns
641203c4805SLuis R. Rodriguez  * the pcdac steps based on eeprom version and curve min/max so that we
642203c4805SLuis R. Rodriguez  * can have pcdac/pwr points.
643203c4805SLuis R. Rodriguez  */
644203c4805SLuis R. Rodriguez static inline void
645203c4805SLuis R. Rodriguez ath5k_get_pcdac_intercepts(struct ath5k_hw *ah, u8 min, u8 max, u8 *vp)
646203c4805SLuis R. Rodriguez {
647d2c7f773SPavel Roskin 	static const u16 intercepts3[] = {
648d2c7f773SPavel Roskin 		0, 5, 10, 20, 30, 50, 70, 85, 90, 95, 100
649d2c7f773SPavel Roskin 	};
650d2c7f773SPavel Roskin 	static const u16 intercepts3_2[] = {
651d2c7f773SPavel Roskin 		0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
652d2c7f773SPavel Roskin 	};
653203c4805SLuis R. Rodriguez 	const u16 *ip;
654203c4805SLuis R. Rodriguez 	int i;
655203c4805SLuis R. Rodriguez 
656203c4805SLuis R. Rodriguez 	if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_2)
657203c4805SLuis R. Rodriguez 		ip = intercepts3_2;
658203c4805SLuis R. Rodriguez 	else
659203c4805SLuis R. Rodriguez 		ip = intercepts3;
660203c4805SLuis R. Rodriguez 
661203c4805SLuis R. Rodriguez 	for (i = 0; i < ARRAY_SIZE(intercepts3); i++)
662203c4805SLuis R. Rodriguez 		vp[i] = (ip[i] * max + (100 - ip[i]) * min) / 100;
663203c4805SLuis R. Rodriguez }
664203c4805SLuis R. Rodriguez 
665a0657846SJohn W. Linville static int
666a0657846SJohn W. Linville ath5k_eeprom_free_pcal_info(struct ath5k_hw *ah, int mode)
667a0657846SJohn W. Linville {
668a0657846SJohn W. Linville 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
669a0657846SJohn W. Linville 	struct ath5k_chan_pcal_info *chinfo;
670a0657846SJohn W. Linville 	u8 pier, pdg;
671a0657846SJohn W. Linville 
672a0657846SJohn W. Linville 	switch (mode) {
673a0657846SJohn W. Linville 	case AR5K_EEPROM_MODE_11A:
674a0657846SJohn W. Linville 		if (!AR5K_EEPROM_HDR_11A(ee->ee_header))
675a0657846SJohn W. Linville 			return 0;
676a0657846SJohn W. Linville 		chinfo = ee->ee_pwr_cal_a;
677a0657846SJohn W. Linville 		break;
678a0657846SJohn W. Linville 	case AR5K_EEPROM_MODE_11B:
679a0657846SJohn W. Linville 		if (!AR5K_EEPROM_HDR_11B(ee->ee_header))
680a0657846SJohn W. Linville 			return 0;
681a0657846SJohn W. Linville 		chinfo = ee->ee_pwr_cal_b;
682a0657846SJohn W. Linville 		break;
683a0657846SJohn W. Linville 	case AR5K_EEPROM_MODE_11G:
684a0657846SJohn W. Linville 		if (!AR5K_EEPROM_HDR_11G(ee->ee_header))
685a0657846SJohn W. Linville 			return 0;
686a0657846SJohn W. Linville 		chinfo = ee->ee_pwr_cal_g;
687a0657846SJohn W. Linville 		break;
688a0657846SJohn W. Linville 	default:
689a0657846SJohn W. Linville 		return -EINVAL;
690a0657846SJohn W. Linville 	}
691a0657846SJohn W. Linville 
692a0657846SJohn W. Linville 	for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
693a0657846SJohn W. Linville 		if (!chinfo[pier].pd_curves)
694a0657846SJohn W. Linville 			continue;
695a0657846SJohn W. Linville 
696a0b8de35SEugene A. Shatokhin 		for (pdg = 0; pdg < AR5K_EEPROM_N_PD_CURVES; pdg++) {
697a0657846SJohn W. Linville 			struct ath5k_pdgain_info *pd =
698a0657846SJohn W. Linville 					&chinfo[pier].pd_curves[pdg];
699a0657846SJohn W. Linville 
700a0657846SJohn W. Linville 			kfree(pd->pd_step);
701a0657846SJohn W. Linville 			kfree(pd->pd_pwr);
702a0657846SJohn W. Linville 		}
703a0657846SJohn W. Linville 
704a0657846SJohn W. Linville 		kfree(chinfo[pier].pd_curves);
705a0657846SJohn W. Linville 	}
706a0657846SJohn W. Linville 
707a0657846SJohn W. Linville 	return 0;
708a0657846SJohn W. Linville }
709a0657846SJohn W. Linville 
710203c4805SLuis R. Rodriguez /* Convert RF5111 specific data to generic raw data
711203c4805SLuis R. Rodriguez  * used by interpolation code */
712203c4805SLuis R. Rodriguez static int
713203c4805SLuis R. Rodriguez ath5k_eeprom_convert_pcal_info_5111(struct ath5k_hw *ah, int mode,
714203c4805SLuis R. Rodriguez 				struct ath5k_chan_pcal_info *chinfo)
715203c4805SLuis R. Rodriguez {
716203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
717203c4805SLuis R. Rodriguez 	struct ath5k_chan_pcal_info_rf5111 *pcinfo;
718203c4805SLuis R. Rodriguez 	struct ath5k_pdgain_info *pd;
719203c4805SLuis R. Rodriguez 	u8 pier, point, idx;
720203c4805SLuis R. Rodriguez 	u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
721203c4805SLuis R. Rodriguez 
722203c4805SLuis R. Rodriguez 	/* Fill raw data for each calibration pier */
723203c4805SLuis R. Rodriguez 	for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
724203c4805SLuis R. Rodriguez 
725203c4805SLuis R. Rodriguez 		pcinfo = &chinfo[pier].rf5111_info;
726203c4805SLuis R. Rodriguez 
727203c4805SLuis R. Rodriguez 		/* Allocate pd_curves for this cal pier */
728203c4805SLuis R. Rodriguez 		chinfo[pier].pd_curves =
729203c4805SLuis R. Rodriguez 			kcalloc(AR5K_EEPROM_N_PD_CURVES,
730203c4805SLuis R. Rodriguez 				sizeof(struct ath5k_pdgain_info),
731203c4805SLuis R. Rodriguez 				GFP_KERNEL);
732203c4805SLuis R. Rodriguez 
733203c4805SLuis R. Rodriguez 		if (!chinfo[pier].pd_curves)
734a0657846SJohn W. Linville 			goto err_out;
735203c4805SLuis R. Rodriguez 
736203c4805SLuis R. Rodriguez 		/* Only one curve for RF5111
737203c4805SLuis R. Rodriguez 		 * find out which one and place
73877c2061dSWalter Goldens 		 * in pd_curves.
739203c4805SLuis R. Rodriguez 		 * Note: ee_x_gain is reversed here */
740203c4805SLuis R. Rodriguez 		for (idx = 0; idx < AR5K_EEPROM_N_PD_CURVES; idx++) {
741203c4805SLuis R. Rodriguez 
742203c4805SLuis R. Rodriguez 			if (!((ee->ee_x_gain[mode] >> idx) & 0x1)) {
743203c4805SLuis R. Rodriguez 				pdgain_idx[0] = idx;
744203c4805SLuis R. Rodriguez 				break;
745203c4805SLuis R. Rodriguez 			}
746203c4805SLuis R. Rodriguez 		}
747203c4805SLuis R. Rodriguez 
748203c4805SLuis R. Rodriguez 		ee->ee_pd_gains[mode] = 1;
749203c4805SLuis R. Rodriguez 
750203c4805SLuis R. Rodriguez 		pd = &chinfo[pier].pd_curves[idx];
751203c4805SLuis R. Rodriguez 
752203c4805SLuis R. Rodriguez 		pd->pd_points = AR5K_EEPROM_N_PWR_POINTS_5111;
753203c4805SLuis R. Rodriguez 
754203c4805SLuis R. Rodriguez 		/* Allocate pd points for this curve */
755203c4805SLuis R. Rodriguez 		pd->pd_step = kcalloc(AR5K_EEPROM_N_PWR_POINTS_5111,
756203c4805SLuis R. Rodriguez 					sizeof(u8), GFP_KERNEL);
757203c4805SLuis R. Rodriguez 		if (!pd->pd_step)
758a0657846SJohn W. Linville 			goto err_out;
759203c4805SLuis R. Rodriguez 
760203c4805SLuis R. Rodriguez 		pd->pd_pwr = kcalloc(AR5K_EEPROM_N_PWR_POINTS_5111,
761203c4805SLuis R. Rodriguez 					sizeof(s16), GFP_KERNEL);
762203c4805SLuis R. Rodriguez 		if (!pd->pd_pwr)
763a0657846SJohn W. Linville 			goto err_out;
764203c4805SLuis R. Rodriguez 
765203c4805SLuis R. Rodriguez 		/* Fill raw dataset
766203c4805SLuis R. Rodriguez 		 * (convert power to 0.25dB units
767*6a2a0e73SPavel Roskin 		 * for RF5112 compatibility) */
768203c4805SLuis R. Rodriguez 		for (point = 0; point < pd->pd_points; point++) {
769203c4805SLuis R. Rodriguez 
770203c4805SLuis R. Rodriguez 			/* Absolute values */
771203c4805SLuis R. Rodriguez 			pd->pd_pwr[point] = 2 * pcinfo->pwr[point];
772203c4805SLuis R. Rodriguez 
773203c4805SLuis R. Rodriguez 			/* Already sorted */
774203c4805SLuis R. Rodriguez 			pd->pd_step[point] = pcinfo->pcdac[point];
775203c4805SLuis R. Rodriguez 		}
776203c4805SLuis R. Rodriguez 
777203c4805SLuis R. Rodriguez 		/* Set min/max pwr */
778203c4805SLuis R. Rodriguez 		chinfo[pier].min_pwr = pd->pd_pwr[0];
779203c4805SLuis R. Rodriguez 		chinfo[pier].max_pwr = pd->pd_pwr[10];
780203c4805SLuis R. Rodriguez 
781203c4805SLuis R. Rodriguez 	}
782203c4805SLuis R. Rodriguez 
783203c4805SLuis R. Rodriguez 	return 0;
784a0657846SJohn W. Linville 
785a0657846SJohn W. Linville err_out:
786a0657846SJohn W. Linville 	ath5k_eeprom_free_pcal_info(ah, mode);
787a0657846SJohn W. Linville 	return -ENOMEM;
788203c4805SLuis R. Rodriguez }
789203c4805SLuis R. Rodriguez 
790203c4805SLuis R. Rodriguez /* Parse EEPROM data */
791203c4805SLuis R. Rodriguez static int
792203c4805SLuis R. Rodriguez ath5k_eeprom_read_pcal_info_5111(struct ath5k_hw *ah, int mode)
793203c4805SLuis R. Rodriguez {
794203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
795203c4805SLuis R. Rodriguez 	struct ath5k_chan_pcal_info *pcal;
796203c4805SLuis R. Rodriguez 	int offset, ret;
797203c4805SLuis R. Rodriguez 	int i;
798203c4805SLuis R. Rodriguez 	u16 val;
799203c4805SLuis R. Rodriguez 
800203c4805SLuis R. Rodriguez 	offset = AR5K_EEPROM_GROUPS_START(ee->ee_version);
801203c4805SLuis R. Rodriguez 	switch (mode) {
802203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11A:
803203c4805SLuis R. Rodriguez 		if (!AR5K_EEPROM_HDR_11A(ee->ee_header))
804203c4805SLuis R. Rodriguez 			return 0;
805203c4805SLuis R. Rodriguez 
806203c4805SLuis R. Rodriguez 		ret = ath5k_eeprom_init_11a_pcal_freq(ah,
807203c4805SLuis R. Rodriguez 			offset + AR5K_EEPROM_GROUP1_OFFSET);
808203c4805SLuis R. Rodriguez 		if (ret < 0)
809203c4805SLuis R. Rodriguez 			return ret;
810203c4805SLuis R. Rodriguez 
811203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_GROUP2_OFFSET;
812203c4805SLuis R. Rodriguez 		pcal = ee->ee_pwr_cal_a;
813203c4805SLuis R. Rodriguez 		break;
814203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11B:
815203c4805SLuis R. Rodriguez 		if (!AR5K_EEPROM_HDR_11B(ee->ee_header) &&
816203c4805SLuis R. Rodriguez 		    !AR5K_EEPROM_HDR_11G(ee->ee_header))
817203c4805SLuis R. Rodriguez 			return 0;
818203c4805SLuis R. Rodriguez 
819203c4805SLuis R. Rodriguez 		pcal = ee->ee_pwr_cal_b;
820203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_GROUP3_OFFSET;
821203c4805SLuis R. Rodriguez 
822203c4805SLuis R. Rodriguez 		/* fixed piers */
823203c4805SLuis R. Rodriguez 		pcal[0].freq = 2412;
824203c4805SLuis R. Rodriguez 		pcal[1].freq = 2447;
825203c4805SLuis R. Rodriguez 		pcal[2].freq = 2484;
826203c4805SLuis R. Rodriguez 		ee->ee_n_piers[mode] = 3;
827203c4805SLuis R. Rodriguez 		break;
828203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11G:
829203c4805SLuis R. Rodriguez 		if (!AR5K_EEPROM_HDR_11G(ee->ee_header))
830203c4805SLuis R. Rodriguez 			return 0;
831203c4805SLuis R. Rodriguez 
832203c4805SLuis R. Rodriguez 		pcal = ee->ee_pwr_cal_g;
833203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_GROUP4_OFFSET;
834203c4805SLuis R. Rodriguez 
835203c4805SLuis R. Rodriguez 		/* fixed piers */
836203c4805SLuis R. Rodriguez 		pcal[0].freq = 2312;
837203c4805SLuis R. Rodriguez 		pcal[1].freq = 2412;
838203c4805SLuis R. Rodriguez 		pcal[2].freq = 2484;
839203c4805SLuis R. Rodriguez 		ee->ee_n_piers[mode] = 3;
840203c4805SLuis R. Rodriguez 		break;
841203c4805SLuis R. Rodriguez 	default:
842203c4805SLuis R. Rodriguez 		return -EINVAL;
843203c4805SLuis R. Rodriguez 	}
844203c4805SLuis R. Rodriguez 
845203c4805SLuis R. Rodriguez 	for (i = 0; i < ee->ee_n_piers[mode]; i++) {
846203c4805SLuis R. Rodriguez 		struct ath5k_chan_pcal_info_rf5111 *cdata =
847203c4805SLuis R. Rodriguez 			&pcal[i].rf5111_info;
848203c4805SLuis R. Rodriguez 
849203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
850203c4805SLuis R. Rodriguez 		cdata->pcdac_max = ((val >> 10) & AR5K_EEPROM_PCDAC_M);
851203c4805SLuis R. Rodriguez 		cdata->pcdac_min = ((val >> 4) & AR5K_EEPROM_PCDAC_M);
852203c4805SLuis R. Rodriguez 		cdata->pwr[0] = ((val << 2) & AR5K_EEPROM_POWER_M);
853203c4805SLuis R. Rodriguez 
854203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
855203c4805SLuis R. Rodriguez 		cdata->pwr[0] |= ((val >> 14) & 0x3);
856203c4805SLuis R. Rodriguez 		cdata->pwr[1] = ((val >> 8) & AR5K_EEPROM_POWER_M);
857203c4805SLuis R. Rodriguez 		cdata->pwr[2] = ((val >> 2) & AR5K_EEPROM_POWER_M);
858203c4805SLuis R. Rodriguez 		cdata->pwr[3] = ((val << 4) & AR5K_EEPROM_POWER_M);
859203c4805SLuis R. Rodriguez 
860203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
861203c4805SLuis R. Rodriguez 		cdata->pwr[3] |= ((val >> 12) & 0xf);
862203c4805SLuis R. Rodriguez 		cdata->pwr[4] = ((val >> 6) & AR5K_EEPROM_POWER_M);
863203c4805SLuis R. Rodriguez 		cdata->pwr[5] = (val  & AR5K_EEPROM_POWER_M);
864203c4805SLuis R. Rodriguez 
865203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
866203c4805SLuis R. Rodriguez 		cdata->pwr[6] = ((val >> 10) & AR5K_EEPROM_POWER_M);
867203c4805SLuis R. Rodriguez 		cdata->pwr[7] = ((val >> 4) & AR5K_EEPROM_POWER_M);
868203c4805SLuis R. Rodriguez 		cdata->pwr[8] = ((val << 2) & AR5K_EEPROM_POWER_M);
869203c4805SLuis R. Rodriguez 
870203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
871203c4805SLuis R. Rodriguez 		cdata->pwr[8] |= ((val >> 14) & 0x3);
872203c4805SLuis R. Rodriguez 		cdata->pwr[9] = ((val >> 8) & AR5K_EEPROM_POWER_M);
873203c4805SLuis R. Rodriguez 		cdata->pwr[10] = ((val >> 2) & AR5K_EEPROM_POWER_M);
874203c4805SLuis R. Rodriguez 
875203c4805SLuis R. Rodriguez 		ath5k_get_pcdac_intercepts(ah, cdata->pcdac_min,
876203c4805SLuis R. Rodriguez 			cdata->pcdac_max, cdata->pcdac);
877203c4805SLuis R. Rodriguez 	}
878203c4805SLuis R. Rodriguez 
879203c4805SLuis R. Rodriguez 	return ath5k_eeprom_convert_pcal_info_5111(ah, mode, pcal);
880203c4805SLuis R. Rodriguez }
881203c4805SLuis R. Rodriguez 
882203c4805SLuis R. Rodriguez 
883203c4805SLuis R. Rodriguez /*
884203c4805SLuis R. Rodriguez  * Read power calibration for RF5112 chips
885203c4805SLuis R. Rodriguez  *
886203c4805SLuis R. Rodriguez  * For RF5112 we have 4 XPD -eXternal Power Detector- curves
887*6a2a0e73SPavel Roskin  * for each calibrated channel on 0, -6, -12 and -18dBm but we only
888203c4805SLuis R. Rodriguez  * use the higher (3) and the lower (0) curves. Each curve has 0.5dB
889203c4805SLuis R. Rodriguez  * power steps on x axis and PCDAC steps on y axis and looks like a
890203c4805SLuis R. Rodriguez  * linear function. To recreate the curve and pass the power values
891203c4805SLuis R. Rodriguez  * on hw, we read 4 points for xpd 0 (lower gain -> max power)
892203c4805SLuis R. Rodriguez  * and 3 points for xpd 3 (higher gain -> lower power) here and
893203c4805SLuis R. Rodriguez  * interpolate later.
894203c4805SLuis R. Rodriguez  *
895203c4805SLuis R. Rodriguez  * Note: Many vendors just use xpd 0 so xpd 3 is zeroed.
896203c4805SLuis R. Rodriguez  */
897203c4805SLuis R. Rodriguez 
898203c4805SLuis R. Rodriguez /* Convert RF5112 specific data to generic raw data
899203c4805SLuis R. Rodriguez  * used by interpolation code */
900203c4805SLuis R. Rodriguez static int
901203c4805SLuis R. Rodriguez ath5k_eeprom_convert_pcal_info_5112(struct ath5k_hw *ah, int mode,
902203c4805SLuis R. Rodriguez 				struct ath5k_chan_pcal_info *chinfo)
903203c4805SLuis R. Rodriguez {
904203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
905203c4805SLuis R. Rodriguez 	struct ath5k_chan_pcal_info_rf5112 *pcinfo;
906203c4805SLuis R. Rodriguez 	u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
907203c4805SLuis R. Rodriguez 	unsigned int pier, pdg, point;
908203c4805SLuis R. Rodriguez 
909203c4805SLuis R. Rodriguez 	/* Fill raw data for each calibration pier */
910203c4805SLuis R. Rodriguez 	for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
911203c4805SLuis R. Rodriguez 
912203c4805SLuis R. Rodriguez 		pcinfo = &chinfo[pier].rf5112_info;
913203c4805SLuis R. Rodriguez 
914203c4805SLuis R. Rodriguez 		/* Allocate pd_curves for this cal pier */
915203c4805SLuis R. Rodriguez 		chinfo[pier].pd_curves =
916203c4805SLuis R. Rodriguez 				kcalloc(AR5K_EEPROM_N_PD_CURVES,
917203c4805SLuis R. Rodriguez 					sizeof(struct ath5k_pdgain_info),
918203c4805SLuis R. Rodriguez 					GFP_KERNEL);
919203c4805SLuis R. Rodriguez 
920203c4805SLuis R. Rodriguez 		if (!chinfo[pier].pd_curves)
921a0657846SJohn W. Linville 			goto err_out;
922203c4805SLuis R. Rodriguez 
923203c4805SLuis R. Rodriguez 		/* Fill pd_curves */
924203c4805SLuis R. Rodriguez 		for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) {
925203c4805SLuis R. Rodriguez 
926203c4805SLuis R. Rodriguez 			u8 idx = pdgain_idx[pdg];
927203c4805SLuis R. Rodriguez 			struct ath5k_pdgain_info *pd =
928203c4805SLuis R. Rodriguez 					&chinfo[pier].pd_curves[idx];
929203c4805SLuis R. Rodriguez 
930203c4805SLuis R. Rodriguez 			/* Lowest gain curve (max power) */
931203c4805SLuis R. Rodriguez 			if (pdg == 0) {
932203c4805SLuis R. Rodriguez 				/* One more point for better accuracy */
933203c4805SLuis R. Rodriguez 				pd->pd_points = AR5K_EEPROM_N_XPD0_POINTS;
934203c4805SLuis R. Rodriguez 
935203c4805SLuis R. Rodriguez 				/* Allocate pd points for this curve */
936203c4805SLuis R. Rodriguez 				pd->pd_step = kcalloc(pd->pd_points,
937203c4805SLuis R. Rodriguez 						sizeof(u8), GFP_KERNEL);
938203c4805SLuis R. Rodriguez 
939203c4805SLuis R. Rodriguez 				if (!pd->pd_step)
940a0657846SJohn W. Linville 					goto err_out;
941203c4805SLuis R. Rodriguez 
942203c4805SLuis R. Rodriguez 				pd->pd_pwr = kcalloc(pd->pd_points,
943203c4805SLuis R. Rodriguez 						sizeof(s16), GFP_KERNEL);
944203c4805SLuis R. Rodriguez 
945203c4805SLuis R. Rodriguez 				if (!pd->pd_pwr)
946a0657846SJohn W. Linville 					goto err_out;
947203c4805SLuis R. Rodriguez 
948203c4805SLuis R. Rodriguez 				/* Fill raw dataset
949203c4805SLuis R. Rodriguez 				 * (all power levels are in 0.25dB units) */
950203c4805SLuis R. Rodriguez 				pd->pd_step[0] = pcinfo->pcdac_x0[0];
951203c4805SLuis R. Rodriguez 				pd->pd_pwr[0] = pcinfo->pwr_x0[0];
952203c4805SLuis R. Rodriguez 
953203c4805SLuis R. Rodriguez 				for (point = 1; point < pd->pd_points;
954203c4805SLuis R. Rodriguez 				point++) {
955203c4805SLuis R. Rodriguez 					/* Absolute values */
956203c4805SLuis R. Rodriguez 					pd->pd_pwr[point] =
957203c4805SLuis R. Rodriguez 						pcinfo->pwr_x0[point];
958203c4805SLuis R. Rodriguez 
959203c4805SLuis R. Rodriguez 					/* Deltas */
960203c4805SLuis R. Rodriguez 					pd->pd_step[point] =
961203c4805SLuis R. Rodriguez 						pd->pd_step[point - 1] +
962203c4805SLuis R. Rodriguez 						pcinfo->pcdac_x0[point];
963203c4805SLuis R. Rodriguez 				}
964203c4805SLuis R. Rodriguez 
965203c4805SLuis R. Rodriguez 				/* Set min power for this frequency */
966203c4805SLuis R. Rodriguez 				chinfo[pier].min_pwr = pd->pd_pwr[0];
967203c4805SLuis R. Rodriguez 
968203c4805SLuis R. Rodriguez 			/* Highest gain curve (min power) */
969203c4805SLuis R. Rodriguez 			} else if (pdg == 1) {
970203c4805SLuis R. Rodriguez 
971203c4805SLuis R. Rodriguez 				pd->pd_points = AR5K_EEPROM_N_XPD3_POINTS;
972203c4805SLuis R. Rodriguez 
973203c4805SLuis R. Rodriguez 				/* Allocate pd points for this curve */
974203c4805SLuis R. Rodriguez 				pd->pd_step = kcalloc(pd->pd_points,
975203c4805SLuis R. Rodriguez 						sizeof(u8), GFP_KERNEL);
976203c4805SLuis R. Rodriguez 
977203c4805SLuis R. Rodriguez 				if (!pd->pd_step)
978a0657846SJohn W. Linville 					goto err_out;
979203c4805SLuis R. Rodriguez 
980203c4805SLuis R. Rodriguez 				pd->pd_pwr = kcalloc(pd->pd_points,
981203c4805SLuis R. Rodriguez 						sizeof(s16), GFP_KERNEL);
982203c4805SLuis R. Rodriguez 
983203c4805SLuis R. Rodriguez 				if (!pd->pd_pwr)
984a0657846SJohn W. Linville 					goto err_out;
985203c4805SLuis R. Rodriguez 
986203c4805SLuis R. Rodriguez 				/* Fill raw dataset
987203c4805SLuis R. Rodriguez 				 * (all power levels are in 0.25dB units) */
988203c4805SLuis R. Rodriguez 				for (point = 0; point < pd->pd_points;
989203c4805SLuis R. Rodriguez 				point++) {
990203c4805SLuis R. Rodriguez 					/* Absolute values */
991203c4805SLuis R. Rodriguez 					pd->pd_pwr[point] =
992203c4805SLuis R. Rodriguez 						pcinfo->pwr_x3[point];
993203c4805SLuis R. Rodriguez 
994203c4805SLuis R. Rodriguez 					/* Fixed points */
995203c4805SLuis R. Rodriguez 					pd->pd_step[point] =
996203c4805SLuis R. Rodriguez 						pcinfo->pcdac_x3[point];
997203c4805SLuis R. Rodriguez 				}
998203c4805SLuis R. Rodriguez 
999203c4805SLuis R. Rodriguez 				/* Since we have a higher gain curve
1000203c4805SLuis R. Rodriguez 				 * override min power */
1001203c4805SLuis R. Rodriguez 				chinfo[pier].min_pwr = pd->pd_pwr[0];
1002203c4805SLuis R. Rodriguez 			}
1003203c4805SLuis R. Rodriguez 		}
1004203c4805SLuis R. Rodriguez 	}
1005203c4805SLuis R. Rodriguez 
1006203c4805SLuis R. Rodriguez 	return 0;
1007a0657846SJohn W. Linville 
1008a0657846SJohn W. Linville err_out:
1009a0657846SJohn W. Linville 	ath5k_eeprom_free_pcal_info(ah, mode);
1010a0657846SJohn W. Linville 	return -ENOMEM;
1011203c4805SLuis R. Rodriguez }
1012203c4805SLuis R. Rodriguez 
1013203c4805SLuis R. Rodriguez /* Parse EEPROM data */
1014203c4805SLuis R. Rodriguez static int
1015203c4805SLuis R. Rodriguez ath5k_eeprom_read_pcal_info_5112(struct ath5k_hw *ah, int mode)
1016203c4805SLuis R. Rodriguez {
1017203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1018203c4805SLuis R. Rodriguez 	struct ath5k_chan_pcal_info_rf5112 *chan_pcal_info;
1019203c4805SLuis R. Rodriguez 	struct ath5k_chan_pcal_info *gen_chan_info;
1020203c4805SLuis R. Rodriguez 	u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
1021203c4805SLuis R. Rodriguez 	u32 offset;
1022203c4805SLuis R. Rodriguez 	u8 i, c;
1023203c4805SLuis R. Rodriguez 	u16 val;
1024203c4805SLuis R. Rodriguez 	u8 pd_gains = 0;
1025203c4805SLuis R. Rodriguez 
1026203c4805SLuis R. Rodriguez 	/* Count how many curves we have and
1027203c4805SLuis R. Rodriguez 	 * identify them (which one of the 4
1028203c4805SLuis R. Rodriguez 	 * available curves we have on each count).
1029203c4805SLuis R. Rodriguez 	 * Curves are stored from lower (x0) to
1030203c4805SLuis R. Rodriguez 	 * higher (x3) gain */
1031203c4805SLuis R. Rodriguez 	for (i = 0; i < AR5K_EEPROM_N_PD_CURVES; i++) {
1032203c4805SLuis R. Rodriguez 		/* ee_x_gain[mode] is x gain mask */
1033203c4805SLuis R. Rodriguez 		if ((ee->ee_x_gain[mode] >> i) & 0x1)
1034203c4805SLuis R. Rodriguez 			pdgain_idx[pd_gains++] = i;
1035203c4805SLuis R. Rodriguez 	}
1036203c4805SLuis R. Rodriguez 	ee->ee_pd_gains[mode] = pd_gains;
1037203c4805SLuis R. Rodriguez 
1038203c4805SLuis R. Rodriguez 	if (pd_gains == 0 || pd_gains > 2)
1039203c4805SLuis R. Rodriguez 		return -EINVAL;
1040203c4805SLuis R. Rodriguez 
1041203c4805SLuis R. Rodriguez 	switch (mode) {
1042203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11A:
1043203c4805SLuis R. Rodriguez 		/*
1044203c4805SLuis R. Rodriguez 		 * Read 5GHz EEPROM channels
1045203c4805SLuis R. Rodriguez 		 */
1046203c4805SLuis R. Rodriguez 		offset = AR5K_EEPROM_GROUPS_START(ee->ee_version);
1047203c4805SLuis R. Rodriguez 		ath5k_eeprom_init_11a_pcal_freq(ah, offset);
1048203c4805SLuis R. Rodriguez 
1049203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_GROUP2_OFFSET;
1050203c4805SLuis R. Rodriguez 		gen_chan_info = ee->ee_pwr_cal_a;
1051203c4805SLuis R. Rodriguez 		break;
1052203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11B:
1053203c4805SLuis R. Rodriguez 		offset = AR5K_EEPROM_GROUPS_START(ee->ee_version);
1054203c4805SLuis R. Rodriguez 		if (AR5K_EEPROM_HDR_11A(ee->ee_header))
1055203c4805SLuis R. Rodriguez 			offset += AR5K_EEPROM_GROUP3_OFFSET;
1056203c4805SLuis R. Rodriguez 
1057203c4805SLuis R. Rodriguez 		/* NB: frequency piers parsed during mode init */
1058203c4805SLuis R. Rodriguez 		gen_chan_info = ee->ee_pwr_cal_b;
1059203c4805SLuis R. Rodriguez 		break;
1060203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11G:
1061203c4805SLuis R. Rodriguez 		offset = AR5K_EEPROM_GROUPS_START(ee->ee_version);
1062203c4805SLuis R. Rodriguez 		if (AR5K_EEPROM_HDR_11A(ee->ee_header))
1063203c4805SLuis R. Rodriguez 			offset += AR5K_EEPROM_GROUP4_OFFSET;
1064203c4805SLuis R. Rodriguez 		else if (AR5K_EEPROM_HDR_11B(ee->ee_header))
1065203c4805SLuis R. Rodriguez 			offset += AR5K_EEPROM_GROUP2_OFFSET;
1066203c4805SLuis R. Rodriguez 
1067203c4805SLuis R. Rodriguez 		/* NB: frequency piers parsed during mode init */
1068203c4805SLuis R. Rodriguez 		gen_chan_info = ee->ee_pwr_cal_g;
1069203c4805SLuis R. Rodriguez 		break;
1070203c4805SLuis R. Rodriguez 	default:
1071203c4805SLuis R. Rodriguez 		return -EINVAL;
1072203c4805SLuis R. Rodriguez 	}
1073203c4805SLuis R. Rodriguez 
1074203c4805SLuis R. Rodriguez 	for (i = 0; i < ee->ee_n_piers[mode]; i++) {
1075203c4805SLuis R. Rodriguez 		chan_pcal_info = &gen_chan_info[i].rf5112_info;
1076203c4805SLuis R. Rodriguez 
1077203c4805SLuis R. Rodriguez 		/* Power values in quarter dB
1078203c4805SLuis R. Rodriguez 		 * for the lower xpd gain curve
1079203c4805SLuis R. Rodriguez 		 * (0 dBm -> higher output power) */
1080203c4805SLuis R. Rodriguez 		for (c = 0; c < AR5K_EEPROM_N_XPD0_POINTS; c++) {
1081203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1082203c4805SLuis R. Rodriguez 			chan_pcal_info->pwr_x0[c] = (s8) (val & 0xff);
1083203c4805SLuis R. Rodriguez 			chan_pcal_info->pwr_x0[++c] = (s8) ((val >> 8) & 0xff);
1084203c4805SLuis R. Rodriguez 		}
1085203c4805SLuis R. Rodriguez 
1086203c4805SLuis R. Rodriguez 		/* PCDAC steps
1087203c4805SLuis R. Rodriguez 		 * corresponding to the above power
1088203c4805SLuis R. Rodriguez 		 * measurements */
1089203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
1090203c4805SLuis R. Rodriguez 		chan_pcal_info->pcdac_x0[1] = (val & 0x1f);
1091203c4805SLuis R. Rodriguez 		chan_pcal_info->pcdac_x0[2] = ((val >> 5) & 0x1f);
1092203c4805SLuis R. Rodriguez 		chan_pcal_info->pcdac_x0[3] = ((val >> 10) & 0x1f);
1093203c4805SLuis R. Rodriguez 
1094203c4805SLuis R. Rodriguez 		/* Power values in quarter dB
1095203c4805SLuis R. Rodriguez 		 * for the higher xpd gain curve
1096203c4805SLuis R. Rodriguez 		 * (18 dBm -> lower output power) */
1097203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
1098203c4805SLuis R. Rodriguez 		chan_pcal_info->pwr_x3[0] = (s8) (val & 0xff);
1099203c4805SLuis R. Rodriguez 		chan_pcal_info->pwr_x3[1] = (s8) ((val >> 8) & 0xff);
1100203c4805SLuis R. Rodriguez 
1101203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
1102203c4805SLuis R. Rodriguez 		chan_pcal_info->pwr_x3[2] = (val & 0xff);
1103203c4805SLuis R. Rodriguez 
1104203c4805SLuis R. Rodriguez 		/* PCDAC steps
1105203c4805SLuis R. Rodriguez 		 * corresponding to the above power
1106203c4805SLuis R. Rodriguez 		 * measurements (fixed) */
1107203c4805SLuis R. Rodriguez 		chan_pcal_info->pcdac_x3[0] = 20;
1108203c4805SLuis R. Rodriguez 		chan_pcal_info->pcdac_x3[1] = 35;
1109203c4805SLuis R. Rodriguez 		chan_pcal_info->pcdac_x3[2] = 63;
1110203c4805SLuis R. Rodriguez 
1111203c4805SLuis R. Rodriguez 		if (ee->ee_version >= AR5K_EEPROM_VERSION_4_3) {
1112203c4805SLuis R. Rodriguez 			chan_pcal_info->pcdac_x0[0] = ((val >> 8) & 0x3f);
1113203c4805SLuis R. Rodriguez 
1114203c4805SLuis R. Rodriguez 			/* Last xpd0 power level is also channel maximum */
1115203c4805SLuis R. Rodriguez 			gen_chan_info[i].max_pwr = chan_pcal_info->pwr_x0[3];
1116203c4805SLuis R. Rodriguez 		} else {
1117203c4805SLuis R. Rodriguez 			chan_pcal_info->pcdac_x0[0] = 1;
1118203c4805SLuis R. Rodriguez 			gen_chan_info[i].max_pwr = (s8) ((val >> 8) & 0xff);
1119203c4805SLuis R. Rodriguez 		}
1120203c4805SLuis R. Rodriguez 
1121203c4805SLuis R. Rodriguez 	}
1122203c4805SLuis R. Rodriguez 
1123203c4805SLuis R. Rodriguez 	return ath5k_eeprom_convert_pcal_info_5112(ah, mode, gen_chan_info);
1124203c4805SLuis R. Rodriguez }
1125203c4805SLuis R. Rodriguez 
1126203c4805SLuis R. Rodriguez 
1127203c4805SLuis R. Rodriguez /*
1128203c4805SLuis R. Rodriguez  * Read power calibration for RF2413 chips
1129203c4805SLuis R. Rodriguez  *
1130203c4805SLuis R. Rodriguez  * For RF2413 we have a Power to PDDAC table (Power Detector)
1131203c4805SLuis R. Rodriguez  * instead of a PCDAC and 4 pd gain curves for each calibrated channel.
1132203c4805SLuis R. Rodriguez  * Each curve has power on x axis in 0.5 db steps and PDDADC steps on y
1133203c4805SLuis R. Rodriguez  * axis and looks like an exponential function like the RF5111 curve.
1134203c4805SLuis R. Rodriguez  *
1135203c4805SLuis R. Rodriguez  * To recreate the curves we read here the points and interpolate
1136203c4805SLuis R. Rodriguez  * later. Note that in most cases only 2 (higher and lower) curves are
113725985edcSLucas De Marchi  * used (like RF5112) but vendors have the opportunity to include all
1138203c4805SLuis R. Rodriguez  * 4 curves on eeprom. The final curve (higher power) has an extra
1139203c4805SLuis R. Rodriguez  * point for better accuracy like RF5112.
1140203c4805SLuis R. Rodriguez  */
1141203c4805SLuis R. Rodriguez 
1142203c4805SLuis R. Rodriguez /* For RF2413 power calibration data doesn't start on a fixed location and
1143a180a130SBob Copeland  * if a mode is not supported, its section is missing -not zeroed-.
1144203c4805SLuis R. Rodriguez  * So we need to calculate the starting offset for each section by using
1145203c4805SLuis R. Rodriguez  * these two functions */
1146203c4805SLuis R. Rodriguez 
1147203c4805SLuis R. Rodriguez /* Return the size of each section based on the mode and the number of pd
1148203c4805SLuis R. Rodriguez  * gains available (maximum 4). */
1149203c4805SLuis R. Rodriguez static inline unsigned int
1150203c4805SLuis R. Rodriguez ath5k_pdgains_size_2413(struct ath5k_eeprom_info *ee, unsigned int mode)
1151203c4805SLuis R. Rodriguez {
1152203c4805SLuis R. Rodriguez 	static const unsigned int pdgains_size[] = { 4, 6, 9, 12 };
1153203c4805SLuis R. Rodriguez 	unsigned int sz;
1154203c4805SLuis R. Rodriguez 
1155203c4805SLuis R. Rodriguez 	sz = pdgains_size[ee->ee_pd_gains[mode] - 1];
1156203c4805SLuis R. Rodriguez 	sz *= ee->ee_n_piers[mode];
1157203c4805SLuis R. Rodriguez 
1158203c4805SLuis R. Rodriguez 	return sz;
1159203c4805SLuis R. Rodriguez }
1160203c4805SLuis R. Rodriguez 
1161203c4805SLuis R. Rodriguez /* Return the starting offset for a section based on the modes supported
1162203c4805SLuis R. Rodriguez  * and each section's size. */
1163203c4805SLuis R. Rodriguez static unsigned int
1164203c4805SLuis R. Rodriguez ath5k_cal_data_offset_2413(struct ath5k_eeprom_info *ee, int mode)
1165203c4805SLuis R. Rodriguez {
1166203c4805SLuis R. Rodriguez 	u32 offset = AR5K_EEPROM_CAL_DATA_START(ee->ee_misc4);
1167203c4805SLuis R. Rodriguez 
1168203c4805SLuis R. Rodriguez 	switch (mode) {
1169203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11G:
1170203c4805SLuis R. Rodriguez 		if (AR5K_EEPROM_HDR_11B(ee->ee_header))
1171203c4805SLuis R. Rodriguez 			offset += ath5k_pdgains_size_2413(ee,
1172203c4805SLuis R. Rodriguez 					AR5K_EEPROM_MODE_11B) +
1173203c4805SLuis R. Rodriguez 					AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2;
1174203c4805SLuis R. Rodriguez 		/* fall through */
1175203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11B:
1176203c4805SLuis R. Rodriguez 		if (AR5K_EEPROM_HDR_11A(ee->ee_header))
1177203c4805SLuis R. Rodriguez 			offset += ath5k_pdgains_size_2413(ee,
1178203c4805SLuis R. Rodriguez 					AR5K_EEPROM_MODE_11A) +
1179203c4805SLuis R. Rodriguez 					AR5K_EEPROM_N_5GHZ_CHAN / 2;
1180203c4805SLuis R. Rodriguez 		/* fall through */
1181203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11A:
1182203c4805SLuis R. Rodriguez 		break;
1183203c4805SLuis R. Rodriguez 	default:
1184203c4805SLuis R. Rodriguez 		break;
1185203c4805SLuis R. Rodriguez 	}
1186203c4805SLuis R. Rodriguez 
1187203c4805SLuis R. Rodriguez 	return offset;
1188203c4805SLuis R. Rodriguez }
1189203c4805SLuis R. Rodriguez 
1190203c4805SLuis R. Rodriguez /* Convert RF2413 specific data to generic raw data
1191203c4805SLuis R. Rodriguez  * used by interpolation code */
1192203c4805SLuis R. Rodriguez static int
1193203c4805SLuis R. Rodriguez ath5k_eeprom_convert_pcal_info_2413(struct ath5k_hw *ah, int mode,
1194203c4805SLuis R. Rodriguez 				struct ath5k_chan_pcal_info *chinfo)
1195203c4805SLuis R. Rodriguez {
1196203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1197203c4805SLuis R. Rodriguez 	struct ath5k_chan_pcal_info_rf2413 *pcinfo;
1198203c4805SLuis R. Rodriguez 	u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
1199203c4805SLuis R. Rodriguez 	unsigned int pier, pdg, point;
1200203c4805SLuis R. Rodriguez 
1201203c4805SLuis R. Rodriguez 	/* Fill raw data for each calibration pier */
1202203c4805SLuis R. Rodriguez 	for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
1203203c4805SLuis R. Rodriguez 
1204203c4805SLuis R. Rodriguez 		pcinfo = &chinfo[pier].rf2413_info;
1205203c4805SLuis R. Rodriguez 
1206203c4805SLuis R. Rodriguez 		/* Allocate pd_curves for this cal pier */
1207203c4805SLuis R. Rodriguez 		chinfo[pier].pd_curves =
1208203c4805SLuis R. Rodriguez 				kcalloc(AR5K_EEPROM_N_PD_CURVES,
1209203c4805SLuis R. Rodriguez 					sizeof(struct ath5k_pdgain_info),
1210203c4805SLuis R. Rodriguez 					GFP_KERNEL);
1211203c4805SLuis R. Rodriguez 
1212203c4805SLuis R. Rodriguez 		if (!chinfo[pier].pd_curves)
1213a0657846SJohn W. Linville 			goto err_out;
1214203c4805SLuis R. Rodriguez 
1215203c4805SLuis R. Rodriguez 		/* Fill pd_curves */
1216203c4805SLuis R. Rodriguez 		for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) {
1217203c4805SLuis R. Rodriguez 
1218203c4805SLuis R. Rodriguez 			u8 idx = pdgain_idx[pdg];
1219203c4805SLuis R. Rodriguez 			struct ath5k_pdgain_info *pd =
1220203c4805SLuis R. Rodriguez 					&chinfo[pier].pd_curves[idx];
1221203c4805SLuis R. Rodriguez 
1222203c4805SLuis R. Rodriguez 			/* One more point for the highest power
1223203c4805SLuis R. Rodriguez 			 * curve (lowest gain) */
1224203c4805SLuis R. Rodriguez 			if (pdg == ee->ee_pd_gains[mode] - 1)
1225203c4805SLuis R. Rodriguez 				pd->pd_points = AR5K_EEPROM_N_PD_POINTS;
1226203c4805SLuis R. Rodriguez 			else
1227203c4805SLuis R. Rodriguez 				pd->pd_points = AR5K_EEPROM_N_PD_POINTS - 1;
1228203c4805SLuis R. Rodriguez 
1229203c4805SLuis R. Rodriguez 			/* Allocate pd points for this curve */
1230203c4805SLuis R. Rodriguez 			pd->pd_step = kcalloc(pd->pd_points,
1231203c4805SLuis R. Rodriguez 					sizeof(u8), GFP_KERNEL);
1232203c4805SLuis R. Rodriguez 
1233203c4805SLuis R. Rodriguez 			if (!pd->pd_step)
1234a0657846SJohn W. Linville 				goto err_out;
1235203c4805SLuis R. Rodriguez 
1236203c4805SLuis R. Rodriguez 			pd->pd_pwr = kcalloc(pd->pd_points,
1237203c4805SLuis R. Rodriguez 					sizeof(s16), GFP_KERNEL);
1238203c4805SLuis R. Rodriguez 
1239203c4805SLuis R. Rodriguez 			if (!pd->pd_pwr)
1240a0657846SJohn W. Linville 				goto err_out;
1241203c4805SLuis R. Rodriguez 
1242203c4805SLuis R. Rodriguez 			/* Fill raw dataset
1243203c4805SLuis R. Rodriguez 			 * convert all pwr levels to
1244*6a2a0e73SPavel Roskin 			 * quarter dB for RF5112 compatibility */
1245203c4805SLuis R. Rodriguez 			pd->pd_step[0] = pcinfo->pddac_i[pdg];
1246203c4805SLuis R. Rodriguez 			pd->pd_pwr[0] = 4 * pcinfo->pwr_i[pdg];
1247203c4805SLuis R. Rodriguez 
1248203c4805SLuis R. Rodriguez 			for (point = 1; point < pd->pd_points; point++) {
1249203c4805SLuis R. Rodriguez 
1250203c4805SLuis R. Rodriguez 				pd->pd_pwr[point] = pd->pd_pwr[point - 1] +
1251203c4805SLuis R. Rodriguez 					2 * pcinfo->pwr[pdg][point - 1];
1252203c4805SLuis R. Rodriguez 
1253203c4805SLuis R. Rodriguez 				pd->pd_step[point] = pd->pd_step[point - 1] +
1254203c4805SLuis R. Rodriguez 						pcinfo->pddac[pdg][point - 1];
1255203c4805SLuis R. Rodriguez 
1256203c4805SLuis R. Rodriguez 			}
1257203c4805SLuis R. Rodriguez 
1258203c4805SLuis R. Rodriguez 			/* Highest gain curve -> min power */
1259203c4805SLuis R. Rodriguez 			if (pdg == 0)
1260203c4805SLuis R. Rodriguez 				chinfo[pier].min_pwr = pd->pd_pwr[0];
1261203c4805SLuis R. Rodriguez 
1262203c4805SLuis R. Rodriguez 			/* Lowest gain curve -> max power */
1263203c4805SLuis R. Rodriguez 			if (pdg == ee->ee_pd_gains[mode] - 1)
1264203c4805SLuis R. Rodriguez 				chinfo[pier].max_pwr =
1265203c4805SLuis R. Rodriguez 					pd->pd_pwr[pd->pd_points - 1];
1266203c4805SLuis R. Rodriguez 		}
1267203c4805SLuis R. Rodriguez 	}
1268203c4805SLuis R. Rodriguez 
1269203c4805SLuis R. Rodriguez 	return 0;
1270a0657846SJohn W. Linville 
1271a0657846SJohn W. Linville err_out:
1272a0657846SJohn W. Linville 	ath5k_eeprom_free_pcal_info(ah, mode);
1273a0657846SJohn W. Linville 	return -ENOMEM;
1274203c4805SLuis R. Rodriguez }
1275203c4805SLuis R. Rodriguez 
1276203c4805SLuis R. Rodriguez /* Parse EEPROM data */
1277203c4805SLuis R. Rodriguez static int
1278203c4805SLuis R. Rodriguez ath5k_eeprom_read_pcal_info_2413(struct ath5k_hw *ah, int mode)
1279203c4805SLuis R. Rodriguez {
1280203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1281203c4805SLuis R. Rodriguez 	struct ath5k_chan_pcal_info_rf2413 *pcinfo;
1282203c4805SLuis R. Rodriguez 	struct ath5k_chan_pcal_info *chinfo;
1283203c4805SLuis R. Rodriguez 	u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
1284203c4805SLuis R. Rodriguez 	u32 offset;
1285fda9b7afSWojciech Dubowik 	int idx, i;
1286203c4805SLuis R. Rodriguez 	u16 val;
1287203c4805SLuis R. Rodriguez 	u8 pd_gains = 0;
1288203c4805SLuis R. Rodriguez 
1289203c4805SLuis R. Rodriguez 	/* Count how many curves we have and
1290203c4805SLuis R. Rodriguez 	 * identify them (which one of the 4
1291203c4805SLuis R. Rodriguez 	 * available curves we have on each count).
1292203c4805SLuis R. Rodriguez 	 * Curves are stored from higher to
1293203c4805SLuis R. Rodriguez 	 * lower gain so we go backwards */
1294203c4805SLuis R. Rodriguez 	for (idx = AR5K_EEPROM_N_PD_CURVES - 1; idx >= 0; idx--) {
1295203c4805SLuis R. Rodriguez 		/* ee_x_gain[mode] is x gain mask */
1296203c4805SLuis R. Rodriguez 		if ((ee->ee_x_gain[mode] >> idx) & 0x1)
1297203c4805SLuis R. Rodriguez 			pdgain_idx[pd_gains++] = idx;
1298203c4805SLuis R. Rodriguez 
1299203c4805SLuis R. Rodriguez 	}
1300203c4805SLuis R. Rodriguez 	ee->ee_pd_gains[mode] = pd_gains;
1301203c4805SLuis R. Rodriguez 
1302203c4805SLuis R. Rodriguez 	if (pd_gains == 0)
1303203c4805SLuis R. Rodriguez 		return -EINVAL;
1304203c4805SLuis R. Rodriguez 
1305203c4805SLuis R. Rodriguez 	offset = ath5k_cal_data_offset_2413(ee, mode);
1306203c4805SLuis R. Rodriguez 	switch (mode) {
1307203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11A:
1308203c4805SLuis R. Rodriguez 		if (!AR5K_EEPROM_HDR_11A(ee->ee_header))
1309203c4805SLuis R. Rodriguez 			return 0;
1310203c4805SLuis R. Rodriguez 
1311203c4805SLuis R. Rodriguez 		ath5k_eeprom_init_11a_pcal_freq(ah, offset);
1312203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_N_5GHZ_CHAN / 2;
1313203c4805SLuis R. Rodriguez 		chinfo = ee->ee_pwr_cal_a;
1314203c4805SLuis R. Rodriguez 		break;
1315203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11B:
1316203c4805SLuis R. Rodriguez 		if (!AR5K_EEPROM_HDR_11B(ee->ee_header))
1317203c4805SLuis R. Rodriguez 			return 0;
1318203c4805SLuis R. Rodriguez 
1319203c4805SLuis R. Rodriguez 		ath5k_eeprom_init_11bg_2413(ah, mode, offset);
1320203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2;
1321203c4805SLuis R. Rodriguez 		chinfo = ee->ee_pwr_cal_b;
1322203c4805SLuis R. Rodriguez 		break;
1323203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11G:
1324203c4805SLuis R. Rodriguez 		if (!AR5K_EEPROM_HDR_11G(ee->ee_header))
1325203c4805SLuis R. Rodriguez 			return 0;
1326203c4805SLuis R. Rodriguez 
1327203c4805SLuis R. Rodriguez 		ath5k_eeprom_init_11bg_2413(ah, mode, offset);
1328203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2;
1329203c4805SLuis R. Rodriguez 		chinfo = ee->ee_pwr_cal_g;
1330203c4805SLuis R. Rodriguez 		break;
1331203c4805SLuis R. Rodriguez 	default:
1332203c4805SLuis R. Rodriguez 		return -EINVAL;
1333203c4805SLuis R. Rodriguez 	}
1334203c4805SLuis R. Rodriguez 
1335203c4805SLuis R. Rodriguez 	for (i = 0; i < ee->ee_n_piers[mode]; i++) {
1336203c4805SLuis R. Rodriguez 		pcinfo = &chinfo[i].rf2413_info;
1337203c4805SLuis R. Rodriguez 
1338203c4805SLuis R. Rodriguez 		/*
1339203c4805SLuis R. Rodriguez 		 * Read pwr_i, pddac_i and the first
1340203c4805SLuis R. Rodriguez 		 * 2 pd points (pwr, pddac)
1341203c4805SLuis R. Rodriguez 		 */
1342203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
1343203c4805SLuis R. Rodriguez 		pcinfo->pwr_i[0] = val & 0x1f;
1344203c4805SLuis R. Rodriguez 		pcinfo->pddac_i[0] = (val >> 5) & 0x7f;
1345203c4805SLuis R. Rodriguez 		pcinfo->pwr[0][0] = (val >> 12) & 0xf;
1346203c4805SLuis R. Rodriguez 
1347203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
1348203c4805SLuis R. Rodriguez 		pcinfo->pddac[0][0] = val & 0x3f;
1349203c4805SLuis R. Rodriguez 		pcinfo->pwr[0][1] = (val >> 6) & 0xf;
1350203c4805SLuis R. Rodriguez 		pcinfo->pddac[0][1] = (val >> 10) & 0x3f;
1351203c4805SLuis R. Rodriguez 
1352203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
1353203c4805SLuis R. Rodriguez 		pcinfo->pwr[0][2] = val & 0xf;
1354203c4805SLuis R. Rodriguez 		pcinfo->pddac[0][2] = (val >> 4) & 0x3f;
1355203c4805SLuis R. Rodriguez 
1356203c4805SLuis R. Rodriguez 		pcinfo->pwr[0][3] = 0;
1357203c4805SLuis R. Rodriguez 		pcinfo->pddac[0][3] = 0;
1358203c4805SLuis R. Rodriguez 
1359203c4805SLuis R. Rodriguez 		if (pd_gains > 1) {
1360203c4805SLuis R. Rodriguez 			/*
1361203c4805SLuis R. Rodriguez 			 * Pd gain 0 is not the last pd gain
1362203c4805SLuis R. Rodriguez 			 * so it only has 2 pd points.
136325985edcSLucas De Marchi 			 * Continue with pd gain 1.
1364203c4805SLuis R. Rodriguez 			 */
1365203c4805SLuis R. Rodriguez 			pcinfo->pwr_i[1] = (val >> 10) & 0x1f;
1366203c4805SLuis R. Rodriguez 
1367203c4805SLuis R. Rodriguez 			pcinfo->pddac_i[1] = (val >> 15) & 0x1;
1368203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1369203c4805SLuis R. Rodriguez 			pcinfo->pddac_i[1] |= (val & 0x3F) << 1;
1370203c4805SLuis R. Rodriguez 
1371203c4805SLuis R. Rodriguez 			pcinfo->pwr[1][0] = (val >> 6) & 0xf;
1372203c4805SLuis R. Rodriguez 			pcinfo->pddac[1][0] = (val >> 10) & 0x3f;
1373203c4805SLuis R. Rodriguez 
1374203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1375203c4805SLuis R. Rodriguez 			pcinfo->pwr[1][1] = val & 0xf;
1376203c4805SLuis R. Rodriguez 			pcinfo->pddac[1][1] = (val >> 4) & 0x3f;
1377203c4805SLuis R. Rodriguez 			pcinfo->pwr[1][2] = (val >> 10) & 0xf;
1378203c4805SLuis R. Rodriguez 
1379203c4805SLuis R. Rodriguez 			pcinfo->pddac[1][2] = (val >> 14) & 0x3;
1380203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1381203c4805SLuis R. Rodriguez 			pcinfo->pddac[1][2] |= (val & 0xF) << 2;
1382203c4805SLuis R. Rodriguez 
1383203c4805SLuis R. Rodriguez 			pcinfo->pwr[1][3] = 0;
1384203c4805SLuis R. Rodriguez 			pcinfo->pddac[1][3] = 0;
1385203c4805SLuis R. Rodriguez 		} else if (pd_gains == 1) {
1386203c4805SLuis R. Rodriguez 			/*
1387203c4805SLuis R. Rodriguez 			 * Pd gain 0 is the last one so
1388203c4805SLuis R. Rodriguez 			 * read the extra point.
1389203c4805SLuis R. Rodriguez 			 */
1390203c4805SLuis R. Rodriguez 			pcinfo->pwr[0][3] = (val >> 10) & 0xf;
1391203c4805SLuis R. Rodriguez 
1392203c4805SLuis R. Rodriguez 			pcinfo->pddac[0][3] = (val >> 14) & 0x3;
1393203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1394203c4805SLuis R. Rodriguez 			pcinfo->pddac[0][3] |= (val & 0xF) << 2;
1395203c4805SLuis R. Rodriguez 		}
1396203c4805SLuis R. Rodriguez 
1397203c4805SLuis R. Rodriguez 		/*
1398203c4805SLuis R. Rodriguez 		 * Proceed with the other pd_gains
1399203c4805SLuis R. Rodriguez 		 * as above.
1400203c4805SLuis R. Rodriguez 		 */
1401203c4805SLuis R. Rodriguez 		if (pd_gains > 2) {
1402203c4805SLuis R. Rodriguez 			pcinfo->pwr_i[2] = (val >> 4) & 0x1f;
1403203c4805SLuis R. Rodriguez 			pcinfo->pddac_i[2] = (val >> 9) & 0x7f;
1404203c4805SLuis R. Rodriguez 
1405203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1406203c4805SLuis R. Rodriguez 			pcinfo->pwr[2][0] = (val >> 0) & 0xf;
1407203c4805SLuis R. Rodriguez 			pcinfo->pddac[2][0] = (val >> 4) & 0x3f;
1408203c4805SLuis R. Rodriguez 			pcinfo->pwr[2][1] = (val >> 10) & 0xf;
1409203c4805SLuis R. Rodriguez 
1410203c4805SLuis R. Rodriguez 			pcinfo->pddac[2][1] = (val >> 14) & 0x3;
1411203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1412203c4805SLuis R. Rodriguez 			pcinfo->pddac[2][1] |= (val & 0xF) << 2;
1413203c4805SLuis R. Rodriguez 
1414203c4805SLuis R. Rodriguez 			pcinfo->pwr[2][2] = (val >> 4) & 0xf;
1415203c4805SLuis R. Rodriguez 			pcinfo->pddac[2][2] = (val >> 8) & 0x3f;
1416203c4805SLuis R. Rodriguez 
1417203c4805SLuis R. Rodriguez 			pcinfo->pwr[2][3] = 0;
1418203c4805SLuis R. Rodriguez 			pcinfo->pddac[2][3] = 0;
1419203c4805SLuis R. Rodriguez 		} else if (pd_gains == 2) {
1420203c4805SLuis R. Rodriguez 			pcinfo->pwr[1][3] = (val >> 4) & 0xf;
1421203c4805SLuis R. Rodriguez 			pcinfo->pddac[1][3] = (val >> 8) & 0x3f;
1422203c4805SLuis R. Rodriguez 		}
1423203c4805SLuis R. Rodriguez 
1424203c4805SLuis R. Rodriguez 		if (pd_gains > 3) {
1425203c4805SLuis R. Rodriguez 			pcinfo->pwr_i[3] = (val >> 14) & 0x3;
1426203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1427203c4805SLuis R. Rodriguez 			pcinfo->pwr_i[3] |= ((val >> 0) & 0x7) << 2;
1428203c4805SLuis R. Rodriguez 
1429203c4805SLuis R. Rodriguez 			pcinfo->pddac_i[3] = (val >> 3) & 0x7f;
1430203c4805SLuis R. Rodriguez 			pcinfo->pwr[3][0] = (val >> 10) & 0xf;
1431203c4805SLuis R. Rodriguez 			pcinfo->pddac[3][0] = (val >> 14) & 0x3;
1432203c4805SLuis R. Rodriguez 
1433203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1434203c4805SLuis R. Rodriguez 			pcinfo->pddac[3][0] |= (val & 0xF) << 2;
1435203c4805SLuis R. Rodriguez 			pcinfo->pwr[3][1] = (val >> 4) & 0xf;
1436203c4805SLuis R. Rodriguez 			pcinfo->pddac[3][1] = (val >> 8) & 0x3f;
1437203c4805SLuis R. Rodriguez 
1438203c4805SLuis R. Rodriguez 			pcinfo->pwr[3][2] = (val >> 14) & 0x3;
1439203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1440203c4805SLuis R. Rodriguez 			pcinfo->pwr[3][2] |= ((val >> 0) & 0x3) << 2;
1441203c4805SLuis R. Rodriguez 
1442203c4805SLuis R. Rodriguez 			pcinfo->pddac[3][2] = (val >> 2) & 0x3f;
1443203c4805SLuis R. Rodriguez 			pcinfo->pwr[3][3] = (val >> 8) & 0xf;
1444203c4805SLuis R. Rodriguez 
1445203c4805SLuis R. Rodriguez 			pcinfo->pddac[3][3] = (val >> 12) & 0xF;
1446203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1447203c4805SLuis R. Rodriguez 			pcinfo->pddac[3][3] |= ((val >> 0) & 0x3) << 4;
1448203c4805SLuis R. Rodriguez 		} else if (pd_gains == 3) {
1449203c4805SLuis R. Rodriguez 			pcinfo->pwr[2][3] = (val >> 14) & 0x3;
1450203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1451203c4805SLuis R. Rodriguez 			pcinfo->pwr[2][3] |= ((val >> 0) & 0x3) << 2;
1452203c4805SLuis R. Rodriguez 
1453203c4805SLuis R. Rodriguez 			pcinfo->pddac[2][3] = (val >> 2) & 0x3f;
1454203c4805SLuis R. Rodriguez 		}
1455203c4805SLuis R. Rodriguez 	}
1456203c4805SLuis R. Rodriguez 
1457203c4805SLuis R. Rodriguez 	return ath5k_eeprom_convert_pcal_info_2413(ah, mode, chinfo);
1458203c4805SLuis R. Rodriguez }
1459203c4805SLuis R. Rodriguez 
1460203c4805SLuis R. Rodriguez 
1461203c4805SLuis R. Rodriguez /*
1462203c4805SLuis R. Rodriguez  * Read per rate target power (this is the maximum tx power
1463203c4805SLuis R. Rodriguez  * supported by the card). This info is used when setting
1464203c4805SLuis R. Rodriguez  * tx power, no matter the channel.
1465203c4805SLuis R. Rodriguez  *
1466203c4805SLuis R. Rodriguez  * This also works for v5 EEPROMs.
1467203c4805SLuis R. Rodriguez  */
1468203c4805SLuis R. Rodriguez static int
1469203c4805SLuis R. Rodriguez ath5k_eeprom_read_target_rate_pwr_info(struct ath5k_hw *ah, unsigned int mode)
1470203c4805SLuis R. Rodriguez {
1471203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1472203c4805SLuis R. Rodriguez 	struct ath5k_rate_pcal_info *rate_pcal_info;
1473203c4805SLuis R. Rodriguez 	u8 *rate_target_pwr_num;
1474203c4805SLuis R. Rodriguez 	u32 offset;
1475203c4805SLuis R. Rodriguez 	u16 val;
1476fda9b7afSWojciech Dubowik 	int i;
1477203c4805SLuis R. Rodriguez 
1478203c4805SLuis R. Rodriguez 	offset = AR5K_EEPROM_TARGET_PWRSTART(ee->ee_misc1);
1479203c4805SLuis R. Rodriguez 	rate_target_pwr_num = &ee->ee_rate_target_pwr_num[mode];
1480203c4805SLuis R. Rodriguez 	switch (mode) {
1481203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11A:
1482203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_TARGET_PWR_OFF_11A(ee->ee_version);
1483203c4805SLuis R. Rodriguez 		rate_pcal_info = ee->ee_rate_tpwr_a;
1484203c4805SLuis R. Rodriguez 		ee->ee_rate_target_pwr_num[mode] = AR5K_EEPROM_N_5GHZ_CHAN;
1485203c4805SLuis R. Rodriguez 		break;
1486203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11B:
1487203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_TARGET_PWR_OFF_11B(ee->ee_version);
1488203c4805SLuis R. Rodriguez 		rate_pcal_info = ee->ee_rate_tpwr_b;
1489203c4805SLuis R. Rodriguez 		ee->ee_rate_target_pwr_num[mode] = 2; /* 3rd is g mode's 1st */
1490203c4805SLuis R. Rodriguez 		break;
1491203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11G:
1492203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_TARGET_PWR_OFF_11G(ee->ee_version);
1493203c4805SLuis R. Rodriguez 		rate_pcal_info = ee->ee_rate_tpwr_g;
1494203c4805SLuis R. Rodriguez 		ee->ee_rate_target_pwr_num[mode] = AR5K_EEPROM_N_2GHZ_CHAN;
1495203c4805SLuis R. Rodriguez 		break;
1496203c4805SLuis R. Rodriguez 	default:
1497203c4805SLuis R. Rodriguez 		return -EINVAL;
1498203c4805SLuis R. Rodriguez 	}
1499203c4805SLuis R. Rodriguez 
1500203c4805SLuis R. Rodriguez 	/* Different freq mask for older eeproms (<= v3.2) */
1501203c4805SLuis R. Rodriguez 	if (ee->ee_version <= AR5K_EEPROM_VERSION_3_2) {
1502203c4805SLuis R. Rodriguez 		for (i = 0; i < (*rate_target_pwr_num); i++) {
1503203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1504203c4805SLuis R. Rodriguez 			rate_pcal_info[i].freq =
1505203c4805SLuis R. Rodriguez 			    ath5k_eeprom_bin2freq(ee, (val >> 9) & 0x7f, mode);
1506203c4805SLuis R. Rodriguez 
1507203c4805SLuis R. Rodriguez 			rate_pcal_info[i].target_power_6to24 = ((val >> 3) & 0x3f);
1508203c4805SLuis R. Rodriguez 			rate_pcal_info[i].target_power_36 = (val << 3) & 0x3f;
1509203c4805SLuis R. Rodriguez 
1510203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1511203c4805SLuis R. Rodriguez 
1512203c4805SLuis R. Rodriguez 			if (rate_pcal_info[i].freq == AR5K_EEPROM_CHANNEL_DIS ||
1513203c4805SLuis R. Rodriguez 			    val == 0) {
1514203c4805SLuis R. Rodriguez 				(*rate_target_pwr_num) = i;
1515203c4805SLuis R. Rodriguez 				break;
1516203c4805SLuis R. Rodriguez 			}
1517203c4805SLuis R. Rodriguez 
1518203c4805SLuis R. Rodriguez 			rate_pcal_info[i].target_power_36 |= ((val >> 13) & 0x7);
1519203c4805SLuis R. Rodriguez 			rate_pcal_info[i].target_power_48 = ((val >> 7) & 0x3f);
1520203c4805SLuis R. Rodriguez 			rate_pcal_info[i].target_power_54 = ((val >> 1) & 0x3f);
1521203c4805SLuis R. Rodriguez 		}
1522203c4805SLuis R. Rodriguez 	} else {
1523203c4805SLuis R. Rodriguez 		for (i = 0; i < (*rate_target_pwr_num); i++) {
1524203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1525203c4805SLuis R. Rodriguez 			rate_pcal_info[i].freq =
1526203c4805SLuis R. Rodriguez 			    ath5k_eeprom_bin2freq(ee, (val >> 8) & 0xff, mode);
1527203c4805SLuis R. Rodriguez 
1528203c4805SLuis R. Rodriguez 			rate_pcal_info[i].target_power_6to24 = ((val >> 2) & 0x3f);
1529203c4805SLuis R. Rodriguez 			rate_pcal_info[i].target_power_36 = (val << 4) & 0x3f;
1530203c4805SLuis R. Rodriguez 
1531203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1532203c4805SLuis R. Rodriguez 
1533203c4805SLuis R. Rodriguez 			if (rate_pcal_info[i].freq == AR5K_EEPROM_CHANNEL_DIS ||
1534203c4805SLuis R. Rodriguez 			    val == 0) {
1535203c4805SLuis R. Rodriguez 				(*rate_target_pwr_num) = i;
1536203c4805SLuis R. Rodriguez 				break;
1537203c4805SLuis R. Rodriguez 			}
1538203c4805SLuis R. Rodriguez 
1539203c4805SLuis R. Rodriguez 			rate_pcal_info[i].target_power_36 |= (val >> 12) & 0xf;
1540203c4805SLuis R. Rodriguez 			rate_pcal_info[i].target_power_48 = ((val >> 6) & 0x3f);
1541203c4805SLuis R. Rodriguez 			rate_pcal_info[i].target_power_54 = (val & 0x3f);
1542203c4805SLuis R. Rodriguez 		}
1543203c4805SLuis R. Rodriguez 	}
1544203c4805SLuis R. Rodriguez 
1545203c4805SLuis R. Rodriguez 	return 0;
1546203c4805SLuis R. Rodriguez }
1547203c4805SLuis R. Rodriguez 
15489320b5c4SNick Kossifidis 
1549203c4805SLuis R. Rodriguez /*
1550203c4805SLuis R. Rodriguez  * Read per channel calibration info from EEPROM
1551203c4805SLuis R. Rodriguez  *
1552203c4805SLuis R. Rodriguez  * This info is used to calibrate the baseband power table. Imagine
1553203c4805SLuis R. Rodriguez  * that for each channel there is a power curve that's hw specific
1554203c4805SLuis R. Rodriguez  * (depends on amplifier etc) and we try to "correct" this curve using
1555bf48aabbSUwe Kleine-König  * offsets we pass on to phy chip (baseband -> before amplifier) so that
1556203c4805SLuis R. Rodriguez  * it can use accurate power values when setting tx power (takes amplifier's
1557203c4805SLuis R. Rodriguez  * performance on each channel into account).
1558203c4805SLuis R. Rodriguez  *
1559203c4805SLuis R. Rodriguez  * EEPROM provides us with the offsets for some pre-calibrated channels
1560203c4805SLuis R. Rodriguez  * and we have to interpolate to create the full table for these channels and
1561203c4805SLuis R. Rodriguez  * also the table for any channel.
1562203c4805SLuis R. Rodriguez  */
1563203c4805SLuis R. Rodriguez static int
1564203c4805SLuis R. Rodriguez ath5k_eeprom_read_pcal_info(struct ath5k_hw *ah)
1565203c4805SLuis R. Rodriguez {
1566203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1567203c4805SLuis R. Rodriguez 	int (*read_pcal)(struct ath5k_hw *hw, int mode);
1568203c4805SLuis R. Rodriguez 	int mode;
1569203c4805SLuis R. Rodriguez 	int err;
1570203c4805SLuis R. Rodriguez 
1571203c4805SLuis R. Rodriguez 	if ((ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) &&
1572203c4805SLuis R. Rodriguez 			(AR5K_EEPROM_EEMAP(ee->ee_misc0) == 1))
1573203c4805SLuis R. Rodriguez 		read_pcal = ath5k_eeprom_read_pcal_info_5112;
1574203c4805SLuis R. Rodriguez 	else if ((ah->ah_ee_version >= AR5K_EEPROM_VERSION_5_0) &&
1575203c4805SLuis R. Rodriguez 			(AR5K_EEPROM_EEMAP(ee->ee_misc0) == 2))
1576203c4805SLuis R. Rodriguez 		read_pcal = ath5k_eeprom_read_pcal_info_2413;
1577203c4805SLuis R. Rodriguez 	else
1578203c4805SLuis R. Rodriguez 		read_pcal = ath5k_eeprom_read_pcal_info_5111;
1579203c4805SLuis R. Rodriguez 
1580203c4805SLuis R. Rodriguez 
1581203c4805SLuis R. Rodriguez 	for (mode = AR5K_EEPROM_MODE_11A; mode <= AR5K_EEPROM_MODE_11G;
1582203c4805SLuis R. Rodriguez 	mode++) {
1583203c4805SLuis R. Rodriguez 		err = read_pcal(ah, mode);
1584203c4805SLuis R. Rodriguez 		if (err)
1585203c4805SLuis R. Rodriguez 			return err;
1586203c4805SLuis R. Rodriguez 
1587203c4805SLuis R. Rodriguez 		err = ath5k_eeprom_read_target_rate_pwr_info(ah, mode);
1588203c4805SLuis R. Rodriguez 		if (err < 0)
1589203c4805SLuis R. Rodriguez 			return err;
1590203c4805SLuis R. Rodriguez 	}
1591203c4805SLuis R. Rodriguez 
1592203c4805SLuis R. Rodriguez 	return 0;
1593203c4805SLuis R. Rodriguez }
1594203c4805SLuis R. Rodriguez 
1595203c4805SLuis R. Rodriguez /* Read conformance test limits used for regulatory control */
1596203c4805SLuis R. Rodriguez static int
1597203c4805SLuis R. Rodriguez ath5k_eeprom_read_ctl_info(struct ath5k_hw *ah)
1598203c4805SLuis R. Rodriguez {
1599203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1600203c4805SLuis R. Rodriguez 	struct ath5k_edge_power *rep;
1601203c4805SLuis R. Rodriguez 	unsigned int fmask, pmask;
1602203c4805SLuis R. Rodriguez 	unsigned int ctl_mode;
1603fda9b7afSWojciech Dubowik 	int i, j;
1604203c4805SLuis R. Rodriguez 	u32 offset;
1605203c4805SLuis R. Rodriguez 	u16 val;
1606203c4805SLuis R. Rodriguez 
1607203c4805SLuis R. Rodriguez 	pmask = AR5K_EEPROM_POWER_M;
1608203c4805SLuis R. Rodriguez 	fmask = AR5K_EEPROM_FREQ_M(ee->ee_version);
1609203c4805SLuis R. Rodriguez 	offset = AR5K_EEPROM_CTL(ee->ee_version);
1610203c4805SLuis R. Rodriguez 	ee->ee_ctls = AR5K_EEPROM_N_CTLS(ee->ee_version);
1611203c4805SLuis R. Rodriguez 	for (i = 0; i < ee->ee_ctls; i += 2) {
1612203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
1613203c4805SLuis R. Rodriguez 		ee->ee_ctl[i] = (val >> 8) & 0xff;
1614203c4805SLuis R. Rodriguez 		ee->ee_ctl[i + 1] = val & 0xff;
1615203c4805SLuis R. Rodriguez 	}
1616203c4805SLuis R. Rodriguez 
1617203c4805SLuis R. Rodriguez 	offset = AR5K_EEPROM_GROUP8_OFFSET;
1618203c4805SLuis R. Rodriguez 	if (ee->ee_version >= AR5K_EEPROM_VERSION_4_0)
1619203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_TARGET_PWRSTART(ee->ee_misc1) -
1620203c4805SLuis R. Rodriguez 			AR5K_EEPROM_GROUP5_OFFSET;
1621203c4805SLuis R. Rodriguez 	else
1622203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_GROUPS_START(ee->ee_version);
1623203c4805SLuis R. Rodriguez 
1624203c4805SLuis R. Rodriguez 	rep = ee->ee_ctl_pwr;
1625203c4805SLuis R. Rodriguez 	for (i = 0; i < ee->ee_ctls; i++) {
1626203c4805SLuis R. Rodriguez 		switch (ee->ee_ctl[i] & AR5K_CTL_MODE_M) {
1627203c4805SLuis R. Rodriguez 		case AR5K_CTL_11A:
1628203c4805SLuis R. Rodriguez 		case AR5K_CTL_TURBO:
1629203c4805SLuis R. Rodriguez 			ctl_mode = AR5K_EEPROM_MODE_11A;
1630203c4805SLuis R. Rodriguez 			break;
1631203c4805SLuis R. Rodriguez 		default:
1632203c4805SLuis R. Rodriguez 			ctl_mode = AR5K_EEPROM_MODE_11G;
1633203c4805SLuis R. Rodriguez 			break;
1634203c4805SLuis R. Rodriguez 		}
1635203c4805SLuis R. Rodriguez 		if (ee->ee_ctl[i] == 0) {
1636203c4805SLuis R. Rodriguez 			if (ee->ee_version >= AR5K_EEPROM_VERSION_3_3)
1637203c4805SLuis R. Rodriguez 				offset += 8;
1638203c4805SLuis R. Rodriguez 			else
1639203c4805SLuis R. Rodriguez 				offset += 7;
1640203c4805SLuis R. Rodriguez 			rep += AR5K_EEPROM_N_EDGES;
1641203c4805SLuis R. Rodriguez 			continue;
1642203c4805SLuis R. Rodriguez 		}
1643203c4805SLuis R. Rodriguez 		if (ee->ee_version >= AR5K_EEPROM_VERSION_3_3) {
1644203c4805SLuis R. Rodriguez 			for (j = 0; j < AR5K_EEPROM_N_EDGES; j += 2) {
1645203c4805SLuis R. Rodriguez 				AR5K_EEPROM_READ(offset++, val);
1646203c4805SLuis R. Rodriguez 				rep[j].freq = (val >> 8) & fmask;
1647203c4805SLuis R. Rodriguez 				rep[j + 1].freq = val & fmask;
1648203c4805SLuis R. Rodriguez 			}
1649203c4805SLuis R. Rodriguez 			for (j = 0; j < AR5K_EEPROM_N_EDGES; j += 2) {
1650203c4805SLuis R. Rodriguez 				AR5K_EEPROM_READ(offset++, val);
1651203c4805SLuis R. Rodriguez 				rep[j].edge = (val >> 8) & pmask;
1652203c4805SLuis R. Rodriguez 				rep[j].flag = (val >> 14) & 1;
1653203c4805SLuis R. Rodriguez 				rep[j + 1].edge = val & pmask;
1654203c4805SLuis R. Rodriguez 				rep[j + 1].flag = (val >> 6) & 1;
1655203c4805SLuis R. Rodriguez 			}
1656203c4805SLuis R. Rodriguez 		} else {
1657203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1658203c4805SLuis R. Rodriguez 			rep[0].freq = (val >> 9) & fmask;
1659203c4805SLuis R. Rodriguez 			rep[1].freq = (val >> 2) & fmask;
1660203c4805SLuis R. Rodriguez 			rep[2].freq = (val << 5) & fmask;
1661203c4805SLuis R. Rodriguez 
1662203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1663203c4805SLuis R. Rodriguez 			rep[2].freq |= (val >> 11) & 0x1f;
1664203c4805SLuis R. Rodriguez 			rep[3].freq = (val >> 4) & fmask;
1665203c4805SLuis R. Rodriguez 			rep[4].freq = (val << 3) & fmask;
1666203c4805SLuis R. Rodriguez 
1667203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1668203c4805SLuis R. Rodriguez 			rep[4].freq |= (val >> 13) & 0x7;
1669203c4805SLuis R. Rodriguez 			rep[5].freq = (val >> 6) & fmask;
1670203c4805SLuis R. Rodriguez 			rep[6].freq = (val << 1) & fmask;
1671203c4805SLuis R. Rodriguez 
1672203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1673203c4805SLuis R. Rodriguez 			rep[6].freq |= (val >> 15) & 0x1;
1674203c4805SLuis R. Rodriguez 			rep[7].freq = (val >> 8) & fmask;
1675203c4805SLuis R. Rodriguez 
1676203c4805SLuis R. Rodriguez 			rep[0].edge = (val >> 2) & pmask;
1677203c4805SLuis R. Rodriguez 			rep[1].edge = (val << 4) & pmask;
1678203c4805SLuis R. Rodriguez 
1679203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1680203c4805SLuis R. Rodriguez 			rep[1].edge |= (val >> 12) & 0xf;
1681203c4805SLuis R. Rodriguez 			rep[2].edge = (val >> 6) & pmask;
1682203c4805SLuis R. Rodriguez 			rep[3].edge = val & pmask;
1683203c4805SLuis R. Rodriguez 
1684203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1685203c4805SLuis R. Rodriguez 			rep[4].edge = (val >> 10) & pmask;
1686203c4805SLuis R. Rodriguez 			rep[5].edge = (val >> 4) & pmask;
1687203c4805SLuis R. Rodriguez 			rep[6].edge = (val << 2) & pmask;
1688203c4805SLuis R. Rodriguez 
1689203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1690203c4805SLuis R. Rodriguez 			rep[6].edge |= (val >> 14) & 0x3;
1691203c4805SLuis R. Rodriguez 			rep[7].edge = (val >> 8) & pmask;
1692203c4805SLuis R. Rodriguez 		}
1693203c4805SLuis R. Rodriguez 		for (j = 0; j < AR5K_EEPROM_N_EDGES; j++) {
1694203c4805SLuis R. Rodriguez 			rep[j].freq = ath5k_eeprom_bin2freq(ee,
1695203c4805SLuis R. Rodriguez 				rep[j].freq, ctl_mode);
1696203c4805SLuis R. Rodriguez 		}
1697203c4805SLuis R. Rodriguez 		rep += AR5K_EEPROM_N_EDGES;
1698203c4805SLuis R. Rodriguez 	}
1699203c4805SLuis R. Rodriguez 
1700203c4805SLuis R. Rodriguez 	return 0;
1701203c4805SLuis R. Rodriguez }
1702203c4805SLuis R. Rodriguez 
1703cd417519SNick Kossifidis static int
1704cd417519SNick Kossifidis ath5k_eeprom_read_spur_chans(struct ath5k_hw *ah)
1705cd417519SNick Kossifidis {
1706cd417519SNick Kossifidis 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1707cd417519SNick Kossifidis 	u32 offset;
1708cd417519SNick Kossifidis 	u16 val;
1709cd417519SNick Kossifidis 	int ret = 0, i;
1710cd417519SNick Kossifidis 
1711cd417519SNick Kossifidis 	offset = AR5K_EEPROM_CTL(ee->ee_version) +
1712cd417519SNick Kossifidis 				AR5K_EEPROM_N_CTLS(ee->ee_version);
1713cd417519SNick Kossifidis 
1714cd417519SNick Kossifidis 	if (ee->ee_version < AR5K_EEPROM_VERSION_5_3) {
1715cd417519SNick Kossifidis 		/* No spur info for 5GHz */
1716cd417519SNick Kossifidis 		ee->ee_spur_chans[0][0] = AR5K_EEPROM_NO_SPUR;
1717cd417519SNick Kossifidis 		/* 2 channels for 2GHz (2464/2420) */
1718cd417519SNick Kossifidis 		ee->ee_spur_chans[0][1] = AR5K_EEPROM_5413_SPUR_CHAN_1;
1719cd417519SNick Kossifidis 		ee->ee_spur_chans[1][1] = AR5K_EEPROM_5413_SPUR_CHAN_2;
1720cd417519SNick Kossifidis 		ee->ee_spur_chans[2][1] = AR5K_EEPROM_NO_SPUR;
1721cd417519SNick Kossifidis 	} else if (ee->ee_version >= AR5K_EEPROM_VERSION_5_3) {
1722cd417519SNick Kossifidis 		for (i = 0; i < AR5K_EEPROM_N_SPUR_CHANS; i++) {
1723cd417519SNick Kossifidis 			AR5K_EEPROM_READ(offset, val);
1724cd417519SNick Kossifidis 			ee->ee_spur_chans[i][0] = val;
1725cd417519SNick Kossifidis 			AR5K_EEPROM_READ(offset + AR5K_EEPROM_N_SPUR_CHANS,
1726cd417519SNick Kossifidis 									val);
1727cd417519SNick Kossifidis 			ee->ee_spur_chans[i][1] = val;
1728cd417519SNick Kossifidis 			offset++;
1729cd417519SNick Kossifidis 		}
1730cd417519SNick Kossifidis 	}
1731cd417519SNick Kossifidis 
1732cd417519SNick Kossifidis 	return ret;
1733cd417519SNick Kossifidis }
1734203c4805SLuis R. Rodriguez 
17359320b5c4SNick Kossifidis 
17369320b5c4SNick Kossifidis /***********************\
17379320b5c4SNick Kossifidis * Init/Detach functions *
17389320b5c4SNick Kossifidis \***********************/
17399320b5c4SNick Kossifidis 
17409320b5c4SNick Kossifidis /*
17419320b5c4SNick Kossifidis  * Initialize eeprom data structure
17429320b5c4SNick Kossifidis  */
17439320b5c4SNick Kossifidis int
17449320b5c4SNick Kossifidis ath5k_eeprom_init(struct ath5k_hw *ah)
17459320b5c4SNick Kossifidis {
17469320b5c4SNick Kossifidis 	int err;
17479320b5c4SNick Kossifidis 
17489320b5c4SNick Kossifidis 	err = ath5k_eeprom_init_header(ah);
17499320b5c4SNick Kossifidis 	if (err < 0)
17509320b5c4SNick Kossifidis 		return err;
17519320b5c4SNick Kossifidis 
17529320b5c4SNick Kossifidis 	err = ath5k_eeprom_init_modes(ah);
17539320b5c4SNick Kossifidis 	if (err < 0)
17549320b5c4SNick Kossifidis 		return err;
17559320b5c4SNick Kossifidis 
17569320b5c4SNick Kossifidis 	err = ath5k_eeprom_read_pcal_info(ah);
17579320b5c4SNick Kossifidis 	if (err < 0)
17589320b5c4SNick Kossifidis 		return err;
17599320b5c4SNick Kossifidis 
17609320b5c4SNick Kossifidis 	err = ath5k_eeprom_read_ctl_info(ah);
17619320b5c4SNick Kossifidis 	if (err < 0)
17629320b5c4SNick Kossifidis 		return err;
17639320b5c4SNick Kossifidis 
17649320b5c4SNick Kossifidis 	err = ath5k_eeprom_read_spur_chans(ah);
17659320b5c4SNick Kossifidis 	if (err < 0)
17669320b5c4SNick Kossifidis 		return err;
17679320b5c4SNick Kossifidis 
17689320b5c4SNick Kossifidis 	return 0;
17699320b5c4SNick Kossifidis }
17709320b5c4SNick Kossifidis 
17719320b5c4SNick Kossifidis void
17729320b5c4SNick Kossifidis ath5k_eeprom_detach(struct ath5k_hw *ah)
17739320b5c4SNick Kossifidis {
17749320b5c4SNick Kossifidis 	u8 mode;
17759320b5c4SNick Kossifidis 
17769320b5c4SNick Kossifidis 	for (mode = AR5K_EEPROM_MODE_11A; mode <= AR5K_EEPROM_MODE_11G; mode++)
17779320b5c4SNick Kossifidis 		ath5k_eeprom_free_pcal_info(ah, mode);
17789320b5c4SNick Kossifidis }
17790207c0c5SBruno Randolf 
17800207c0c5SBruno Randolf int
17810207c0c5SBruno Randolf ath5k_eeprom_mode_from_channel(struct ieee80211_channel *channel)
17820207c0c5SBruno Randolf {
17830207c0c5SBruno Randolf 	switch (channel->hw_value & CHANNEL_MODES) {
17840207c0c5SBruno Randolf 	case CHANNEL_A:
17850207c0c5SBruno Randolf 	case CHANNEL_XR:
17860207c0c5SBruno Randolf 		return AR5K_EEPROM_MODE_11A;
17870207c0c5SBruno Randolf 	case CHANNEL_G:
17880207c0c5SBruno Randolf 		return AR5K_EEPROM_MODE_11G;
17890207c0c5SBruno Randolf 	case CHANNEL_B:
17900207c0c5SBruno Randolf 		return AR5K_EEPROM_MODE_11B;
17910207c0c5SBruno Randolf 	default:
17920207c0c5SBruno Randolf 		return -1;
17930207c0c5SBruno Randolf 	}
17940207c0c5SBruno Randolf }
1795