xref: /linux/drivers/net/wireless/ath/ath5k/eeprom.c (revision fda9b7afa70f9003853929821748aec98d567b1e)
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;
194*fda9b7afSWojciech 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;
551*fda9b7afSWojciech 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
637203c4805SLuis R. Rodriguez  * older eeprom versions (< 3.2) these steps are equaly 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 {
647bbb33881STobias Klauser 	static const u16 intercepts3[] =
648203c4805SLuis R. Rodriguez 		{ 0, 5, 10, 20, 30, 50, 70, 85, 90, 95, 100 };
649bbb33881STobias Klauser 	static const u16 intercepts3_2[] =
650203c4805SLuis R. Rodriguez 		{ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
651203c4805SLuis R. Rodriguez 	const u16 *ip;
652203c4805SLuis R. Rodriguez 	int i;
653203c4805SLuis R. Rodriguez 
654203c4805SLuis R. Rodriguez 	if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_2)
655203c4805SLuis R. Rodriguez 		ip = intercepts3_2;
656203c4805SLuis R. Rodriguez 	else
657203c4805SLuis R. Rodriguez 		ip = intercepts3;
658203c4805SLuis R. Rodriguez 
659203c4805SLuis R. Rodriguez 	for (i = 0; i < ARRAY_SIZE(intercepts3); i++)
660203c4805SLuis R. Rodriguez 		vp[i] = (ip[i] * max + (100 - ip[i]) * min) / 100;
661203c4805SLuis R. Rodriguez }
662203c4805SLuis R. Rodriguez 
663203c4805SLuis R. Rodriguez /* Convert RF5111 specific data to generic raw data
664203c4805SLuis R. Rodriguez  * used by interpolation code */
665203c4805SLuis R. Rodriguez static int
666203c4805SLuis R. Rodriguez ath5k_eeprom_convert_pcal_info_5111(struct ath5k_hw *ah, int mode,
667203c4805SLuis R. Rodriguez 				struct ath5k_chan_pcal_info *chinfo)
668203c4805SLuis R. Rodriguez {
669203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
670203c4805SLuis R. Rodriguez 	struct ath5k_chan_pcal_info_rf5111 *pcinfo;
671203c4805SLuis R. Rodriguez 	struct ath5k_pdgain_info *pd;
672203c4805SLuis R. Rodriguez 	u8 pier, point, idx;
673203c4805SLuis R. Rodriguez 	u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
674203c4805SLuis R. Rodriguez 
675203c4805SLuis R. Rodriguez 	/* Fill raw data for each calibration pier */
676203c4805SLuis R. Rodriguez 	for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
677203c4805SLuis R. Rodriguez 
678203c4805SLuis R. Rodriguez 		pcinfo = &chinfo[pier].rf5111_info;
679203c4805SLuis R. Rodriguez 
680203c4805SLuis R. Rodriguez 		/* Allocate pd_curves for this cal pier */
681203c4805SLuis R. Rodriguez 		chinfo[pier].pd_curves =
682203c4805SLuis R. Rodriguez 			kcalloc(AR5K_EEPROM_N_PD_CURVES,
683203c4805SLuis R. Rodriguez 				sizeof(struct ath5k_pdgain_info),
684203c4805SLuis R. Rodriguez 				GFP_KERNEL);
685203c4805SLuis R. Rodriguez 
686203c4805SLuis R. Rodriguez 		if (!chinfo[pier].pd_curves)
687203c4805SLuis R. Rodriguez 			return -ENOMEM;
688203c4805SLuis R. Rodriguez 
689203c4805SLuis R. Rodriguez 		/* Only one curve for RF5111
690203c4805SLuis R. Rodriguez 		 * find out which one and place
69177c2061dSWalter Goldens 		 * in pd_curves.
692203c4805SLuis R. Rodriguez 		 * Note: ee_x_gain is reversed here */
693203c4805SLuis R. Rodriguez 		for (idx = 0; idx < AR5K_EEPROM_N_PD_CURVES; idx++) {
694203c4805SLuis R. Rodriguez 
695203c4805SLuis R. Rodriguez 			if (!((ee->ee_x_gain[mode] >> idx) & 0x1)) {
696203c4805SLuis R. Rodriguez 				pdgain_idx[0] = idx;
697203c4805SLuis R. Rodriguez 				break;
698203c4805SLuis R. Rodriguez 			}
699203c4805SLuis R. Rodriguez 		}
700203c4805SLuis R. Rodriguez 
701203c4805SLuis R. Rodriguez 		ee->ee_pd_gains[mode] = 1;
702203c4805SLuis R. Rodriguez 
703203c4805SLuis R. Rodriguez 		pd = &chinfo[pier].pd_curves[idx];
704203c4805SLuis R. Rodriguez 
705203c4805SLuis R. Rodriguez 		pd->pd_points = AR5K_EEPROM_N_PWR_POINTS_5111;
706203c4805SLuis R. Rodriguez 
707203c4805SLuis R. Rodriguez 		/* Allocate pd points for this curve */
708203c4805SLuis R. Rodriguez 		pd->pd_step = kcalloc(AR5K_EEPROM_N_PWR_POINTS_5111,
709203c4805SLuis R. Rodriguez 					sizeof(u8), GFP_KERNEL);
710203c4805SLuis R. Rodriguez 		if (!pd->pd_step)
711203c4805SLuis R. Rodriguez 			return -ENOMEM;
712203c4805SLuis R. Rodriguez 
713203c4805SLuis R. Rodriguez 		pd->pd_pwr = kcalloc(AR5K_EEPROM_N_PWR_POINTS_5111,
714203c4805SLuis R. Rodriguez 					sizeof(s16), GFP_KERNEL);
715203c4805SLuis R. Rodriguez 		if (!pd->pd_pwr)
716203c4805SLuis R. Rodriguez 			return -ENOMEM;
717203c4805SLuis R. Rodriguez 
718203c4805SLuis R. Rodriguez 		/* Fill raw dataset
719203c4805SLuis R. Rodriguez 		 * (convert power to 0.25dB units
720203c4805SLuis R. Rodriguez 		 * for RF5112 combatibility) */
721203c4805SLuis R. Rodriguez 		for (point = 0; point < pd->pd_points; point++) {
722203c4805SLuis R. Rodriguez 
723203c4805SLuis R. Rodriguez 			/* Absolute values */
724203c4805SLuis R. Rodriguez 			pd->pd_pwr[point] = 2 * pcinfo->pwr[point];
725203c4805SLuis R. Rodriguez 
726203c4805SLuis R. Rodriguez 			/* Already sorted */
727203c4805SLuis R. Rodriguez 			pd->pd_step[point] = pcinfo->pcdac[point];
728203c4805SLuis R. Rodriguez 		}
729203c4805SLuis R. Rodriguez 
730203c4805SLuis R. Rodriguez 		/* Set min/max pwr */
731203c4805SLuis R. Rodriguez 		chinfo[pier].min_pwr = pd->pd_pwr[0];
732203c4805SLuis R. Rodriguez 		chinfo[pier].max_pwr = pd->pd_pwr[10];
733203c4805SLuis R. Rodriguez 
734203c4805SLuis R. Rodriguez 	}
735203c4805SLuis R. Rodriguez 
736203c4805SLuis R. Rodriguez 	return 0;
737203c4805SLuis R. Rodriguez }
738203c4805SLuis R. Rodriguez 
739203c4805SLuis R. Rodriguez /* Parse EEPROM data */
740203c4805SLuis R. Rodriguez static int
741203c4805SLuis R. Rodriguez ath5k_eeprom_read_pcal_info_5111(struct ath5k_hw *ah, int mode)
742203c4805SLuis R. Rodriguez {
743203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
744203c4805SLuis R. Rodriguez 	struct ath5k_chan_pcal_info *pcal;
745203c4805SLuis R. Rodriguez 	int offset, ret;
746203c4805SLuis R. Rodriguez 	int i;
747203c4805SLuis R. Rodriguez 	u16 val;
748203c4805SLuis R. Rodriguez 
749203c4805SLuis R. Rodriguez 	offset = AR5K_EEPROM_GROUPS_START(ee->ee_version);
750203c4805SLuis R. Rodriguez 	switch(mode) {
751203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11A:
752203c4805SLuis R. Rodriguez 		if (!AR5K_EEPROM_HDR_11A(ee->ee_header))
753203c4805SLuis R. Rodriguez 			return 0;
754203c4805SLuis R. Rodriguez 
755203c4805SLuis R. Rodriguez 		ret = ath5k_eeprom_init_11a_pcal_freq(ah,
756203c4805SLuis R. Rodriguez 			offset + AR5K_EEPROM_GROUP1_OFFSET);
757203c4805SLuis R. Rodriguez 		if (ret < 0)
758203c4805SLuis R. Rodriguez 			return ret;
759203c4805SLuis R. Rodriguez 
760203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_GROUP2_OFFSET;
761203c4805SLuis R. Rodriguez 		pcal = ee->ee_pwr_cal_a;
762203c4805SLuis R. Rodriguez 		break;
763203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11B:
764203c4805SLuis R. Rodriguez 		if (!AR5K_EEPROM_HDR_11B(ee->ee_header) &&
765203c4805SLuis R. Rodriguez 		    !AR5K_EEPROM_HDR_11G(ee->ee_header))
766203c4805SLuis R. Rodriguez 			return 0;
767203c4805SLuis R. Rodriguez 
768203c4805SLuis R. Rodriguez 		pcal = ee->ee_pwr_cal_b;
769203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_GROUP3_OFFSET;
770203c4805SLuis R. Rodriguez 
771203c4805SLuis R. Rodriguez 		/* fixed piers */
772203c4805SLuis R. Rodriguez 		pcal[0].freq = 2412;
773203c4805SLuis R. Rodriguez 		pcal[1].freq = 2447;
774203c4805SLuis R. Rodriguez 		pcal[2].freq = 2484;
775203c4805SLuis R. Rodriguez 		ee->ee_n_piers[mode] = 3;
776203c4805SLuis R. Rodriguez 		break;
777203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11G:
778203c4805SLuis R. Rodriguez 		if (!AR5K_EEPROM_HDR_11G(ee->ee_header))
779203c4805SLuis R. Rodriguez 			return 0;
780203c4805SLuis R. Rodriguez 
781203c4805SLuis R. Rodriguez 		pcal = ee->ee_pwr_cal_g;
782203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_GROUP4_OFFSET;
783203c4805SLuis R. Rodriguez 
784203c4805SLuis R. Rodriguez 		/* fixed piers */
785203c4805SLuis R. Rodriguez 		pcal[0].freq = 2312;
786203c4805SLuis R. Rodriguez 		pcal[1].freq = 2412;
787203c4805SLuis R. Rodriguez 		pcal[2].freq = 2484;
788203c4805SLuis R. Rodriguez 		ee->ee_n_piers[mode] = 3;
789203c4805SLuis R. Rodriguez 		break;
790203c4805SLuis R. Rodriguez 	default:
791203c4805SLuis R. Rodriguez 		return -EINVAL;
792203c4805SLuis R. Rodriguez 	}
793203c4805SLuis R. Rodriguez 
794203c4805SLuis R. Rodriguez 	for (i = 0; i < ee->ee_n_piers[mode]; i++) {
795203c4805SLuis R. Rodriguez 		struct ath5k_chan_pcal_info_rf5111 *cdata =
796203c4805SLuis R. Rodriguez 			&pcal[i].rf5111_info;
797203c4805SLuis R. Rodriguez 
798203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
799203c4805SLuis R. Rodriguez 		cdata->pcdac_max = ((val >> 10) & AR5K_EEPROM_PCDAC_M);
800203c4805SLuis R. Rodriguez 		cdata->pcdac_min = ((val >> 4) & AR5K_EEPROM_PCDAC_M);
801203c4805SLuis R. Rodriguez 		cdata->pwr[0] = ((val << 2) & AR5K_EEPROM_POWER_M);
802203c4805SLuis R. Rodriguez 
803203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
804203c4805SLuis R. Rodriguez 		cdata->pwr[0] |= ((val >> 14) & 0x3);
805203c4805SLuis R. Rodriguez 		cdata->pwr[1] = ((val >> 8) & AR5K_EEPROM_POWER_M);
806203c4805SLuis R. Rodriguez 		cdata->pwr[2] = ((val >> 2) & AR5K_EEPROM_POWER_M);
807203c4805SLuis R. Rodriguez 		cdata->pwr[3] = ((val << 4) & AR5K_EEPROM_POWER_M);
808203c4805SLuis R. Rodriguez 
809203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
810203c4805SLuis R. Rodriguez 		cdata->pwr[3] |= ((val >> 12) & 0xf);
811203c4805SLuis R. Rodriguez 		cdata->pwr[4] = ((val >> 6) & AR5K_EEPROM_POWER_M);
812203c4805SLuis R. Rodriguez 		cdata->pwr[5] = (val  & AR5K_EEPROM_POWER_M);
813203c4805SLuis R. Rodriguez 
814203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
815203c4805SLuis R. Rodriguez 		cdata->pwr[6] = ((val >> 10) & AR5K_EEPROM_POWER_M);
816203c4805SLuis R. Rodriguez 		cdata->pwr[7] = ((val >> 4) & AR5K_EEPROM_POWER_M);
817203c4805SLuis R. Rodriguez 		cdata->pwr[8] = ((val << 2) & AR5K_EEPROM_POWER_M);
818203c4805SLuis R. Rodriguez 
819203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
820203c4805SLuis R. Rodriguez 		cdata->pwr[8] |= ((val >> 14) & 0x3);
821203c4805SLuis R. Rodriguez 		cdata->pwr[9] = ((val >> 8) & AR5K_EEPROM_POWER_M);
822203c4805SLuis R. Rodriguez 		cdata->pwr[10] = ((val >> 2) & AR5K_EEPROM_POWER_M);
823203c4805SLuis R. Rodriguez 
824203c4805SLuis R. Rodriguez 		ath5k_get_pcdac_intercepts(ah, cdata->pcdac_min,
825203c4805SLuis R. Rodriguez 			cdata->pcdac_max, cdata->pcdac);
826203c4805SLuis R. Rodriguez 	}
827203c4805SLuis R. Rodriguez 
828203c4805SLuis R. Rodriguez 	return ath5k_eeprom_convert_pcal_info_5111(ah, mode, pcal);
829203c4805SLuis R. Rodriguez }
830203c4805SLuis R. Rodriguez 
831203c4805SLuis R. Rodriguez 
832203c4805SLuis R. Rodriguez /*
833203c4805SLuis R. Rodriguez  * Read power calibration for RF5112 chips
834203c4805SLuis R. Rodriguez  *
835203c4805SLuis R. Rodriguez  * For RF5112 we have 4 XPD -eXternal Power Detector- curves
836203c4805SLuis R. Rodriguez  * for each calibrated channel on 0, -6, -12 and -18dbm but we only
837203c4805SLuis R. Rodriguez  * use the higher (3) and the lower (0) curves. Each curve has 0.5dB
838203c4805SLuis R. Rodriguez  * power steps on x axis and PCDAC steps on y axis and looks like a
839203c4805SLuis R. Rodriguez  * linear function. To recreate the curve and pass the power values
840203c4805SLuis R. Rodriguez  * on hw, we read 4 points for xpd 0 (lower gain -> max power)
841203c4805SLuis R. Rodriguez  * and 3 points for xpd 3 (higher gain -> lower power) here and
842203c4805SLuis R. Rodriguez  * interpolate later.
843203c4805SLuis R. Rodriguez  *
844203c4805SLuis R. Rodriguez  * Note: Many vendors just use xpd 0 so xpd 3 is zeroed.
845203c4805SLuis R. Rodriguez  */
846203c4805SLuis R. Rodriguez 
847203c4805SLuis R. Rodriguez /* Convert RF5112 specific data to generic raw data
848203c4805SLuis R. Rodriguez  * used by interpolation code */
849203c4805SLuis R. Rodriguez static int
850203c4805SLuis R. Rodriguez ath5k_eeprom_convert_pcal_info_5112(struct ath5k_hw *ah, int mode,
851203c4805SLuis R. Rodriguez 				struct ath5k_chan_pcal_info *chinfo)
852203c4805SLuis R. Rodriguez {
853203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
854203c4805SLuis R. Rodriguez 	struct ath5k_chan_pcal_info_rf5112 *pcinfo;
855203c4805SLuis R. Rodriguez 	u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
856203c4805SLuis R. Rodriguez 	unsigned int pier, pdg, point;
857203c4805SLuis R. Rodriguez 
858203c4805SLuis R. Rodriguez 	/* Fill raw data for each calibration pier */
859203c4805SLuis R. Rodriguez 	for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
860203c4805SLuis R. Rodriguez 
861203c4805SLuis R. Rodriguez 		pcinfo = &chinfo[pier].rf5112_info;
862203c4805SLuis R. Rodriguez 
863203c4805SLuis R. Rodriguez 		/* Allocate pd_curves for this cal pier */
864203c4805SLuis R. Rodriguez 		chinfo[pier].pd_curves =
865203c4805SLuis R. Rodriguez 				kcalloc(AR5K_EEPROM_N_PD_CURVES,
866203c4805SLuis R. Rodriguez 					sizeof(struct ath5k_pdgain_info),
867203c4805SLuis R. Rodriguez 					GFP_KERNEL);
868203c4805SLuis R. Rodriguez 
869203c4805SLuis R. Rodriguez 		if (!chinfo[pier].pd_curves)
870203c4805SLuis R. Rodriguez 			return -ENOMEM;
871203c4805SLuis R. Rodriguez 
872203c4805SLuis R. Rodriguez 		/* Fill pd_curves */
873203c4805SLuis R. Rodriguez 		for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) {
874203c4805SLuis R. Rodriguez 
875203c4805SLuis R. Rodriguez 			u8 idx = pdgain_idx[pdg];
876203c4805SLuis R. Rodriguez 			struct ath5k_pdgain_info *pd =
877203c4805SLuis R. Rodriguez 					&chinfo[pier].pd_curves[idx];
878203c4805SLuis R. Rodriguez 
879203c4805SLuis R. Rodriguez 			/* Lowest gain curve (max power) */
880203c4805SLuis R. Rodriguez 			if (pdg == 0) {
881203c4805SLuis R. Rodriguez 				/* One more point for better accuracy */
882203c4805SLuis R. Rodriguez 				pd->pd_points = AR5K_EEPROM_N_XPD0_POINTS;
883203c4805SLuis R. Rodriguez 
884203c4805SLuis R. Rodriguez 				/* Allocate pd points for this curve */
885203c4805SLuis R. Rodriguez 				pd->pd_step = kcalloc(pd->pd_points,
886203c4805SLuis R. Rodriguez 						sizeof(u8), GFP_KERNEL);
887203c4805SLuis R. Rodriguez 
888203c4805SLuis R. Rodriguez 				if (!pd->pd_step)
889203c4805SLuis R. Rodriguez 					return -ENOMEM;
890203c4805SLuis R. Rodriguez 
891203c4805SLuis R. Rodriguez 				pd->pd_pwr = kcalloc(pd->pd_points,
892203c4805SLuis R. Rodriguez 						sizeof(s16), GFP_KERNEL);
893203c4805SLuis R. Rodriguez 
894203c4805SLuis R. Rodriguez 				if (!pd->pd_pwr)
895203c4805SLuis R. Rodriguez 					return -ENOMEM;
896203c4805SLuis R. Rodriguez 
897203c4805SLuis R. Rodriguez 
898203c4805SLuis R. Rodriguez 				/* Fill raw dataset
899203c4805SLuis R. Rodriguez 				 * (all power levels are in 0.25dB units) */
900203c4805SLuis R. Rodriguez 				pd->pd_step[0] = pcinfo->pcdac_x0[0];
901203c4805SLuis R. Rodriguez 				pd->pd_pwr[0] = pcinfo->pwr_x0[0];
902203c4805SLuis R. Rodriguez 
903203c4805SLuis R. Rodriguez 				for (point = 1; point < pd->pd_points;
904203c4805SLuis R. Rodriguez 				point++) {
905203c4805SLuis R. Rodriguez 					/* Absolute values */
906203c4805SLuis R. Rodriguez 					pd->pd_pwr[point] =
907203c4805SLuis R. Rodriguez 						pcinfo->pwr_x0[point];
908203c4805SLuis R. Rodriguez 
909203c4805SLuis R. Rodriguez 					/* Deltas */
910203c4805SLuis R. Rodriguez 					pd->pd_step[point] =
911203c4805SLuis R. Rodriguez 						pd->pd_step[point - 1] +
912203c4805SLuis R. Rodriguez 						pcinfo->pcdac_x0[point];
913203c4805SLuis R. Rodriguez 				}
914203c4805SLuis R. Rodriguez 
915203c4805SLuis R. Rodriguez 				/* Set min power for this frequency */
916203c4805SLuis R. Rodriguez 				chinfo[pier].min_pwr = pd->pd_pwr[0];
917203c4805SLuis R. Rodriguez 
918203c4805SLuis R. Rodriguez 			/* Highest gain curve (min power) */
919203c4805SLuis R. Rodriguez 			} else if (pdg == 1) {
920203c4805SLuis R. Rodriguez 
921203c4805SLuis R. Rodriguez 				pd->pd_points = AR5K_EEPROM_N_XPD3_POINTS;
922203c4805SLuis R. Rodriguez 
923203c4805SLuis R. Rodriguez 				/* Allocate pd points for this curve */
924203c4805SLuis R. Rodriguez 				pd->pd_step = kcalloc(pd->pd_points,
925203c4805SLuis R. Rodriguez 						sizeof(u8), GFP_KERNEL);
926203c4805SLuis R. Rodriguez 
927203c4805SLuis R. Rodriguez 				if (!pd->pd_step)
928203c4805SLuis R. Rodriguez 					return -ENOMEM;
929203c4805SLuis R. Rodriguez 
930203c4805SLuis R. Rodriguez 				pd->pd_pwr = kcalloc(pd->pd_points,
931203c4805SLuis R. Rodriguez 						sizeof(s16), GFP_KERNEL);
932203c4805SLuis R. Rodriguez 
933203c4805SLuis R. Rodriguez 				if (!pd->pd_pwr)
934203c4805SLuis R. Rodriguez 					return -ENOMEM;
935203c4805SLuis R. Rodriguez 
936203c4805SLuis R. Rodriguez 				/* Fill raw dataset
937203c4805SLuis R. Rodriguez 				 * (all power levels are in 0.25dB units) */
938203c4805SLuis R. Rodriguez 				for (point = 0; point < pd->pd_points;
939203c4805SLuis R. Rodriguez 				point++) {
940203c4805SLuis R. Rodriguez 					/* Absolute values */
941203c4805SLuis R. Rodriguez 					pd->pd_pwr[point] =
942203c4805SLuis R. Rodriguez 						pcinfo->pwr_x3[point];
943203c4805SLuis R. Rodriguez 
944203c4805SLuis R. Rodriguez 					/* Fixed points */
945203c4805SLuis R. Rodriguez 					pd->pd_step[point] =
946203c4805SLuis R. Rodriguez 						pcinfo->pcdac_x3[point];
947203c4805SLuis R. Rodriguez 				}
948203c4805SLuis R. Rodriguez 
949203c4805SLuis R. Rodriguez 				/* Since we have a higher gain curve
950203c4805SLuis R. Rodriguez 				 * override min power */
951203c4805SLuis R. Rodriguez 				chinfo[pier].min_pwr = pd->pd_pwr[0];
952203c4805SLuis R. Rodriguez 			}
953203c4805SLuis R. Rodriguez 		}
954203c4805SLuis R. Rodriguez 	}
955203c4805SLuis R. Rodriguez 
956203c4805SLuis R. Rodriguez 	return 0;
957203c4805SLuis R. Rodriguez }
958203c4805SLuis R. Rodriguez 
959203c4805SLuis R. Rodriguez /* Parse EEPROM data */
960203c4805SLuis R. Rodriguez static int
961203c4805SLuis R. Rodriguez ath5k_eeprom_read_pcal_info_5112(struct ath5k_hw *ah, int mode)
962203c4805SLuis R. Rodriguez {
963203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
964203c4805SLuis R. Rodriguez 	struct ath5k_chan_pcal_info_rf5112 *chan_pcal_info;
965203c4805SLuis R. Rodriguez 	struct ath5k_chan_pcal_info *gen_chan_info;
966203c4805SLuis R. Rodriguez 	u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
967203c4805SLuis R. Rodriguez 	u32 offset;
968203c4805SLuis R. Rodriguez 	u8 i, c;
969203c4805SLuis R. Rodriguez 	u16 val;
970203c4805SLuis R. Rodriguez 	u8 pd_gains = 0;
971203c4805SLuis R. Rodriguez 
972203c4805SLuis R. Rodriguez 	/* Count how many curves we have and
973203c4805SLuis R. Rodriguez 	 * identify them (which one of the 4
974203c4805SLuis R. Rodriguez 	 * available curves we have on each count).
975203c4805SLuis R. Rodriguez 	 * Curves are stored from lower (x0) to
976203c4805SLuis R. Rodriguez 	 * higher (x3) gain */
977203c4805SLuis R. Rodriguez 	for (i = 0; i < AR5K_EEPROM_N_PD_CURVES; i++) {
978203c4805SLuis R. Rodriguez 		/* ee_x_gain[mode] is x gain mask */
979203c4805SLuis R. Rodriguez 		if ((ee->ee_x_gain[mode] >> i) & 0x1)
980203c4805SLuis R. Rodriguez 			pdgain_idx[pd_gains++] = i;
981203c4805SLuis R. Rodriguez 	}
982203c4805SLuis R. Rodriguez 	ee->ee_pd_gains[mode] = pd_gains;
983203c4805SLuis R. Rodriguez 
984203c4805SLuis R. Rodriguez 	if (pd_gains == 0 || pd_gains > 2)
985203c4805SLuis R. Rodriguez 		return -EINVAL;
986203c4805SLuis R. Rodriguez 
987203c4805SLuis R. Rodriguez 	switch (mode) {
988203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11A:
989203c4805SLuis R. Rodriguez 		/*
990203c4805SLuis R. Rodriguez 		 * Read 5GHz EEPROM channels
991203c4805SLuis R. Rodriguez 		 */
992203c4805SLuis R. Rodriguez 		offset = AR5K_EEPROM_GROUPS_START(ee->ee_version);
993203c4805SLuis R. Rodriguez 		ath5k_eeprom_init_11a_pcal_freq(ah, offset);
994203c4805SLuis R. Rodriguez 
995203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_GROUP2_OFFSET;
996203c4805SLuis R. Rodriguez 		gen_chan_info = ee->ee_pwr_cal_a;
997203c4805SLuis R. Rodriguez 		break;
998203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11B:
999203c4805SLuis R. Rodriguez 		offset = AR5K_EEPROM_GROUPS_START(ee->ee_version);
1000203c4805SLuis R. Rodriguez 		if (AR5K_EEPROM_HDR_11A(ee->ee_header))
1001203c4805SLuis R. Rodriguez 			offset += AR5K_EEPROM_GROUP3_OFFSET;
1002203c4805SLuis R. Rodriguez 
1003203c4805SLuis R. Rodriguez 		/* NB: frequency piers parsed during mode init */
1004203c4805SLuis R. Rodriguez 		gen_chan_info = ee->ee_pwr_cal_b;
1005203c4805SLuis R. Rodriguez 		break;
1006203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11G:
1007203c4805SLuis R. Rodriguez 		offset = AR5K_EEPROM_GROUPS_START(ee->ee_version);
1008203c4805SLuis R. Rodriguez 		if (AR5K_EEPROM_HDR_11A(ee->ee_header))
1009203c4805SLuis R. Rodriguez 			offset += AR5K_EEPROM_GROUP4_OFFSET;
1010203c4805SLuis R. Rodriguez 		else if (AR5K_EEPROM_HDR_11B(ee->ee_header))
1011203c4805SLuis R. Rodriguez 			offset += AR5K_EEPROM_GROUP2_OFFSET;
1012203c4805SLuis R. Rodriguez 
1013203c4805SLuis R. Rodriguez 		/* NB: frequency piers parsed during mode init */
1014203c4805SLuis R. Rodriguez 		gen_chan_info = ee->ee_pwr_cal_g;
1015203c4805SLuis R. Rodriguez 		break;
1016203c4805SLuis R. Rodriguez 	default:
1017203c4805SLuis R. Rodriguez 		return -EINVAL;
1018203c4805SLuis R. Rodriguez 	}
1019203c4805SLuis R. Rodriguez 
1020203c4805SLuis R. Rodriguez 	for (i = 0; i < ee->ee_n_piers[mode]; i++) {
1021203c4805SLuis R. Rodriguez 		chan_pcal_info = &gen_chan_info[i].rf5112_info;
1022203c4805SLuis R. Rodriguez 
1023203c4805SLuis R. Rodriguez 		/* Power values in quarter dB
1024203c4805SLuis R. Rodriguez 		 * for the lower xpd gain curve
1025203c4805SLuis R. Rodriguez 		 * (0 dBm -> higher output power) */
1026203c4805SLuis R. Rodriguez 		for (c = 0; c < AR5K_EEPROM_N_XPD0_POINTS; c++) {
1027203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1028203c4805SLuis R. Rodriguez 			chan_pcal_info->pwr_x0[c] = (s8) (val & 0xff);
1029203c4805SLuis R. Rodriguez 			chan_pcal_info->pwr_x0[++c] = (s8) ((val >> 8) & 0xff);
1030203c4805SLuis R. Rodriguez 		}
1031203c4805SLuis R. Rodriguez 
1032203c4805SLuis R. Rodriguez 		/* PCDAC steps
1033203c4805SLuis R. Rodriguez 		 * corresponding to the above power
1034203c4805SLuis R. Rodriguez 		 * measurements */
1035203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
1036203c4805SLuis R. Rodriguez 		chan_pcal_info->pcdac_x0[1] = (val & 0x1f);
1037203c4805SLuis R. Rodriguez 		chan_pcal_info->pcdac_x0[2] = ((val >> 5) & 0x1f);
1038203c4805SLuis R. Rodriguez 		chan_pcal_info->pcdac_x0[3] = ((val >> 10) & 0x1f);
1039203c4805SLuis R. Rodriguez 
1040203c4805SLuis R. Rodriguez 		/* Power values in quarter dB
1041203c4805SLuis R. Rodriguez 		 * for the higher xpd gain curve
1042203c4805SLuis R. Rodriguez 		 * (18 dBm -> lower output power) */
1043203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
1044203c4805SLuis R. Rodriguez 		chan_pcal_info->pwr_x3[0] = (s8) (val & 0xff);
1045203c4805SLuis R. Rodriguez 		chan_pcal_info->pwr_x3[1] = (s8) ((val >> 8) & 0xff);
1046203c4805SLuis R. Rodriguez 
1047203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
1048203c4805SLuis R. Rodriguez 		chan_pcal_info->pwr_x3[2] = (val & 0xff);
1049203c4805SLuis R. Rodriguez 
1050203c4805SLuis R. Rodriguez 		/* PCDAC steps
1051203c4805SLuis R. Rodriguez 		 * corresponding to the above power
1052203c4805SLuis R. Rodriguez 		 * measurements (fixed) */
1053203c4805SLuis R. Rodriguez 		chan_pcal_info->pcdac_x3[0] = 20;
1054203c4805SLuis R. Rodriguez 		chan_pcal_info->pcdac_x3[1] = 35;
1055203c4805SLuis R. Rodriguez 		chan_pcal_info->pcdac_x3[2] = 63;
1056203c4805SLuis R. Rodriguez 
1057203c4805SLuis R. Rodriguez 		if (ee->ee_version >= AR5K_EEPROM_VERSION_4_3) {
1058203c4805SLuis R. Rodriguez 			chan_pcal_info->pcdac_x0[0] = ((val >> 8) & 0x3f);
1059203c4805SLuis R. Rodriguez 
1060203c4805SLuis R. Rodriguez 			/* Last xpd0 power level is also channel maximum */
1061203c4805SLuis R. Rodriguez 			gen_chan_info[i].max_pwr = chan_pcal_info->pwr_x0[3];
1062203c4805SLuis R. Rodriguez 		} else {
1063203c4805SLuis R. Rodriguez 			chan_pcal_info->pcdac_x0[0] = 1;
1064203c4805SLuis R. Rodriguez 			gen_chan_info[i].max_pwr = (s8) ((val >> 8) & 0xff);
1065203c4805SLuis R. Rodriguez 		}
1066203c4805SLuis R. Rodriguez 
1067203c4805SLuis R. Rodriguez 	}
1068203c4805SLuis R. Rodriguez 
1069203c4805SLuis R. Rodriguez 	return ath5k_eeprom_convert_pcal_info_5112(ah, mode, gen_chan_info);
1070203c4805SLuis R. Rodriguez }
1071203c4805SLuis R. Rodriguez 
1072203c4805SLuis R. Rodriguez 
1073203c4805SLuis R. Rodriguez /*
1074203c4805SLuis R. Rodriguez  * Read power calibration for RF2413 chips
1075203c4805SLuis R. Rodriguez  *
1076203c4805SLuis R. Rodriguez  * For RF2413 we have a Power to PDDAC table (Power Detector)
1077203c4805SLuis R. Rodriguez  * instead of a PCDAC and 4 pd gain curves for each calibrated channel.
1078203c4805SLuis R. Rodriguez  * Each curve has power on x axis in 0.5 db steps and PDDADC steps on y
1079203c4805SLuis R. Rodriguez  * axis and looks like an exponential function like the RF5111 curve.
1080203c4805SLuis R. Rodriguez  *
1081203c4805SLuis R. Rodriguez  * To recreate the curves we read here the points and interpolate
1082203c4805SLuis R. Rodriguez  * later. Note that in most cases only 2 (higher and lower) curves are
1083203c4805SLuis R. Rodriguez  * used (like RF5112) but vendors have the oportunity to include all
1084203c4805SLuis R. Rodriguez  * 4 curves on eeprom. The final curve (higher power) has an extra
1085203c4805SLuis R. Rodriguez  * point for better accuracy like RF5112.
1086203c4805SLuis R. Rodriguez  */
1087203c4805SLuis R. Rodriguez 
1088203c4805SLuis R. Rodriguez /* For RF2413 power calibration data doesn't start on a fixed location and
1089a180a130SBob Copeland  * if a mode is not supported, its section is missing -not zeroed-.
1090203c4805SLuis R. Rodriguez  * So we need to calculate the starting offset for each section by using
1091203c4805SLuis R. Rodriguez  * these two functions */
1092203c4805SLuis R. Rodriguez 
1093203c4805SLuis R. Rodriguez /* Return the size of each section based on the mode and the number of pd
1094203c4805SLuis R. Rodriguez  * gains available (maximum 4). */
1095203c4805SLuis R. Rodriguez static inline unsigned int
1096203c4805SLuis R. Rodriguez ath5k_pdgains_size_2413(struct ath5k_eeprom_info *ee, unsigned int mode)
1097203c4805SLuis R. Rodriguez {
1098203c4805SLuis R. Rodriguez 	static const unsigned int pdgains_size[] = { 4, 6, 9, 12 };
1099203c4805SLuis R. Rodriguez 	unsigned int sz;
1100203c4805SLuis R. Rodriguez 
1101203c4805SLuis R. Rodriguez 	sz = pdgains_size[ee->ee_pd_gains[mode] - 1];
1102203c4805SLuis R. Rodriguez 	sz *= ee->ee_n_piers[mode];
1103203c4805SLuis R. Rodriguez 
1104203c4805SLuis R. Rodriguez 	return sz;
1105203c4805SLuis R. Rodriguez }
1106203c4805SLuis R. Rodriguez 
1107203c4805SLuis R. Rodriguez /* Return the starting offset for a section based on the modes supported
1108203c4805SLuis R. Rodriguez  * and each section's size. */
1109203c4805SLuis R. Rodriguez static unsigned int
1110203c4805SLuis R. Rodriguez ath5k_cal_data_offset_2413(struct ath5k_eeprom_info *ee, int mode)
1111203c4805SLuis R. Rodriguez {
1112203c4805SLuis R. Rodriguez 	u32 offset = AR5K_EEPROM_CAL_DATA_START(ee->ee_misc4);
1113203c4805SLuis R. Rodriguez 
1114203c4805SLuis R. Rodriguez 	switch(mode) {
1115203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11G:
1116203c4805SLuis R. Rodriguez 		if (AR5K_EEPROM_HDR_11B(ee->ee_header))
1117203c4805SLuis R. Rodriguez 			offset += ath5k_pdgains_size_2413(ee,
1118203c4805SLuis R. Rodriguez 					AR5K_EEPROM_MODE_11B) +
1119203c4805SLuis R. Rodriguez 					AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2;
1120203c4805SLuis R. Rodriguez 		/* fall through */
1121203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11B:
1122203c4805SLuis R. Rodriguez 		if (AR5K_EEPROM_HDR_11A(ee->ee_header))
1123203c4805SLuis R. Rodriguez 			offset += ath5k_pdgains_size_2413(ee,
1124203c4805SLuis R. Rodriguez 					AR5K_EEPROM_MODE_11A) +
1125203c4805SLuis R. Rodriguez 					AR5K_EEPROM_N_5GHZ_CHAN / 2;
1126203c4805SLuis R. Rodriguez 		/* fall through */
1127203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11A:
1128203c4805SLuis R. Rodriguez 		break;
1129203c4805SLuis R. Rodriguez 	default:
1130203c4805SLuis R. Rodriguez 		break;
1131203c4805SLuis R. Rodriguez 	}
1132203c4805SLuis R. Rodriguez 
1133203c4805SLuis R. Rodriguez 	return offset;
1134203c4805SLuis R. Rodriguez }
1135203c4805SLuis R. Rodriguez 
1136203c4805SLuis R. Rodriguez /* Convert RF2413 specific data to generic raw data
1137203c4805SLuis R. Rodriguez  * used by interpolation code */
1138203c4805SLuis R. Rodriguez static int
1139203c4805SLuis R. Rodriguez ath5k_eeprom_convert_pcal_info_2413(struct ath5k_hw *ah, int mode,
1140203c4805SLuis R. Rodriguez 				struct ath5k_chan_pcal_info *chinfo)
1141203c4805SLuis R. Rodriguez {
1142203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1143203c4805SLuis R. Rodriguez 	struct ath5k_chan_pcal_info_rf2413 *pcinfo;
1144203c4805SLuis R. Rodriguez 	u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
1145203c4805SLuis R. Rodriguez 	unsigned int pier, pdg, point;
1146203c4805SLuis R. Rodriguez 
1147203c4805SLuis R. Rodriguez 	/* Fill raw data for each calibration pier */
1148203c4805SLuis R. Rodriguez 	for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
1149203c4805SLuis R. Rodriguez 
1150203c4805SLuis R. Rodriguez 		pcinfo = &chinfo[pier].rf2413_info;
1151203c4805SLuis R. Rodriguez 
1152203c4805SLuis R. Rodriguez 		/* Allocate pd_curves for this cal pier */
1153203c4805SLuis R. Rodriguez 		chinfo[pier].pd_curves =
1154203c4805SLuis R. Rodriguez 				kcalloc(AR5K_EEPROM_N_PD_CURVES,
1155203c4805SLuis R. Rodriguez 					sizeof(struct ath5k_pdgain_info),
1156203c4805SLuis R. Rodriguez 					GFP_KERNEL);
1157203c4805SLuis R. Rodriguez 
1158203c4805SLuis R. Rodriguez 		if (!chinfo[pier].pd_curves)
1159203c4805SLuis R. Rodriguez 			return -ENOMEM;
1160203c4805SLuis R. Rodriguez 
1161203c4805SLuis R. Rodriguez 		/* Fill pd_curves */
1162203c4805SLuis R. Rodriguez 		for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) {
1163203c4805SLuis R. Rodriguez 
1164203c4805SLuis R. Rodriguez 			u8 idx = pdgain_idx[pdg];
1165203c4805SLuis R. Rodriguez 			struct ath5k_pdgain_info *pd =
1166203c4805SLuis R. Rodriguez 					&chinfo[pier].pd_curves[idx];
1167203c4805SLuis R. Rodriguez 
1168203c4805SLuis R. Rodriguez 			/* One more point for the highest power
1169203c4805SLuis R. Rodriguez 			 * curve (lowest gain) */
1170203c4805SLuis R. Rodriguez 			if (pdg == ee->ee_pd_gains[mode] - 1)
1171203c4805SLuis R. Rodriguez 				pd->pd_points = AR5K_EEPROM_N_PD_POINTS;
1172203c4805SLuis R. Rodriguez 			else
1173203c4805SLuis R. Rodriguez 				pd->pd_points = AR5K_EEPROM_N_PD_POINTS - 1;
1174203c4805SLuis R. Rodriguez 
1175203c4805SLuis R. Rodriguez 			/* Allocate pd points for this curve */
1176203c4805SLuis R. Rodriguez 			pd->pd_step = kcalloc(pd->pd_points,
1177203c4805SLuis R. Rodriguez 					sizeof(u8), GFP_KERNEL);
1178203c4805SLuis R. Rodriguez 
1179203c4805SLuis R. Rodriguez 			if (!pd->pd_step)
1180203c4805SLuis R. Rodriguez 				return -ENOMEM;
1181203c4805SLuis R. Rodriguez 
1182203c4805SLuis R. Rodriguez 			pd->pd_pwr = kcalloc(pd->pd_points,
1183203c4805SLuis R. Rodriguez 					sizeof(s16), GFP_KERNEL);
1184203c4805SLuis R. Rodriguez 
1185203c4805SLuis R. Rodriguez 			if (!pd->pd_pwr)
1186203c4805SLuis R. Rodriguez 				return -ENOMEM;
1187203c4805SLuis R. Rodriguez 
1188203c4805SLuis R. Rodriguez 			/* Fill raw dataset
1189203c4805SLuis R. Rodriguez 			 * convert all pwr levels to
1190203c4805SLuis R. Rodriguez 			 * quarter dB for RF5112 combatibility */
1191203c4805SLuis R. Rodriguez 			pd->pd_step[0] = pcinfo->pddac_i[pdg];
1192203c4805SLuis R. Rodriguez 			pd->pd_pwr[0] = 4 * pcinfo->pwr_i[pdg];
1193203c4805SLuis R. Rodriguez 
1194203c4805SLuis R. Rodriguez 			for (point = 1; point < pd->pd_points; point++) {
1195203c4805SLuis R. Rodriguez 
1196203c4805SLuis R. Rodriguez 				pd->pd_pwr[point] = pd->pd_pwr[point - 1] +
1197203c4805SLuis R. Rodriguez 					2 * pcinfo->pwr[pdg][point - 1];
1198203c4805SLuis R. Rodriguez 
1199203c4805SLuis R. Rodriguez 				pd->pd_step[point] = pd->pd_step[point - 1] +
1200203c4805SLuis R. Rodriguez 						pcinfo->pddac[pdg][point - 1];
1201203c4805SLuis R. Rodriguez 
1202203c4805SLuis R. Rodriguez 			}
1203203c4805SLuis R. Rodriguez 
1204203c4805SLuis R. Rodriguez 			/* Highest gain curve -> min power */
1205203c4805SLuis R. Rodriguez 			if (pdg == 0)
1206203c4805SLuis R. Rodriguez 				chinfo[pier].min_pwr = pd->pd_pwr[0];
1207203c4805SLuis R. Rodriguez 
1208203c4805SLuis R. Rodriguez 			/* Lowest gain curve -> max power */
1209203c4805SLuis R. Rodriguez 			if (pdg == ee->ee_pd_gains[mode] - 1)
1210203c4805SLuis R. Rodriguez 				chinfo[pier].max_pwr =
1211203c4805SLuis R. Rodriguez 					pd->pd_pwr[pd->pd_points - 1];
1212203c4805SLuis R. Rodriguez 		}
1213203c4805SLuis R. Rodriguez 	}
1214203c4805SLuis R. Rodriguez 
1215203c4805SLuis R. Rodriguez 	return 0;
1216203c4805SLuis R. Rodriguez }
1217203c4805SLuis R. Rodriguez 
1218203c4805SLuis R. Rodriguez /* Parse EEPROM data */
1219203c4805SLuis R. Rodriguez static int
1220203c4805SLuis R. Rodriguez ath5k_eeprom_read_pcal_info_2413(struct ath5k_hw *ah, int mode)
1221203c4805SLuis R. Rodriguez {
1222203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1223203c4805SLuis R. Rodriguez 	struct ath5k_chan_pcal_info_rf2413 *pcinfo;
1224203c4805SLuis R. Rodriguez 	struct ath5k_chan_pcal_info *chinfo;
1225203c4805SLuis R. Rodriguez 	u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
1226203c4805SLuis R. Rodriguez 	u32 offset;
1227*fda9b7afSWojciech Dubowik 	int idx, i;
1228203c4805SLuis R. Rodriguez 	u16 val;
1229203c4805SLuis R. Rodriguez 	u8 pd_gains = 0;
1230203c4805SLuis R. Rodriguez 
1231203c4805SLuis R. Rodriguez 	/* Count how many curves we have and
1232203c4805SLuis R. Rodriguez 	 * identify them (which one of the 4
1233203c4805SLuis R. Rodriguez 	 * available curves we have on each count).
1234203c4805SLuis R. Rodriguez 	 * Curves are stored from higher to
1235203c4805SLuis R. Rodriguez 	 * lower gain so we go backwards */
1236203c4805SLuis R. Rodriguez 	for (idx = AR5K_EEPROM_N_PD_CURVES - 1; idx >= 0; idx--) {
1237203c4805SLuis R. Rodriguez 		/* ee_x_gain[mode] is x gain mask */
1238203c4805SLuis R. Rodriguez 		if ((ee->ee_x_gain[mode] >> idx) & 0x1)
1239203c4805SLuis R. Rodriguez 			pdgain_idx[pd_gains++] = idx;
1240203c4805SLuis R. Rodriguez 
1241203c4805SLuis R. Rodriguez 	}
1242203c4805SLuis R. Rodriguez 	ee->ee_pd_gains[mode] = pd_gains;
1243203c4805SLuis R. Rodriguez 
1244203c4805SLuis R. Rodriguez 	if (pd_gains == 0)
1245203c4805SLuis R. Rodriguez 		return -EINVAL;
1246203c4805SLuis R. Rodriguez 
1247203c4805SLuis R. Rodriguez 	offset = ath5k_cal_data_offset_2413(ee, mode);
1248203c4805SLuis R. Rodriguez 	switch (mode) {
1249203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11A:
1250203c4805SLuis R. Rodriguez 		if (!AR5K_EEPROM_HDR_11A(ee->ee_header))
1251203c4805SLuis R. Rodriguez 			return 0;
1252203c4805SLuis R. Rodriguez 
1253203c4805SLuis R. Rodriguez 		ath5k_eeprom_init_11a_pcal_freq(ah, offset);
1254203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_N_5GHZ_CHAN / 2;
1255203c4805SLuis R. Rodriguez 		chinfo = ee->ee_pwr_cal_a;
1256203c4805SLuis R. Rodriguez 		break;
1257203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11B:
1258203c4805SLuis R. Rodriguez 		if (!AR5K_EEPROM_HDR_11B(ee->ee_header))
1259203c4805SLuis R. Rodriguez 			return 0;
1260203c4805SLuis R. Rodriguez 
1261203c4805SLuis R. Rodriguez 		ath5k_eeprom_init_11bg_2413(ah, mode, offset);
1262203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2;
1263203c4805SLuis R. Rodriguez 		chinfo = ee->ee_pwr_cal_b;
1264203c4805SLuis R. Rodriguez 		break;
1265203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11G:
1266203c4805SLuis R. Rodriguez 		if (!AR5K_EEPROM_HDR_11G(ee->ee_header))
1267203c4805SLuis R. Rodriguez 			return 0;
1268203c4805SLuis R. Rodriguez 
1269203c4805SLuis R. Rodriguez 		ath5k_eeprom_init_11bg_2413(ah, mode, offset);
1270203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2;
1271203c4805SLuis R. Rodriguez 		chinfo = ee->ee_pwr_cal_g;
1272203c4805SLuis R. Rodriguez 		break;
1273203c4805SLuis R. Rodriguez 	default:
1274203c4805SLuis R. Rodriguez 		return -EINVAL;
1275203c4805SLuis R. Rodriguez 	}
1276203c4805SLuis R. Rodriguez 
1277203c4805SLuis R. Rodriguez 	for (i = 0; i < ee->ee_n_piers[mode]; i++) {
1278203c4805SLuis R. Rodriguez 		pcinfo = &chinfo[i].rf2413_info;
1279203c4805SLuis R. Rodriguez 
1280203c4805SLuis R. Rodriguez 		/*
1281203c4805SLuis R. Rodriguez 		 * Read pwr_i, pddac_i and the first
1282203c4805SLuis R. Rodriguez 		 * 2 pd points (pwr, pddac)
1283203c4805SLuis R. Rodriguez 		 */
1284203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
1285203c4805SLuis R. Rodriguez 		pcinfo->pwr_i[0] = val & 0x1f;
1286203c4805SLuis R. Rodriguez 		pcinfo->pddac_i[0] = (val >> 5) & 0x7f;
1287203c4805SLuis R. Rodriguez 		pcinfo->pwr[0][0] = (val >> 12) & 0xf;
1288203c4805SLuis R. Rodriguez 
1289203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
1290203c4805SLuis R. Rodriguez 		pcinfo->pddac[0][0] = val & 0x3f;
1291203c4805SLuis R. Rodriguez 		pcinfo->pwr[0][1] = (val >> 6) & 0xf;
1292203c4805SLuis R. Rodriguez 		pcinfo->pddac[0][1] = (val >> 10) & 0x3f;
1293203c4805SLuis R. Rodriguez 
1294203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
1295203c4805SLuis R. Rodriguez 		pcinfo->pwr[0][2] = val & 0xf;
1296203c4805SLuis R. Rodriguez 		pcinfo->pddac[0][2] = (val >> 4) & 0x3f;
1297203c4805SLuis R. Rodriguez 
1298203c4805SLuis R. Rodriguez 		pcinfo->pwr[0][3] = 0;
1299203c4805SLuis R. Rodriguez 		pcinfo->pddac[0][3] = 0;
1300203c4805SLuis R. Rodriguez 
1301203c4805SLuis R. Rodriguez 		if (pd_gains > 1) {
1302203c4805SLuis R. Rodriguez 			/*
1303203c4805SLuis R. Rodriguez 			 * Pd gain 0 is not the last pd gain
1304203c4805SLuis R. Rodriguez 			 * so it only has 2 pd points.
1305203c4805SLuis R. Rodriguez 			 * Continue wih pd gain 1.
1306203c4805SLuis R. Rodriguez 			 */
1307203c4805SLuis R. Rodriguez 			pcinfo->pwr_i[1] = (val >> 10) & 0x1f;
1308203c4805SLuis R. Rodriguez 
1309203c4805SLuis R. Rodriguez 			pcinfo->pddac_i[1] = (val >> 15) & 0x1;
1310203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1311203c4805SLuis R. Rodriguez 			pcinfo->pddac_i[1] |= (val & 0x3F) << 1;
1312203c4805SLuis R. Rodriguez 
1313203c4805SLuis R. Rodriguez 			pcinfo->pwr[1][0] = (val >> 6) & 0xf;
1314203c4805SLuis R. Rodriguez 			pcinfo->pddac[1][0] = (val >> 10) & 0x3f;
1315203c4805SLuis R. Rodriguez 
1316203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1317203c4805SLuis R. Rodriguez 			pcinfo->pwr[1][1] = val & 0xf;
1318203c4805SLuis R. Rodriguez 			pcinfo->pddac[1][1] = (val >> 4) & 0x3f;
1319203c4805SLuis R. Rodriguez 			pcinfo->pwr[1][2] = (val >> 10) & 0xf;
1320203c4805SLuis R. Rodriguez 
1321203c4805SLuis R. Rodriguez 			pcinfo->pddac[1][2] = (val >> 14) & 0x3;
1322203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1323203c4805SLuis R. Rodriguez 			pcinfo->pddac[1][2] |= (val & 0xF) << 2;
1324203c4805SLuis R. Rodriguez 
1325203c4805SLuis R. Rodriguez 			pcinfo->pwr[1][3] = 0;
1326203c4805SLuis R. Rodriguez 			pcinfo->pddac[1][3] = 0;
1327203c4805SLuis R. Rodriguez 		} else if (pd_gains == 1) {
1328203c4805SLuis R. Rodriguez 			/*
1329203c4805SLuis R. Rodriguez 			 * Pd gain 0 is the last one so
1330203c4805SLuis R. Rodriguez 			 * read the extra point.
1331203c4805SLuis R. Rodriguez 			 */
1332203c4805SLuis R. Rodriguez 			pcinfo->pwr[0][3] = (val >> 10) & 0xf;
1333203c4805SLuis R. Rodriguez 
1334203c4805SLuis R. Rodriguez 			pcinfo->pddac[0][3] = (val >> 14) & 0x3;
1335203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1336203c4805SLuis R. Rodriguez 			pcinfo->pddac[0][3] |= (val & 0xF) << 2;
1337203c4805SLuis R. Rodriguez 		}
1338203c4805SLuis R. Rodriguez 
1339203c4805SLuis R. Rodriguez 		/*
1340203c4805SLuis R. Rodriguez 		 * Proceed with the other pd_gains
1341203c4805SLuis R. Rodriguez 		 * as above.
1342203c4805SLuis R. Rodriguez 		 */
1343203c4805SLuis R. Rodriguez 		if (pd_gains > 2) {
1344203c4805SLuis R. Rodriguez 			pcinfo->pwr_i[2] = (val >> 4) & 0x1f;
1345203c4805SLuis R. Rodriguez 			pcinfo->pddac_i[2] = (val >> 9) & 0x7f;
1346203c4805SLuis R. Rodriguez 
1347203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1348203c4805SLuis R. Rodriguez 			pcinfo->pwr[2][0] = (val >> 0) & 0xf;
1349203c4805SLuis R. Rodriguez 			pcinfo->pddac[2][0] = (val >> 4) & 0x3f;
1350203c4805SLuis R. Rodriguez 			pcinfo->pwr[2][1] = (val >> 10) & 0xf;
1351203c4805SLuis R. Rodriguez 
1352203c4805SLuis R. Rodriguez 			pcinfo->pddac[2][1] = (val >> 14) & 0x3;
1353203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1354203c4805SLuis R. Rodriguez 			pcinfo->pddac[2][1] |= (val & 0xF) << 2;
1355203c4805SLuis R. Rodriguez 
1356203c4805SLuis R. Rodriguez 			pcinfo->pwr[2][2] = (val >> 4) & 0xf;
1357203c4805SLuis R. Rodriguez 			pcinfo->pddac[2][2] = (val >> 8) & 0x3f;
1358203c4805SLuis R. Rodriguez 
1359203c4805SLuis R. Rodriguez 			pcinfo->pwr[2][3] = 0;
1360203c4805SLuis R. Rodriguez 			pcinfo->pddac[2][3] = 0;
1361203c4805SLuis R. Rodriguez 		} else if (pd_gains == 2) {
1362203c4805SLuis R. Rodriguez 			pcinfo->pwr[1][3] = (val >> 4) & 0xf;
1363203c4805SLuis R. Rodriguez 			pcinfo->pddac[1][3] = (val >> 8) & 0x3f;
1364203c4805SLuis R. Rodriguez 		}
1365203c4805SLuis R. Rodriguez 
1366203c4805SLuis R. Rodriguez 		if (pd_gains > 3) {
1367203c4805SLuis R. Rodriguez 			pcinfo->pwr_i[3] = (val >> 14) & 0x3;
1368203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1369203c4805SLuis R. Rodriguez 			pcinfo->pwr_i[3] |= ((val >> 0) & 0x7) << 2;
1370203c4805SLuis R. Rodriguez 
1371203c4805SLuis R. Rodriguez 			pcinfo->pddac_i[3] = (val >> 3) & 0x7f;
1372203c4805SLuis R. Rodriguez 			pcinfo->pwr[3][0] = (val >> 10) & 0xf;
1373203c4805SLuis R. Rodriguez 			pcinfo->pddac[3][0] = (val >> 14) & 0x3;
1374203c4805SLuis R. Rodriguez 
1375203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1376203c4805SLuis R. Rodriguez 			pcinfo->pddac[3][0] |= (val & 0xF) << 2;
1377203c4805SLuis R. Rodriguez 			pcinfo->pwr[3][1] = (val >> 4) & 0xf;
1378203c4805SLuis R. Rodriguez 			pcinfo->pddac[3][1] = (val >> 8) & 0x3f;
1379203c4805SLuis R. Rodriguez 
1380203c4805SLuis R. Rodriguez 			pcinfo->pwr[3][2] = (val >> 14) & 0x3;
1381203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1382203c4805SLuis R. Rodriguez 			pcinfo->pwr[3][2] |= ((val >> 0) & 0x3) << 2;
1383203c4805SLuis R. Rodriguez 
1384203c4805SLuis R. Rodriguez 			pcinfo->pddac[3][2] = (val >> 2) & 0x3f;
1385203c4805SLuis R. Rodriguez 			pcinfo->pwr[3][3] = (val >> 8) & 0xf;
1386203c4805SLuis R. Rodriguez 
1387203c4805SLuis R. Rodriguez 			pcinfo->pddac[3][3] = (val >> 12) & 0xF;
1388203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1389203c4805SLuis R. Rodriguez 			pcinfo->pddac[3][3] |= ((val >> 0) & 0x3) << 4;
1390203c4805SLuis R. Rodriguez 		} else if (pd_gains == 3) {
1391203c4805SLuis R. Rodriguez 			pcinfo->pwr[2][3] = (val >> 14) & 0x3;
1392203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1393203c4805SLuis R. Rodriguez 			pcinfo->pwr[2][3] |= ((val >> 0) & 0x3) << 2;
1394203c4805SLuis R. Rodriguez 
1395203c4805SLuis R. Rodriguez 			pcinfo->pddac[2][3] = (val >> 2) & 0x3f;
1396203c4805SLuis R. Rodriguez 		}
1397203c4805SLuis R. Rodriguez 	}
1398203c4805SLuis R. Rodriguez 
1399203c4805SLuis R. Rodriguez 	return ath5k_eeprom_convert_pcal_info_2413(ah, mode, chinfo);
1400203c4805SLuis R. Rodriguez }
1401203c4805SLuis R. Rodriguez 
1402203c4805SLuis R. Rodriguez 
1403203c4805SLuis R. Rodriguez /*
1404203c4805SLuis R. Rodriguez  * Read per rate target power (this is the maximum tx power
1405203c4805SLuis R. Rodriguez  * supported by the card). This info is used when setting
1406203c4805SLuis R. Rodriguez  * tx power, no matter the channel.
1407203c4805SLuis R. Rodriguez  *
1408203c4805SLuis R. Rodriguez  * This also works for v5 EEPROMs.
1409203c4805SLuis R. Rodriguez  */
1410203c4805SLuis R. Rodriguez static int
1411203c4805SLuis R. Rodriguez ath5k_eeprom_read_target_rate_pwr_info(struct ath5k_hw *ah, unsigned int mode)
1412203c4805SLuis R. Rodriguez {
1413203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1414203c4805SLuis R. Rodriguez 	struct ath5k_rate_pcal_info *rate_pcal_info;
1415203c4805SLuis R. Rodriguez 	u8 *rate_target_pwr_num;
1416203c4805SLuis R. Rodriguez 	u32 offset;
1417203c4805SLuis R. Rodriguez 	u16 val;
1418*fda9b7afSWojciech Dubowik 	int i;
1419203c4805SLuis R. Rodriguez 
1420203c4805SLuis R. Rodriguez 	offset = AR5K_EEPROM_TARGET_PWRSTART(ee->ee_misc1);
1421203c4805SLuis R. Rodriguez 	rate_target_pwr_num = &ee->ee_rate_target_pwr_num[mode];
1422203c4805SLuis R. Rodriguez 	switch (mode) {
1423203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11A:
1424203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_TARGET_PWR_OFF_11A(ee->ee_version);
1425203c4805SLuis R. Rodriguez 		rate_pcal_info = ee->ee_rate_tpwr_a;
1426203c4805SLuis R. Rodriguez 		ee->ee_rate_target_pwr_num[mode] = AR5K_EEPROM_N_5GHZ_CHAN;
1427203c4805SLuis R. Rodriguez 		break;
1428203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11B:
1429203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_TARGET_PWR_OFF_11B(ee->ee_version);
1430203c4805SLuis R. Rodriguez 		rate_pcal_info = ee->ee_rate_tpwr_b;
1431203c4805SLuis R. Rodriguez 		ee->ee_rate_target_pwr_num[mode] = 2; /* 3rd is g mode's 1st */
1432203c4805SLuis R. Rodriguez 		break;
1433203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11G:
1434203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_TARGET_PWR_OFF_11G(ee->ee_version);
1435203c4805SLuis R. Rodriguez 		rate_pcal_info = ee->ee_rate_tpwr_g;
1436203c4805SLuis R. Rodriguez 		ee->ee_rate_target_pwr_num[mode] = AR5K_EEPROM_N_2GHZ_CHAN;
1437203c4805SLuis R. Rodriguez 		break;
1438203c4805SLuis R. Rodriguez 	default:
1439203c4805SLuis R. Rodriguez 		return -EINVAL;
1440203c4805SLuis R. Rodriguez 	}
1441203c4805SLuis R. Rodriguez 
1442203c4805SLuis R. Rodriguez 	/* Different freq mask for older eeproms (<= v3.2) */
1443203c4805SLuis R. Rodriguez 	if (ee->ee_version <= AR5K_EEPROM_VERSION_3_2) {
1444203c4805SLuis R. Rodriguez 		for (i = 0; i < (*rate_target_pwr_num); i++) {
1445203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1446203c4805SLuis R. Rodriguez 			rate_pcal_info[i].freq =
1447203c4805SLuis R. Rodriguez 			    ath5k_eeprom_bin2freq(ee, (val >> 9) & 0x7f, mode);
1448203c4805SLuis R. Rodriguez 
1449203c4805SLuis R. Rodriguez 			rate_pcal_info[i].target_power_6to24 = ((val >> 3) & 0x3f);
1450203c4805SLuis R. Rodriguez 			rate_pcal_info[i].target_power_36 = (val << 3) & 0x3f;
1451203c4805SLuis R. Rodriguez 
1452203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1453203c4805SLuis R. Rodriguez 
1454203c4805SLuis R. Rodriguez 			if (rate_pcal_info[i].freq == AR5K_EEPROM_CHANNEL_DIS ||
1455203c4805SLuis R. Rodriguez 			    val == 0) {
1456203c4805SLuis R. Rodriguez 				(*rate_target_pwr_num) = i;
1457203c4805SLuis R. Rodriguez 				break;
1458203c4805SLuis R. Rodriguez 			}
1459203c4805SLuis R. Rodriguez 
1460203c4805SLuis R. Rodriguez 			rate_pcal_info[i].target_power_36 |= ((val >> 13) & 0x7);
1461203c4805SLuis R. Rodriguez 			rate_pcal_info[i].target_power_48 = ((val >> 7) & 0x3f);
1462203c4805SLuis R. Rodriguez 			rate_pcal_info[i].target_power_54 = ((val >> 1) & 0x3f);
1463203c4805SLuis R. Rodriguez 		}
1464203c4805SLuis R. Rodriguez 	} else {
1465203c4805SLuis R. Rodriguez 		for (i = 0; i < (*rate_target_pwr_num); i++) {
1466203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1467203c4805SLuis R. Rodriguez 			rate_pcal_info[i].freq =
1468203c4805SLuis R. Rodriguez 			    ath5k_eeprom_bin2freq(ee, (val >> 8) & 0xff, mode);
1469203c4805SLuis R. Rodriguez 
1470203c4805SLuis R. Rodriguez 			rate_pcal_info[i].target_power_6to24 = ((val >> 2) & 0x3f);
1471203c4805SLuis R. Rodriguez 			rate_pcal_info[i].target_power_36 = (val << 4) & 0x3f;
1472203c4805SLuis R. Rodriguez 
1473203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1474203c4805SLuis R. Rodriguez 
1475203c4805SLuis R. Rodriguez 			if (rate_pcal_info[i].freq == AR5K_EEPROM_CHANNEL_DIS ||
1476203c4805SLuis R. Rodriguez 			    val == 0) {
1477203c4805SLuis R. Rodriguez 				(*rate_target_pwr_num) = i;
1478203c4805SLuis R. Rodriguez 				break;
1479203c4805SLuis R. Rodriguez 			}
1480203c4805SLuis R. Rodriguez 
1481203c4805SLuis R. Rodriguez 			rate_pcal_info[i].target_power_36 |= (val >> 12) & 0xf;
1482203c4805SLuis R. Rodriguez 			rate_pcal_info[i].target_power_48 = ((val >> 6) & 0x3f);
1483203c4805SLuis R. Rodriguez 			rate_pcal_info[i].target_power_54 = (val & 0x3f);
1484203c4805SLuis R. Rodriguez 		}
1485203c4805SLuis R. Rodriguez 	}
1486203c4805SLuis R. Rodriguez 
1487203c4805SLuis R. Rodriguez 	return 0;
1488203c4805SLuis R. Rodriguez }
1489203c4805SLuis R. Rodriguez 
14909320b5c4SNick Kossifidis 
1491203c4805SLuis R. Rodriguez /*
1492203c4805SLuis R. Rodriguez  * Read per channel calibration info from EEPROM
1493203c4805SLuis R. Rodriguez  *
1494203c4805SLuis R. Rodriguez  * This info is used to calibrate the baseband power table. Imagine
1495203c4805SLuis R. Rodriguez  * that for each channel there is a power curve that's hw specific
1496203c4805SLuis R. Rodriguez  * (depends on amplifier etc) and we try to "correct" this curve using
1497bf48aabbSUwe Kleine-König  * offsets we pass on to phy chip (baseband -> before amplifier) so that
1498203c4805SLuis R. Rodriguez  * it can use accurate power values when setting tx power (takes amplifier's
1499203c4805SLuis R. Rodriguez  * performance on each channel into account).
1500203c4805SLuis R. Rodriguez  *
1501203c4805SLuis R. Rodriguez  * EEPROM provides us with the offsets for some pre-calibrated channels
1502203c4805SLuis R. Rodriguez  * and we have to interpolate to create the full table for these channels and
1503203c4805SLuis R. Rodriguez  * also the table for any channel.
1504203c4805SLuis R. Rodriguez  */
1505203c4805SLuis R. Rodriguez static int
1506203c4805SLuis R. Rodriguez ath5k_eeprom_read_pcal_info(struct ath5k_hw *ah)
1507203c4805SLuis R. Rodriguez {
1508203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1509203c4805SLuis R. Rodriguez 	int (*read_pcal)(struct ath5k_hw *hw, int mode);
1510203c4805SLuis R. Rodriguez 	int mode;
1511203c4805SLuis R. Rodriguez 	int err;
1512203c4805SLuis R. Rodriguez 
1513203c4805SLuis R. Rodriguez 	if ((ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) &&
1514203c4805SLuis R. Rodriguez 			(AR5K_EEPROM_EEMAP(ee->ee_misc0) == 1))
1515203c4805SLuis R. Rodriguez 		read_pcal = ath5k_eeprom_read_pcal_info_5112;
1516203c4805SLuis R. Rodriguez 	else if ((ah->ah_ee_version >= AR5K_EEPROM_VERSION_5_0) &&
1517203c4805SLuis R. Rodriguez 			(AR5K_EEPROM_EEMAP(ee->ee_misc0) == 2))
1518203c4805SLuis R. Rodriguez 		read_pcal = ath5k_eeprom_read_pcal_info_2413;
1519203c4805SLuis R. Rodriguez 	else
1520203c4805SLuis R. Rodriguez 		read_pcal = ath5k_eeprom_read_pcal_info_5111;
1521203c4805SLuis R. Rodriguez 
1522203c4805SLuis R. Rodriguez 
1523203c4805SLuis R. Rodriguez 	for (mode = AR5K_EEPROM_MODE_11A; mode <= AR5K_EEPROM_MODE_11G;
1524203c4805SLuis R. Rodriguez 	mode++) {
1525203c4805SLuis R. Rodriguez 		err = read_pcal(ah, mode);
1526203c4805SLuis R. Rodriguez 		if (err)
1527203c4805SLuis R. Rodriguez 			return err;
1528203c4805SLuis R. Rodriguez 
1529203c4805SLuis R. Rodriguez 		err = ath5k_eeprom_read_target_rate_pwr_info(ah, mode);
1530203c4805SLuis R. Rodriguez 		if (err < 0)
1531203c4805SLuis R. Rodriguez 			return err;
1532203c4805SLuis R. Rodriguez 	}
1533203c4805SLuis R. Rodriguez 
1534203c4805SLuis R. Rodriguez 	return 0;
1535203c4805SLuis R. Rodriguez }
1536203c4805SLuis R. Rodriguez 
1537203c4805SLuis R. Rodriguez static int
1538203c4805SLuis R. Rodriguez ath5k_eeprom_free_pcal_info(struct ath5k_hw *ah, int mode)
1539203c4805SLuis R. Rodriguez {
1540203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1541203c4805SLuis R. Rodriguez 	struct ath5k_chan_pcal_info *chinfo;
1542203c4805SLuis R. Rodriguez 	u8 pier, pdg;
1543203c4805SLuis R. Rodriguez 
1544203c4805SLuis R. Rodriguez 	switch (mode) {
1545203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11A:
1546203c4805SLuis R. Rodriguez 		if (!AR5K_EEPROM_HDR_11A(ee->ee_header))
1547203c4805SLuis R. Rodriguez 			return 0;
1548203c4805SLuis R. Rodriguez 		chinfo = ee->ee_pwr_cal_a;
1549203c4805SLuis R. Rodriguez 		break;
1550203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11B:
1551203c4805SLuis R. Rodriguez 		if (!AR5K_EEPROM_HDR_11B(ee->ee_header))
1552203c4805SLuis R. Rodriguez 			return 0;
1553203c4805SLuis R. Rodriguez 		chinfo = ee->ee_pwr_cal_b;
1554203c4805SLuis R. Rodriguez 		break;
1555203c4805SLuis R. Rodriguez 	case AR5K_EEPROM_MODE_11G:
1556203c4805SLuis R. Rodriguez 		if (!AR5K_EEPROM_HDR_11G(ee->ee_header))
1557203c4805SLuis R. Rodriguez 			return 0;
1558203c4805SLuis R. Rodriguez 		chinfo = ee->ee_pwr_cal_g;
1559203c4805SLuis R. Rodriguez 		break;
1560203c4805SLuis R. Rodriguez 	default:
1561203c4805SLuis R. Rodriguez 		return -EINVAL;
1562203c4805SLuis R. Rodriguez 	}
1563203c4805SLuis R. Rodriguez 
1564203c4805SLuis R. Rodriguez 	for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
1565203c4805SLuis R. Rodriguez 		if (!chinfo[pier].pd_curves)
1566203c4805SLuis R. Rodriguez 			continue;
1567203c4805SLuis R. Rodriguez 
1568203c4805SLuis R. Rodriguez 		for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) {
1569203c4805SLuis R. Rodriguez 			struct ath5k_pdgain_info *pd =
1570203c4805SLuis R. Rodriguez 					&chinfo[pier].pd_curves[pdg];
1571203c4805SLuis R. Rodriguez 
1572203c4805SLuis R. Rodriguez 			if (pd != NULL) {
1573203c4805SLuis R. Rodriguez 				kfree(pd->pd_step);
1574203c4805SLuis R. Rodriguez 				kfree(pd->pd_pwr);
1575203c4805SLuis R. Rodriguez 			}
1576203c4805SLuis R. Rodriguez 		}
1577203c4805SLuis R. Rodriguez 
1578203c4805SLuis R. Rodriguez 		kfree(chinfo[pier].pd_curves);
1579203c4805SLuis R. Rodriguez 	}
1580203c4805SLuis R. Rodriguez 
1581203c4805SLuis R. Rodriguez 	return 0;
1582203c4805SLuis R. Rodriguez }
1583203c4805SLuis R. Rodriguez 
1584203c4805SLuis R. Rodriguez /* Read conformance test limits used for regulatory control */
1585203c4805SLuis R. Rodriguez static int
1586203c4805SLuis R. Rodriguez ath5k_eeprom_read_ctl_info(struct ath5k_hw *ah)
1587203c4805SLuis R. Rodriguez {
1588203c4805SLuis R. Rodriguez 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1589203c4805SLuis R. Rodriguez 	struct ath5k_edge_power *rep;
1590203c4805SLuis R. Rodriguez 	unsigned int fmask, pmask;
1591203c4805SLuis R. Rodriguez 	unsigned int ctl_mode;
1592*fda9b7afSWojciech Dubowik 	int i, j;
1593203c4805SLuis R. Rodriguez 	u32 offset;
1594203c4805SLuis R. Rodriguez 	u16 val;
1595203c4805SLuis R. Rodriguez 
1596203c4805SLuis R. Rodriguez 	pmask = AR5K_EEPROM_POWER_M;
1597203c4805SLuis R. Rodriguez 	fmask = AR5K_EEPROM_FREQ_M(ee->ee_version);
1598203c4805SLuis R. Rodriguez 	offset = AR5K_EEPROM_CTL(ee->ee_version);
1599203c4805SLuis R. Rodriguez 	ee->ee_ctls = AR5K_EEPROM_N_CTLS(ee->ee_version);
1600203c4805SLuis R. Rodriguez 	for (i = 0; i < ee->ee_ctls; i += 2) {
1601203c4805SLuis R. Rodriguez 		AR5K_EEPROM_READ(offset++, val);
1602203c4805SLuis R. Rodriguez 		ee->ee_ctl[i] = (val >> 8) & 0xff;
1603203c4805SLuis R. Rodriguez 		ee->ee_ctl[i + 1] = val & 0xff;
1604203c4805SLuis R. Rodriguez 	}
1605203c4805SLuis R. Rodriguez 
1606203c4805SLuis R. Rodriguez 	offset = AR5K_EEPROM_GROUP8_OFFSET;
1607203c4805SLuis R. Rodriguez 	if (ee->ee_version >= AR5K_EEPROM_VERSION_4_0)
1608203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_TARGET_PWRSTART(ee->ee_misc1) -
1609203c4805SLuis R. Rodriguez 			AR5K_EEPROM_GROUP5_OFFSET;
1610203c4805SLuis R. Rodriguez 	else
1611203c4805SLuis R. Rodriguez 		offset += AR5K_EEPROM_GROUPS_START(ee->ee_version);
1612203c4805SLuis R. Rodriguez 
1613203c4805SLuis R. Rodriguez 	rep = ee->ee_ctl_pwr;
1614203c4805SLuis R. Rodriguez 	for(i = 0; i < ee->ee_ctls; i++) {
1615203c4805SLuis R. Rodriguez 		switch(ee->ee_ctl[i] & AR5K_CTL_MODE_M) {
1616203c4805SLuis R. Rodriguez 		case AR5K_CTL_11A:
1617203c4805SLuis R. Rodriguez 		case AR5K_CTL_TURBO:
1618203c4805SLuis R. Rodriguez 			ctl_mode = AR5K_EEPROM_MODE_11A;
1619203c4805SLuis R. Rodriguez 			break;
1620203c4805SLuis R. Rodriguez 		default:
1621203c4805SLuis R. Rodriguez 			ctl_mode = AR5K_EEPROM_MODE_11G;
1622203c4805SLuis R. Rodriguez 			break;
1623203c4805SLuis R. Rodriguez 		}
1624203c4805SLuis R. Rodriguez 		if (ee->ee_ctl[i] == 0) {
1625203c4805SLuis R. Rodriguez 			if (ee->ee_version >= AR5K_EEPROM_VERSION_3_3)
1626203c4805SLuis R. Rodriguez 				offset += 8;
1627203c4805SLuis R. Rodriguez 			else
1628203c4805SLuis R. Rodriguez 				offset += 7;
1629203c4805SLuis R. Rodriguez 			rep += AR5K_EEPROM_N_EDGES;
1630203c4805SLuis R. Rodriguez 			continue;
1631203c4805SLuis R. Rodriguez 		}
1632203c4805SLuis R. Rodriguez 		if (ee->ee_version >= AR5K_EEPROM_VERSION_3_3) {
1633203c4805SLuis R. Rodriguez 			for (j = 0; j < AR5K_EEPROM_N_EDGES; j += 2) {
1634203c4805SLuis R. Rodriguez 				AR5K_EEPROM_READ(offset++, val);
1635203c4805SLuis R. Rodriguez 				rep[j].freq = (val >> 8) & fmask;
1636203c4805SLuis R. Rodriguez 				rep[j + 1].freq = val & fmask;
1637203c4805SLuis R. Rodriguez 			}
1638203c4805SLuis R. Rodriguez 			for (j = 0; j < AR5K_EEPROM_N_EDGES; j += 2) {
1639203c4805SLuis R. Rodriguez 				AR5K_EEPROM_READ(offset++, val);
1640203c4805SLuis R. Rodriguez 				rep[j].edge = (val >> 8) & pmask;
1641203c4805SLuis R. Rodriguez 				rep[j].flag = (val >> 14) & 1;
1642203c4805SLuis R. Rodriguez 				rep[j + 1].edge = val & pmask;
1643203c4805SLuis R. Rodriguez 				rep[j + 1].flag = (val >> 6) & 1;
1644203c4805SLuis R. Rodriguez 			}
1645203c4805SLuis R. Rodriguez 		} else {
1646203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1647203c4805SLuis R. Rodriguez 			rep[0].freq = (val >> 9) & fmask;
1648203c4805SLuis R. Rodriguez 			rep[1].freq = (val >> 2) & fmask;
1649203c4805SLuis R. Rodriguez 			rep[2].freq = (val << 5) & fmask;
1650203c4805SLuis R. Rodriguez 
1651203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1652203c4805SLuis R. Rodriguez 			rep[2].freq |= (val >> 11) & 0x1f;
1653203c4805SLuis R. Rodriguez 			rep[3].freq = (val >> 4) & fmask;
1654203c4805SLuis R. Rodriguez 			rep[4].freq = (val << 3) & fmask;
1655203c4805SLuis R. Rodriguez 
1656203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1657203c4805SLuis R. Rodriguez 			rep[4].freq |= (val >> 13) & 0x7;
1658203c4805SLuis R. Rodriguez 			rep[5].freq = (val >> 6) & fmask;
1659203c4805SLuis R. Rodriguez 			rep[6].freq = (val << 1) & fmask;
1660203c4805SLuis R. Rodriguez 
1661203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1662203c4805SLuis R. Rodriguez 			rep[6].freq |= (val >> 15) & 0x1;
1663203c4805SLuis R. Rodriguez 			rep[7].freq = (val >> 8) & fmask;
1664203c4805SLuis R. Rodriguez 
1665203c4805SLuis R. Rodriguez 			rep[0].edge = (val >> 2) & pmask;
1666203c4805SLuis R. Rodriguez 			rep[1].edge = (val << 4) & pmask;
1667203c4805SLuis R. Rodriguez 
1668203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1669203c4805SLuis R. Rodriguez 			rep[1].edge |= (val >> 12) & 0xf;
1670203c4805SLuis R. Rodriguez 			rep[2].edge = (val >> 6) & pmask;
1671203c4805SLuis R. Rodriguez 			rep[3].edge = val & pmask;
1672203c4805SLuis R. Rodriguez 
1673203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1674203c4805SLuis R. Rodriguez 			rep[4].edge = (val >> 10) & pmask;
1675203c4805SLuis R. Rodriguez 			rep[5].edge = (val >> 4) & pmask;
1676203c4805SLuis R. Rodriguez 			rep[6].edge = (val << 2) & pmask;
1677203c4805SLuis R. Rodriguez 
1678203c4805SLuis R. Rodriguez 			AR5K_EEPROM_READ(offset++, val);
1679203c4805SLuis R. Rodriguez 			rep[6].edge |= (val >> 14) & 0x3;
1680203c4805SLuis R. Rodriguez 			rep[7].edge = (val >> 8) & pmask;
1681203c4805SLuis R. Rodriguez 		}
1682203c4805SLuis R. Rodriguez 		for (j = 0; j < AR5K_EEPROM_N_EDGES; j++) {
1683203c4805SLuis R. Rodriguez 			rep[j].freq = ath5k_eeprom_bin2freq(ee,
1684203c4805SLuis R. Rodriguez 				rep[j].freq, ctl_mode);
1685203c4805SLuis R. Rodriguez 		}
1686203c4805SLuis R. Rodriguez 		rep += AR5K_EEPROM_N_EDGES;
1687203c4805SLuis R. Rodriguez 	}
1688203c4805SLuis R. Rodriguez 
1689203c4805SLuis R. Rodriguez 	return 0;
1690203c4805SLuis R. Rodriguez }
1691203c4805SLuis R. Rodriguez 
1692cd417519SNick Kossifidis static int
1693cd417519SNick Kossifidis ath5k_eeprom_read_spur_chans(struct ath5k_hw *ah)
1694cd417519SNick Kossifidis {
1695cd417519SNick Kossifidis 	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1696cd417519SNick Kossifidis 	u32 offset;
1697cd417519SNick Kossifidis 	u16 val;
1698cd417519SNick Kossifidis 	int ret = 0, i;
1699cd417519SNick Kossifidis 
1700cd417519SNick Kossifidis 	offset = AR5K_EEPROM_CTL(ee->ee_version) +
1701cd417519SNick Kossifidis 				AR5K_EEPROM_N_CTLS(ee->ee_version);
1702cd417519SNick Kossifidis 
1703cd417519SNick Kossifidis 	if (ee->ee_version < AR5K_EEPROM_VERSION_5_3) {
1704cd417519SNick Kossifidis 		/* No spur info for 5GHz */
1705cd417519SNick Kossifidis 		ee->ee_spur_chans[0][0] = AR5K_EEPROM_NO_SPUR;
1706cd417519SNick Kossifidis 		/* 2 channels for 2GHz (2464/2420) */
1707cd417519SNick Kossifidis 		ee->ee_spur_chans[0][1] = AR5K_EEPROM_5413_SPUR_CHAN_1;
1708cd417519SNick Kossifidis 		ee->ee_spur_chans[1][1] = AR5K_EEPROM_5413_SPUR_CHAN_2;
1709cd417519SNick Kossifidis 		ee->ee_spur_chans[2][1] = AR5K_EEPROM_NO_SPUR;
1710cd417519SNick Kossifidis 	} else if (ee->ee_version >= AR5K_EEPROM_VERSION_5_3) {
1711cd417519SNick Kossifidis 		for (i = 0; i < AR5K_EEPROM_N_SPUR_CHANS; i++) {
1712cd417519SNick Kossifidis 			AR5K_EEPROM_READ(offset, val);
1713cd417519SNick Kossifidis 			ee->ee_spur_chans[i][0] = val;
1714cd417519SNick Kossifidis 			AR5K_EEPROM_READ(offset + AR5K_EEPROM_N_SPUR_CHANS,
1715cd417519SNick Kossifidis 									val);
1716cd417519SNick Kossifidis 			ee->ee_spur_chans[i][1] = val;
1717cd417519SNick Kossifidis 			offset++;
1718cd417519SNick Kossifidis 		}
1719cd417519SNick Kossifidis 	}
1720cd417519SNick Kossifidis 
1721cd417519SNick Kossifidis 	return ret;
1722cd417519SNick Kossifidis }
1723203c4805SLuis R. Rodriguez 
1724203c4805SLuis R. Rodriguez /*
1725203c4805SLuis R. Rodriguez  * Read the MAC address from eeprom
1726203c4805SLuis R. Rodriguez  */
1727203c4805SLuis R. Rodriguez int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
1728203c4805SLuis R. Rodriguez {
1729203c4805SLuis R. Rodriguez 	u8 mac_d[ETH_ALEN] = {};
1730203c4805SLuis R. Rodriguez 	u32 total, offset;
1731203c4805SLuis R. Rodriguez 	u16 data;
1732*fda9b7afSWojciech Dubowik 	int octet;
1733203c4805SLuis R. Rodriguez 
1734*fda9b7afSWojciech Dubowik 	AR5K_EEPROM_READ(0x20, data);
1735203c4805SLuis R. Rodriguez 
1736203c4805SLuis R. Rodriguez 	for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) {
1737*fda9b7afSWojciech Dubowik 		AR5K_EEPROM_READ(offset, data);
1738203c4805SLuis R. Rodriguez 
1739203c4805SLuis R. Rodriguez 		total += data;
1740203c4805SLuis R. Rodriguez 		mac_d[octet + 1] = data & 0xff;
1741203c4805SLuis R. Rodriguez 		mac_d[octet] = data >> 8;
1742203c4805SLuis R. Rodriguez 		octet += 2;
1743203c4805SLuis R. Rodriguez 	}
1744203c4805SLuis R. Rodriguez 
1745203c4805SLuis R. Rodriguez 	if (!total || total == 3 * 0xffff)
1746203c4805SLuis R. Rodriguez 		return -EINVAL;
1747203c4805SLuis R. Rodriguez 
1748203c4805SLuis R. Rodriguez 	memcpy(mac, mac_d, ETH_ALEN);
1749203c4805SLuis R. Rodriguez 
1750203c4805SLuis R. Rodriguez 	return 0;
1751203c4805SLuis R. Rodriguez }
17529320b5c4SNick Kossifidis 
17539320b5c4SNick Kossifidis 
17549320b5c4SNick Kossifidis /***********************\
17559320b5c4SNick Kossifidis * Init/Detach functions *
17569320b5c4SNick Kossifidis \***********************/
17579320b5c4SNick Kossifidis 
17589320b5c4SNick Kossifidis /*
17599320b5c4SNick Kossifidis  * Initialize eeprom data structure
17609320b5c4SNick Kossifidis  */
17619320b5c4SNick Kossifidis int
17629320b5c4SNick Kossifidis ath5k_eeprom_init(struct ath5k_hw *ah)
17639320b5c4SNick Kossifidis {
17649320b5c4SNick Kossifidis 	int err;
17659320b5c4SNick Kossifidis 
17669320b5c4SNick Kossifidis 	err = ath5k_eeprom_init_header(ah);
17679320b5c4SNick Kossifidis 	if (err < 0)
17689320b5c4SNick Kossifidis 		return err;
17699320b5c4SNick Kossifidis 
17709320b5c4SNick Kossifidis 	err = ath5k_eeprom_init_modes(ah);
17719320b5c4SNick Kossifidis 	if (err < 0)
17729320b5c4SNick Kossifidis 		return err;
17739320b5c4SNick Kossifidis 
17749320b5c4SNick Kossifidis 	err = ath5k_eeprom_read_pcal_info(ah);
17759320b5c4SNick Kossifidis 	if (err < 0)
17769320b5c4SNick Kossifidis 		return err;
17779320b5c4SNick Kossifidis 
17789320b5c4SNick Kossifidis 	err = ath5k_eeprom_read_ctl_info(ah);
17799320b5c4SNick Kossifidis 	if (err < 0)
17809320b5c4SNick Kossifidis 		return err;
17819320b5c4SNick Kossifidis 
17829320b5c4SNick Kossifidis 	err = ath5k_eeprom_read_spur_chans(ah);
17839320b5c4SNick Kossifidis 	if (err < 0)
17849320b5c4SNick Kossifidis 		return err;
17859320b5c4SNick Kossifidis 
17869320b5c4SNick Kossifidis 	return 0;
17879320b5c4SNick Kossifidis }
17889320b5c4SNick Kossifidis 
17899320b5c4SNick Kossifidis void
17909320b5c4SNick Kossifidis ath5k_eeprom_detach(struct ath5k_hw *ah)
17919320b5c4SNick Kossifidis {
17929320b5c4SNick Kossifidis 	u8 mode;
17939320b5c4SNick Kossifidis 
17949320b5c4SNick Kossifidis 	for (mode = AR5K_EEPROM_MODE_11A; mode <= AR5K_EEPROM_MODE_11G; mode++)
17959320b5c4SNick Kossifidis 		ath5k_eeprom_free_pcal_info(ah, mode);
17969320b5c4SNick Kossifidis }
17970207c0c5SBruno Randolf 
17980207c0c5SBruno Randolf int
17990207c0c5SBruno Randolf ath5k_eeprom_mode_from_channel(struct ieee80211_channel *channel)
18000207c0c5SBruno Randolf {
18010207c0c5SBruno Randolf 	switch (channel->hw_value & CHANNEL_MODES) {
18020207c0c5SBruno Randolf 	case CHANNEL_A:
18030207c0c5SBruno Randolf 	case CHANNEL_XR:
18040207c0c5SBruno Randolf 		return AR5K_EEPROM_MODE_11A;
18050207c0c5SBruno Randolf 	case CHANNEL_G:
18060207c0c5SBruno Randolf 		return AR5K_EEPROM_MODE_11G;
18070207c0c5SBruno Randolf 	case CHANNEL_B:
18080207c0c5SBruno Randolf 		return AR5K_EEPROM_MODE_11B;
18090207c0c5SBruno Randolf 	default:
18100207c0c5SBruno Randolf 		return -1;
18110207c0c5SBruno Randolf 	}
18120207c0c5SBruno Randolf }
1813