xref: /titanic_51/usr/src/uts/common/io/arn/arn_eeprom.c (revision c0c934808d1b7d058148814255f32064a0e09555)
1dd1de374Slin wang - Sun Microsystems - Beijing China /*
2*c0c93480Slin wang - Sun Microsystems - Beijing China  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
3dd1de374Slin wang - Sun Microsystems - Beijing China  * Use is subject to license terms.
4dd1de374Slin wang - Sun Microsystems - Beijing China  */
5dd1de374Slin wang - Sun Microsystems - Beijing China 
6dd1de374Slin wang - Sun Microsystems - Beijing China /*
7dd1de374Slin wang - Sun Microsystems - Beijing China  * Copyright (c) 2008 Atheros Communications Inc.
8dd1de374Slin wang - Sun Microsystems - Beijing China  *
9dd1de374Slin wang - Sun Microsystems - Beijing China  * Permission to use, copy, modify, and/or distribute this software for any
10dd1de374Slin wang - Sun Microsystems - Beijing China  * purpose with or without fee is hereby granted, provided that the above
11dd1de374Slin wang - Sun Microsystems - Beijing China  * copyright notice and this permission notice appear in all copies.
12dd1de374Slin wang - Sun Microsystems - Beijing China  *
13dd1de374Slin wang - Sun Microsystems - Beijing China  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14dd1de374Slin wang - Sun Microsystems - Beijing China  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15dd1de374Slin wang - Sun Microsystems - Beijing China  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16dd1de374Slin wang - Sun Microsystems - Beijing China  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17dd1de374Slin wang - Sun Microsystems - Beijing China  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18dd1de374Slin wang - Sun Microsystems - Beijing China  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19dd1de374Slin wang - Sun Microsystems - Beijing China  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20dd1de374Slin wang - Sun Microsystems - Beijing China  */
21dd1de374Slin wang - Sun Microsystems - Beijing China 
22dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/param.h>
23dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/types.h>
24dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/signal.h>
25dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/stream.h>
26dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/termio.h>
27dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/errno.h>
28dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/file.h>
29dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/cmn_err.h>
30dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/stropts.h>
31dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/strsubr.h>
32dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/strtty.h>
33dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/kbio.h>
34dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/cred.h>
35dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/stat.h>
36dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/consdev.h>
37dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/kmem.h>
38dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/modctl.h>
39dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/ddi.h>
40dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/sunddi.h>
41dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/pci.h>
42dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/errno.h>
43dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/gld.h>
44dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/dlpi.h>
45dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/ethernet.h>
46dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/list.h>
47dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/byteorder.h>
48dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/strsun.h>
49dd1de374Slin wang - Sun Microsystems - Beijing China #include <inet/common.h>
50dd1de374Slin wang - Sun Microsystems - Beijing China #include <inet/nd.h>
51dd1de374Slin wang - Sun Microsystems - Beijing China #include <inet/mi.h>
52dd1de374Slin wang - Sun Microsystems - Beijing China #include <inet/wifi_ioctl.h>
53dd1de374Slin wang - Sun Microsystems - Beijing China 
54dd1de374Slin wang - Sun Microsystems - Beijing China #include "arn_core.h"
55dd1de374Slin wang - Sun Microsystems - Beijing China #include "arn_hw.h"
56dd1de374Slin wang - Sun Microsystems - Beijing China #include "arn_reg.h"
57dd1de374Slin wang - Sun Microsystems - Beijing China #include "arn_phy.h"
58dd1de374Slin wang - Sun Microsystems - Beijing China 
59dd1de374Slin wang - Sun Microsystems - Beijing China static void
60dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_analog_shift_rmw(struct ath_hal *ah,
61dd1de374Slin wang - Sun Microsystems - Beijing China     uint32_t reg, uint32_t mask,
62dd1de374Slin wang - Sun Microsystems - Beijing China     uint32_t shift, uint32_t val)
63dd1de374Slin wang - Sun Microsystems - Beijing China {
64dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t regVal;
65dd1de374Slin wang - Sun Microsystems - Beijing China 
66dd1de374Slin wang - Sun Microsystems - Beijing China 	regVal = REG_READ(ah, reg) & ~mask;
67dd1de374Slin wang - Sun Microsystems - Beijing China 	regVal |= (val << shift) & mask;
68dd1de374Slin wang - Sun Microsystems - Beijing China 
69dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, reg, regVal);
70dd1de374Slin wang - Sun Microsystems - Beijing China 
71dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ah->ah_config.analog_shiftreg)
72dd1de374Slin wang - Sun Microsystems - Beijing China 		drv_usecwait(100);
73dd1de374Slin wang - Sun Microsystems - Beijing China }
74dd1de374Slin wang - Sun Microsystems - Beijing China 
75dd1de374Slin wang - Sun Microsystems - Beijing China static inline uint16_t
76dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_fbin2freq(uint8_t fbin, boolean_t is2GHz)
77dd1de374Slin wang - Sun Microsystems - Beijing China {
78dd1de374Slin wang - Sun Microsystems - Beijing China 
79dd1de374Slin wang - Sun Microsystems - Beijing China 	if (fbin == AR5416_BCHAN_UNUSED)
80dd1de374Slin wang - Sun Microsystems - Beijing China 		return (fbin);
81dd1de374Slin wang - Sun Microsystems - Beijing China 
82dd1de374Slin wang - Sun Microsystems - Beijing China 	return ((uint16_t)((is2GHz) ? (2300 + fbin) : (4800 + 5 * fbin)));
83dd1de374Slin wang - Sun Microsystems - Beijing China }
84dd1de374Slin wang - Sun Microsystems - Beijing China 
85dd1de374Slin wang - Sun Microsystems - Beijing China static inline int16_t
86dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_interpolate(uint16_t target, uint16_t srcLeft, uint16_t srcRight,
87dd1de374Slin wang - Sun Microsystems - Beijing China     int16_t targetLeft, int16_t targetRight)
88dd1de374Slin wang - Sun Microsystems - Beijing China {
89dd1de374Slin wang - Sun Microsystems - Beijing China 	int16_t rv;
90dd1de374Slin wang - Sun Microsystems - Beijing China 
91dd1de374Slin wang - Sun Microsystems - Beijing China 	if (srcRight == srcLeft) {
92dd1de374Slin wang - Sun Microsystems - Beijing China 		rv = targetLeft;
93dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
94dd1de374Slin wang - Sun Microsystems - Beijing China 		rv = (int16_t)(((target - srcLeft) * targetRight +
95dd1de374Slin wang - Sun Microsystems - Beijing China 		    (srcRight - target) * targetLeft) /
96dd1de374Slin wang - Sun Microsystems - Beijing China 		    (srcRight - srcLeft));
97dd1de374Slin wang - Sun Microsystems - Beijing China 	}
98dd1de374Slin wang - Sun Microsystems - Beijing China 	return (rv);
99dd1de374Slin wang - Sun Microsystems - Beijing China }
100dd1de374Slin wang - Sun Microsystems - Beijing China 
101dd1de374Slin wang - Sun Microsystems - Beijing China static inline boolean_t
102dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_get_lower_upper_index(uint8_t target, uint8_t *pList,
103dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t listSize, uint16_t *indexL, uint16_t *indexR)
104dd1de374Slin wang - Sun Microsystems - Beijing China {
105dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t i;
106dd1de374Slin wang - Sun Microsystems - Beijing China 
107dd1de374Slin wang - Sun Microsystems - Beijing China 	if (target <= pList[0]) {
108dd1de374Slin wang - Sun Microsystems - Beijing China 		*indexL = *indexR = 0;
109dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_TRUE);
110dd1de374Slin wang - Sun Microsystems - Beijing China 	}
111dd1de374Slin wang - Sun Microsystems - Beijing China 	if (target >= pList[listSize - 1]) {
112dd1de374Slin wang - Sun Microsystems - Beijing China 		*indexL = *indexR = (uint16_t)(listSize - 1);
113dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_TRUE);
114dd1de374Slin wang - Sun Microsystems - Beijing China 	}
115dd1de374Slin wang - Sun Microsystems - Beijing China 
116dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < listSize - 1; i++) {
117dd1de374Slin wang - Sun Microsystems - Beijing China 		if (pList[i] == target) {
118dd1de374Slin wang - Sun Microsystems - Beijing China 			*indexL = *indexR = i;
119dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_TRUE);
120dd1de374Slin wang - Sun Microsystems - Beijing China 		}
121dd1de374Slin wang - Sun Microsystems - Beijing China 		if (target < pList[i + 1]) {
122dd1de374Slin wang - Sun Microsystems - Beijing China 			*indexL = i;
123dd1de374Slin wang - Sun Microsystems - Beijing China 			*indexR = (uint16_t)(i + 1);
124dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_FALSE);
125dd1de374Slin wang - Sun Microsystems - Beijing China 		}
126dd1de374Slin wang - Sun Microsystems - Beijing China 	}
127dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_FALSE);
128dd1de374Slin wang - Sun Microsystems - Beijing China }
129dd1de374Slin wang - Sun Microsystems - Beijing China 
130dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t
131dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_eeprom_read(struct ath_hal *ah, uint32_t off, uint16_t *data)
132dd1de374Slin wang - Sun Microsystems - Beijing China {
133dd1de374Slin wang - Sun Microsystems - Beijing China 	(void) REG_READ(ah, AR5416_EEPROM_OFFSET + (off << AR5416_EEPROM_S));
134dd1de374Slin wang - Sun Microsystems - Beijing China 
135dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_wait(ah, AR_EEPROM_STATUS_DATA,
136dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_EEPROM_STATUS_DATA_BUSY |
137dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_EEPROM_STATUS_DATA_PROT_ACCESS, 0)) {
138dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
139dd1de374Slin wang - Sun Microsystems - Beijing China 	}
140dd1de374Slin wang - Sun Microsystems - Beijing China 
141dd1de374Slin wang - Sun Microsystems - Beijing China 	*data = MS(REG_READ(ah, AR_EEPROM_STATUS_DATA),
142dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_EEPROM_STATUS_DATA_VAL);
143dd1de374Slin wang - Sun Microsystems - Beijing China 
144dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
145dd1de374Slin wang - Sun Microsystems - Beijing China }
146dd1de374Slin wang - Sun Microsystems - Beijing China 
147dd1de374Slin wang - Sun Microsystems - Beijing China /* ARGSUSED */
148dd1de374Slin wang - Sun Microsystems - Beijing China static int
149dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_flash_map(struct ath_hal *ah)
150dd1de374Slin wang - Sun Microsystems - Beijing China {
151dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG((ARN_DBG_EEPROM, "arn: ath9k_hw_flash_map(): "
152dd1de374Slin wang - Sun Microsystems - Beijing China 	    "using flash but eepom\n"));
153dd1de374Slin wang - Sun Microsystems - Beijing China 
154dd1de374Slin wang - Sun Microsystems - Beijing China 	return (0);
155dd1de374Slin wang - Sun Microsystems - Beijing China }
156dd1de374Slin wang - Sun Microsystems - Beijing China 
157dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t
158dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_flash_read(struct ath_hal *ah, uint32_t off, uint16_t *data)
159dd1de374Slin wang - Sun Microsystems - Beijing China {
160dd1de374Slin wang - Sun Microsystems - Beijing China 	*data = FLASH_READ(ah, off);
161dd1de374Slin wang - Sun Microsystems - Beijing China 
162dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
163dd1de374Slin wang - Sun Microsystems - Beijing China }
164dd1de374Slin wang - Sun Microsystems - Beijing China 
165dd1de374Slin wang - Sun Microsystems - Beijing China static inline boolean_t
166dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_nvram_read(struct ath_hal *ah, uint32_t off, uint16_t *data)
167dd1de374Slin wang - Sun Microsystems - Beijing China {
168dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ath9k_hw_use_flash(ah))
169dd1de374Slin wang - Sun Microsystems - Beijing China 		return (ath9k_hw_flash_read(ah, off, data));
170dd1de374Slin wang - Sun Microsystems - Beijing China 	else
171dd1de374Slin wang - Sun Microsystems - Beijing China 		return (ath9k_hw_eeprom_read(ah, off, data));
172dd1de374Slin wang - Sun Microsystems - Beijing China }
173dd1de374Slin wang - Sun Microsystems - Beijing China 
174dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t
175dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_fill_4k_eeprom(struct ath_hal *ah)
176dd1de374Slin wang - Sun Microsystems - Beijing China {
177dd1de374Slin wang - Sun Microsystems - Beijing China #define	SIZE_EEPROM_4K	(sizeof (struct ar5416_eeprom_4k) / sizeof (uint16_t))
178dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
179dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ar5416_eeprom_4k *eep = &ahp->ah_eeprom.map4k;
180dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t *eep_data;
181dd1de374Slin wang - Sun Microsystems - Beijing China 	int addr, eep_start_loc = 0;
182dd1de374Slin wang - Sun Microsystems - Beijing China 
183dd1de374Slin wang - Sun Microsystems - Beijing China 	eep_start_loc = 64;
184dd1de374Slin wang - Sun Microsystems - Beijing China 
185dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_use_flash(ah)) {
186dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_EEPROM,
187dd1de374Slin wang - Sun Microsystems - Beijing China 		    "Reading from EEPROM, not flash\n"));
188dd1de374Slin wang - Sun Microsystems - Beijing China 	}
189dd1de374Slin wang - Sun Microsystems - Beijing China 
190dd1de374Slin wang - Sun Microsystems - Beijing China 	eep_data = (uint16_t *)eep;
191dd1de374Slin wang - Sun Microsystems - Beijing China 
192dd1de374Slin wang - Sun Microsystems - Beijing China 	for (addr = 0; addr < SIZE_EEPROM_4K; addr++) {
193dd1de374Slin wang - Sun Microsystems - Beijing China 		if (!ath9k_hw_nvram_read(ah, addr + eep_start_loc, eep_data)) {
194dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_EEPROM,
195dd1de374Slin wang - Sun Microsystems - Beijing China 			    "Unable to read eeprom region \n"));
196dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_FALSE);
197dd1de374Slin wang - Sun Microsystems - Beijing China 		}
198dd1de374Slin wang - Sun Microsystems - Beijing China 		eep_data++;
199dd1de374Slin wang - Sun Microsystems - Beijing China 	}
200dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
201dd1de374Slin wang - Sun Microsystems - Beijing China #undef SIZE_EEPROM_4K
202dd1de374Slin wang - Sun Microsystems - Beijing China }
203dd1de374Slin wang - Sun Microsystems - Beijing China 
204dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t
205dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_fill_def_eeprom(struct ath_hal *ah)
206dd1de374Slin wang - Sun Microsystems - Beijing China {
207dd1de374Slin wang - Sun Microsystems - Beijing China #define	SIZE_EEPROM_DEF	(sizeof (struct ar5416_eeprom_def) / sizeof (uint16_t))
208dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
209dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ar5416_eeprom_def *eep = &ahp->ah_eeprom.def;
210dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t *eep_data;
211dd1de374Slin wang - Sun Microsystems - Beijing China 	int addr, ar5416_eep_start_loc = 0x100;
212dd1de374Slin wang - Sun Microsystems - Beijing China 
213dd1de374Slin wang - Sun Microsystems - Beijing China 	eep_data = (uint16_t *)eep;
214dd1de374Slin wang - Sun Microsystems - Beijing China 
215dd1de374Slin wang - Sun Microsystems - Beijing China 	for (addr = 0; addr < SIZE_EEPROM_DEF; addr++) {
216dd1de374Slin wang - Sun Microsystems - Beijing China 		if (!ath9k_hw_nvram_read(ah, addr + ar5416_eep_start_loc,
217dd1de374Slin wang - Sun Microsystems - Beijing China 		    eep_data)) {
218dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_EEPROM,
219dd1de374Slin wang - Sun Microsystems - Beijing China 			    "Unable to read eeprom region\n"));
220dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_FALSE);
221dd1de374Slin wang - Sun Microsystems - Beijing China 		}
222dd1de374Slin wang - Sun Microsystems - Beijing China 		eep_data++;
223dd1de374Slin wang - Sun Microsystems - Beijing China 	}
224dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
225dd1de374Slin wang - Sun Microsystems - Beijing China #undef SIZE_EEPROM_DEF
226dd1de374Slin wang - Sun Microsystems - Beijing China }
227dd1de374Slin wang - Sun Microsystems - Beijing China 
228dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t (*ath9k_fill_eeprom[]) (struct ath_hal *) = {
229dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_fill_def_eeprom,
230dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_fill_4k_eeprom
231dd1de374Slin wang - Sun Microsystems - Beijing China };
232dd1de374Slin wang - Sun Microsystems - Beijing China 
233dd1de374Slin wang - Sun Microsystems - Beijing China static inline boolean_t
234dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_fill_eeprom(struct ath_hal *ah)
235dd1de374Slin wang - Sun Microsystems - Beijing China {
236dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
237dd1de374Slin wang - Sun Microsystems - Beijing China 
238dd1de374Slin wang - Sun Microsystems - Beijing China 	return (ath9k_fill_eeprom[ahp->ah_eep_map](ah));
239dd1de374Slin wang - Sun Microsystems - Beijing China }
240dd1de374Slin wang - Sun Microsystems - Beijing China 
241dd1de374Slin wang - Sun Microsystems - Beijing China static int
242dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_check_def_eeprom(struct ath_hal *ah)
243dd1de374Slin wang - Sun Microsystems - Beijing China {
244dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
245dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ar5416_eeprom_def *eep =
246dd1de374Slin wang - Sun Microsystems - Beijing China 	    (struct ar5416_eeprom_def *)&ahp->ah_eeprom.def;
247dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t *eepdata, temp, magic, magic2;
248dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t sum = 0, el;
249dd1de374Slin wang - Sun Microsystems - Beijing China 	boolean_t need_swap = B_FALSE;
250dd1de374Slin wang - Sun Microsystems - Beijing China 	int i, addr, size;
251dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) {
252dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_EEPROM, "arn: "
253dd1de374Slin wang - Sun Microsystems - Beijing China 		    "%s: Reading Magic # failed\n", __func__));
254dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
255dd1de374Slin wang - Sun Microsystems - Beijing China 	}
256dd1de374Slin wang - Sun Microsystems - Beijing China 
257dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_use_flash(ah)) {
258dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_EEPROM, "ath9k: "
259dd1de374Slin wang - Sun Microsystems - Beijing China 		    "%s: Read Magic = 0x%04X\n", __func__, magic));
260dd1de374Slin wang - Sun Microsystems - Beijing China 
261dd1de374Slin wang - Sun Microsystems - Beijing China 		if (magic != AR5416_EEPROM_MAGIC) {
262dd1de374Slin wang - Sun Microsystems - Beijing China 			magic2 = swab16(magic);
263dd1de374Slin wang - Sun Microsystems - Beijing China 
264dd1de374Slin wang - Sun Microsystems - Beijing China 			if (magic2 == AR5416_EEPROM_MAGIC) {
265dd1de374Slin wang - Sun Microsystems - Beijing China 				size = sizeof (struct ar5416_eeprom_def);
266dd1de374Slin wang - Sun Microsystems - Beijing China 				need_swap = B_TRUE;
267dd1de374Slin wang - Sun Microsystems - Beijing China 				eepdata = (uint16_t *)(&ahp->ah_eeprom);
268dd1de374Slin wang - Sun Microsystems - Beijing China 
269dd1de374Slin wang - Sun Microsystems - Beijing China 				for (addr = 0; addr < size / sizeof (uint16_t);
270dd1de374Slin wang - Sun Microsystems - Beijing China 				    addr++) {
271dd1de374Slin wang - Sun Microsystems - Beijing China 					temp = swab16(*eepdata);
272dd1de374Slin wang - Sun Microsystems - Beijing China 					*eepdata = temp;
273dd1de374Slin wang - Sun Microsystems - Beijing China 					eepdata++;
274dd1de374Slin wang - Sun Microsystems - Beijing China 
275dd1de374Slin wang - Sun Microsystems - Beijing China 					ARN_DBG((ARN_DBG_EEPROM,
276dd1de374Slin wang - Sun Microsystems - Beijing China 					    "0x%04X  ", *eepdata));
277dd1de374Slin wang - Sun Microsystems - Beijing China 
278dd1de374Slin wang - Sun Microsystems - Beijing China 					if (((addr + 1) % 6) == 0)
279dd1de374Slin wang - Sun Microsystems - Beijing China 						ARN_DBG((ARN_DBG_EEPROM,
280dd1de374Slin wang - Sun Microsystems - Beijing China 						    "arn: "
281dd1de374Slin wang - Sun Microsystems - Beijing China 						    "%s\n", __func__));
282dd1de374Slin wang - Sun Microsystems - Beijing China 				}
283dd1de374Slin wang - Sun Microsystems - Beijing China 			} else {
284dd1de374Slin wang - Sun Microsystems - Beijing China 				ARN_DBG((ARN_DBG_EEPROM,
285dd1de374Slin wang - Sun Microsystems - Beijing China 				    "Invalid EEPROM Magic. "
286dd1de374Slin wang - Sun Microsystems - Beijing China 				    "endianness mismatch.\n"));
287dd1de374Slin wang - Sun Microsystems - Beijing China 				return (EINVAL);
288dd1de374Slin wang - Sun Microsystems - Beijing China 			}
289dd1de374Slin wang - Sun Microsystems - Beijing China 		}
290dd1de374Slin wang - Sun Microsystems - Beijing China 	}
291dd1de374Slin wang - Sun Microsystems - Beijing China 
292dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG((ARN_DBG_EEPROM, "need_swap = %s.\n",
293dd1de374Slin wang - Sun Microsystems - Beijing China 	    need_swap ? "TRUE" : "FALSE"));
294dd1de374Slin wang - Sun Microsystems - Beijing China 
295dd1de374Slin wang - Sun Microsystems - Beijing China 	if (need_swap)
296dd1de374Slin wang - Sun Microsystems - Beijing China 		el = swab16(ahp->ah_eeprom.def.baseEepHeader.length);
297dd1de374Slin wang - Sun Microsystems - Beijing China 	else
298dd1de374Slin wang - Sun Microsystems - Beijing China 		el = ahp->ah_eeprom.def.baseEepHeader.length;
299dd1de374Slin wang - Sun Microsystems - Beijing China 
300dd1de374Slin wang - Sun Microsystems - Beijing China 	if (el > sizeof (struct ar5416_eeprom_def))
301dd1de374Slin wang - Sun Microsystems - Beijing China 		el = sizeof (struct ar5416_eeprom_def) / sizeof (uint16_t);
302dd1de374Slin wang - Sun Microsystems - Beijing China 	else
303dd1de374Slin wang - Sun Microsystems - Beijing China 		el = el / sizeof (uint16_t);
304dd1de374Slin wang - Sun Microsystems - Beijing China 
305dd1de374Slin wang - Sun Microsystems - Beijing China 	eepdata = (uint16_t *)(&ahp->ah_eeprom);
306dd1de374Slin wang - Sun Microsystems - Beijing China 
307dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < el; i++)
308dd1de374Slin wang - Sun Microsystems - Beijing China 		sum ^= *eepdata++;
309dd1de374Slin wang - Sun Microsystems - Beijing China 
310dd1de374Slin wang - Sun Microsystems - Beijing China 	if (need_swap) {
311dd1de374Slin wang - Sun Microsystems - Beijing China 		uint32_t integer, j;
312dd1de374Slin wang - Sun Microsystems - Beijing China 		uint16_t word;
313dd1de374Slin wang - Sun Microsystems - Beijing China 
314dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_EEPROM,
315dd1de374Slin wang - Sun Microsystems - Beijing China 		    "EEPROM Endianness is not native.. Changing \n"));
316dd1de374Slin wang - Sun Microsystems - Beijing China 
317dd1de374Slin wang - Sun Microsystems - Beijing China 		word = swab16(eep->baseEepHeader.length);
318dd1de374Slin wang - Sun Microsystems - Beijing China 		eep->baseEepHeader.length = word;
319dd1de374Slin wang - Sun Microsystems - Beijing China 
320dd1de374Slin wang - Sun Microsystems - Beijing China 		word = swab16(eep->baseEepHeader.checksum);
321dd1de374Slin wang - Sun Microsystems - Beijing China 		eep->baseEepHeader.checksum = word;
322dd1de374Slin wang - Sun Microsystems - Beijing China 
323dd1de374Slin wang - Sun Microsystems - Beijing China 		word = swab16(eep->baseEepHeader.version);
324dd1de374Slin wang - Sun Microsystems - Beijing China 		eep->baseEepHeader.version = word;
325dd1de374Slin wang - Sun Microsystems - Beijing China 
326dd1de374Slin wang - Sun Microsystems - Beijing China 		word = swab16(eep->baseEepHeader.regDmn[0]);
327dd1de374Slin wang - Sun Microsystems - Beijing China 		eep->baseEepHeader.regDmn[0] = word;
328dd1de374Slin wang - Sun Microsystems - Beijing China 
329dd1de374Slin wang - Sun Microsystems - Beijing China 		word = swab16(eep->baseEepHeader.regDmn[1]);
330dd1de374Slin wang - Sun Microsystems - Beijing China 		eep->baseEepHeader.regDmn[1] = word;
331dd1de374Slin wang - Sun Microsystems - Beijing China 
332dd1de374Slin wang - Sun Microsystems - Beijing China 		word = swab16(eep->baseEepHeader.rfSilent);
333dd1de374Slin wang - Sun Microsystems - Beijing China 		eep->baseEepHeader.rfSilent = word;
334dd1de374Slin wang - Sun Microsystems - Beijing China 
335dd1de374Slin wang - Sun Microsystems - Beijing China 		word = swab16(eep->baseEepHeader.blueToothOptions);
336dd1de374Slin wang - Sun Microsystems - Beijing China 		eep->baseEepHeader.blueToothOptions = word;
337dd1de374Slin wang - Sun Microsystems - Beijing China 
338dd1de374Slin wang - Sun Microsystems - Beijing China 		word = swab16(eep->baseEepHeader.deviceCap);
339dd1de374Slin wang - Sun Microsystems - Beijing China 		eep->baseEepHeader.deviceCap = word;
340dd1de374Slin wang - Sun Microsystems - Beijing China 
341dd1de374Slin wang - Sun Microsystems - Beijing China 		for (j = 0; j < ARRAY_SIZE(eep->modalHeader); j++) {
342dd1de374Slin wang - Sun Microsystems - Beijing China 			struct modal_eep_header *pModal =
343dd1de374Slin wang - Sun Microsystems - Beijing China 			    &eep->modalHeader[j];
344dd1de374Slin wang - Sun Microsystems - Beijing China 			integer = swab32(pModal->antCtrlCommon);
345dd1de374Slin wang - Sun Microsystems - Beijing China 			pModal->antCtrlCommon = integer;
346dd1de374Slin wang - Sun Microsystems - Beijing China 
347dd1de374Slin wang - Sun Microsystems - Beijing China 			for (i = 0; i < AR5416_MAX_CHAINS; i++) {
348dd1de374Slin wang - Sun Microsystems - Beijing China 				integer = swab32(pModal->antCtrlChain[i]);
349dd1de374Slin wang - Sun Microsystems - Beijing China 				pModal->antCtrlChain[i] = integer;
350dd1de374Slin wang - Sun Microsystems - Beijing China 			}
351dd1de374Slin wang - Sun Microsystems - Beijing China 
352dd1de374Slin wang - Sun Microsystems - Beijing China 			for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
353dd1de374Slin wang - Sun Microsystems - Beijing China 				word = swab16(pModal->spurChans[i].spurChan);
354dd1de374Slin wang - Sun Microsystems - Beijing China 				pModal->spurChans[i].spurChan = word;
355dd1de374Slin wang - Sun Microsystems - Beijing China 			}
356dd1de374Slin wang - Sun Microsystems - Beijing China 		}
357dd1de374Slin wang - Sun Microsystems - Beijing China 	}
358dd1de374Slin wang - Sun Microsystems - Beijing China 
359dd1de374Slin wang - Sun Microsystems - Beijing China 	if (sum != 0xffff || ar5416_get_eep_ver(ahp) != AR5416_EEP_VER ||
360dd1de374Slin wang - Sun Microsystems - Beijing China 	    ar5416_get_eep_rev(ahp) < AR5416_EEP_NO_BACK_VER) {
361dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_EEPROM,
362dd1de374Slin wang - Sun Microsystems - Beijing China 		    "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
363dd1de374Slin wang - Sun Microsystems - Beijing China 		    sum, ar5416_get_eep_ver(ahp)));
364dd1de374Slin wang - Sun Microsystems - Beijing China 		return (EINVAL);
365dd1de374Slin wang - Sun Microsystems - Beijing China 	}
366dd1de374Slin wang - Sun Microsystems - Beijing China 
367dd1de374Slin wang - Sun Microsystems - Beijing China 	return (0);
368dd1de374Slin wang - Sun Microsystems - Beijing China }
369dd1de374Slin wang - Sun Microsystems - Beijing China 
370dd1de374Slin wang - Sun Microsystems - Beijing China static int
371dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_check_4k_eeprom(struct ath_hal *ah)
372dd1de374Slin wang - Sun Microsystems - Beijing China {
373dd1de374Slin wang - Sun Microsystems - Beijing China #define	EEPROM_4K_SIZE	(sizeof (struct ar5416_eeprom_4k) / sizeof (uint16_t))
374dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
375dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ar5416_eeprom_4k *eep =
376dd1de374Slin wang - Sun Microsystems - Beijing China 	    (struct ar5416_eeprom_4k *)&ahp->ah_eeprom.map4k;
377dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t *eepdata, temp, magic, magic2;
378dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t sum = 0, el;
379dd1de374Slin wang - Sun Microsystems - Beijing China 	boolean_t need_swap = B_FALSE;
380dd1de374Slin wang - Sun Microsystems - Beijing China 	int i, addr;
381dd1de374Slin wang - Sun Microsystems - Beijing China 
382dd1de374Slin wang - Sun Microsystems - Beijing China 
383dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_use_flash(ah)) {
384dd1de374Slin wang - Sun Microsystems - Beijing China 
385dd1de374Slin wang - Sun Microsystems - Beijing China 		if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET,
386dd1de374Slin wang - Sun Microsystems - Beijing China 		    &magic)) {
387dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_EEPROM,
388dd1de374Slin wang - Sun Microsystems - Beijing China 			    "Reading Magic # failed\n"));
389dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_FALSE);
390dd1de374Slin wang - Sun Microsystems - Beijing China 		}
391dd1de374Slin wang - Sun Microsystems - Beijing China 
392dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_EEPROM,
393dd1de374Slin wang - Sun Microsystems - Beijing China 		    "Read Magic = 0x%04X\n", magic));
394dd1de374Slin wang - Sun Microsystems - Beijing China 
395dd1de374Slin wang - Sun Microsystems - Beijing China 		if (magic != AR5416_EEPROM_MAGIC) {
396dd1de374Slin wang - Sun Microsystems - Beijing China 			magic2 = swab16(magic);
397dd1de374Slin wang - Sun Microsystems - Beijing China 
398dd1de374Slin wang - Sun Microsystems - Beijing China 			if (magic2 == AR5416_EEPROM_MAGIC) {
399dd1de374Slin wang - Sun Microsystems - Beijing China 				need_swap = B_TRUE;
400dd1de374Slin wang - Sun Microsystems - Beijing China 				eepdata = (uint16_t *)(&ahp->ah_eeprom);
401dd1de374Slin wang - Sun Microsystems - Beijing China 
402dd1de374Slin wang - Sun Microsystems - Beijing China 				for (addr = 0; addr < EEPROM_4K_SIZE; addr++) {
403dd1de374Slin wang - Sun Microsystems - Beijing China 					temp = swab16(*eepdata);
404dd1de374Slin wang - Sun Microsystems - Beijing China 					*eepdata = temp;
405dd1de374Slin wang - Sun Microsystems - Beijing China 					eepdata++;
406dd1de374Slin wang - Sun Microsystems - Beijing China 
407dd1de374Slin wang - Sun Microsystems - Beijing China 					ARN_DBG((ARN_DBG_EEPROM,
408dd1de374Slin wang - Sun Microsystems - Beijing China 					    "0x%04X  ", *eepdata));
409dd1de374Slin wang - Sun Microsystems - Beijing China 
410dd1de374Slin wang - Sun Microsystems - Beijing China 					if (((addr + 1) % 6) == 0)
411dd1de374Slin wang - Sun Microsystems - Beijing China 						ARN_DBG((ARN_DBG_EEPROM, "\n"));
412dd1de374Slin wang - Sun Microsystems - Beijing China 				}
413dd1de374Slin wang - Sun Microsystems - Beijing China 			} else {
414dd1de374Slin wang - Sun Microsystems - Beijing China 				ARN_DBG((ARN_DBG_EEPROM,
415dd1de374Slin wang - Sun Microsystems - Beijing China 				    "Invalid EEPROM Magic. "
416dd1de374Slin wang - Sun Microsystems - Beijing China 				    "endianness mismatch.\n"));
417dd1de374Slin wang - Sun Microsystems - Beijing China 				return (EINVAL);
418dd1de374Slin wang - Sun Microsystems - Beijing China 			}
419dd1de374Slin wang - Sun Microsystems - Beijing China 		}
420dd1de374Slin wang - Sun Microsystems - Beijing China 	}
421dd1de374Slin wang - Sun Microsystems - Beijing China 
422dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG((ARN_DBG_EEPROM, "need_swap = %s.\n",
423dd1de374Slin wang - Sun Microsystems - Beijing China 	    need_swap ? "True" : "False"));
424dd1de374Slin wang - Sun Microsystems - Beijing China 
425dd1de374Slin wang - Sun Microsystems - Beijing China 	if (need_swap)
426dd1de374Slin wang - Sun Microsystems - Beijing China 		el = swab16(ahp->ah_eeprom.map4k.baseEepHeader.length);
427dd1de374Slin wang - Sun Microsystems - Beijing China 	else
428dd1de374Slin wang - Sun Microsystems - Beijing China 		el = ahp->ah_eeprom.map4k.baseEepHeader.length;
429dd1de374Slin wang - Sun Microsystems - Beijing China 
430dd1de374Slin wang - Sun Microsystems - Beijing China 	if (el > sizeof (struct ar5416_eeprom_def))
431dd1de374Slin wang - Sun Microsystems - Beijing China 		el = sizeof (struct ar5416_eeprom_4k) / sizeof (uint16_t);
432dd1de374Slin wang - Sun Microsystems - Beijing China 	else
433dd1de374Slin wang - Sun Microsystems - Beijing China 		el = el / sizeof (uint16_t);
434dd1de374Slin wang - Sun Microsystems - Beijing China 
435dd1de374Slin wang - Sun Microsystems - Beijing China 	eepdata = (uint16_t *)(&ahp->ah_eeprom);
436dd1de374Slin wang - Sun Microsystems - Beijing China 
437dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < el; i++)
438dd1de374Slin wang - Sun Microsystems - Beijing China 		sum ^= *eepdata++;
439dd1de374Slin wang - Sun Microsystems - Beijing China 
440dd1de374Slin wang - Sun Microsystems - Beijing China 	if (need_swap) {
441dd1de374Slin wang - Sun Microsystems - Beijing China 		uint32_t integer;
442dd1de374Slin wang - Sun Microsystems - Beijing China 		uint16_t word;
443dd1de374Slin wang - Sun Microsystems - Beijing China 
444dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_EEPROM,
445dd1de374Slin wang - Sun Microsystems - Beijing China 		    "EEPROM Endianness is not native.. Changing \n"));
446dd1de374Slin wang - Sun Microsystems - Beijing China 
447dd1de374Slin wang - Sun Microsystems - Beijing China 		word = swab16(eep->baseEepHeader.length);
448dd1de374Slin wang - Sun Microsystems - Beijing China 		eep->baseEepHeader.length = word;
449dd1de374Slin wang - Sun Microsystems - Beijing China 
450dd1de374Slin wang - Sun Microsystems - Beijing China 		word = swab16(eep->baseEepHeader.checksum);
451dd1de374Slin wang - Sun Microsystems - Beijing China 		eep->baseEepHeader.checksum = word;
452dd1de374Slin wang - Sun Microsystems - Beijing China 
453dd1de374Slin wang - Sun Microsystems - Beijing China 		word = swab16(eep->baseEepHeader.version);
454dd1de374Slin wang - Sun Microsystems - Beijing China 		eep->baseEepHeader.version = word;
455dd1de374Slin wang - Sun Microsystems - Beijing China 
456dd1de374Slin wang - Sun Microsystems - Beijing China 		word = swab16(eep->baseEepHeader.regDmn[0]);
457dd1de374Slin wang - Sun Microsystems - Beijing China 		eep->baseEepHeader.regDmn[0] = word;
458dd1de374Slin wang - Sun Microsystems - Beijing China 
459dd1de374Slin wang - Sun Microsystems - Beijing China 		word = swab16(eep->baseEepHeader.regDmn[1]);
460dd1de374Slin wang - Sun Microsystems - Beijing China 		eep->baseEepHeader.regDmn[1] = word;
461dd1de374Slin wang - Sun Microsystems - Beijing China 
462dd1de374Slin wang - Sun Microsystems - Beijing China 		word = swab16(eep->baseEepHeader.rfSilent);
463dd1de374Slin wang - Sun Microsystems - Beijing China 		eep->baseEepHeader.rfSilent = word;
464dd1de374Slin wang - Sun Microsystems - Beijing China 
465dd1de374Slin wang - Sun Microsystems - Beijing China 		word = swab16(eep->baseEepHeader.blueToothOptions);
466dd1de374Slin wang - Sun Microsystems - Beijing China 		eep->baseEepHeader.blueToothOptions = word;
467dd1de374Slin wang - Sun Microsystems - Beijing China 
468dd1de374Slin wang - Sun Microsystems - Beijing China 		word = swab16(eep->baseEepHeader.deviceCap);
469dd1de374Slin wang - Sun Microsystems - Beijing China 		eep->baseEepHeader.deviceCap = word;
470dd1de374Slin wang - Sun Microsystems - Beijing China 
471dd1de374Slin wang - Sun Microsystems - Beijing China 		integer = swab32(eep->modalHeader.antCtrlCommon);
472dd1de374Slin wang - Sun Microsystems - Beijing China 		eep->modalHeader.antCtrlCommon = integer;
473dd1de374Slin wang - Sun Microsystems - Beijing China 
474dd1de374Slin wang - Sun Microsystems - Beijing China 		for (i = 0; i < AR5416_MAX_CHAINS; i++) {
475dd1de374Slin wang - Sun Microsystems - Beijing China 			integer = swab32(eep->modalHeader.antCtrlChain[i]);
476dd1de374Slin wang - Sun Microsystems - Beijing China 			eep->modalHeader.antCtrlChain[i] = integer;
477dd1de374Slin wang - Sun Microsystems - Beijing China 		}
478dd1de374Slin wang - Sun Microsystems - Beijing China 
479dd1de374Slin wang - Sun Microsystems - Beijing China 		for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
480dd1de374Slin wang - Sun Microsystems - Beijing China 			word = swab16(eep->modalHeader.spurChans[i].spurChan);
481dd1de374Slin wang - Sun Microsystems - Beijing China 			eep->modalHeader.spurChans[i].spurChan = word;
482dd1de374Slin wang - Sun Microsystems - Beijing China 		}
483dd1de374Slin wang - Sun Microsystems - Beijing China 	}
484dd1de374Slin wang - Sun Microsystems - Beijing China 
485dd1de374Slin wang - Sun Microsystems - Beijing China 	if (sum != 0xffff || ar5416_get_eep4k_ver(ahp) != AR5416_EEP_VER ||
486dd1de374Slin wang - Sun Microsystems - Beijing China 	    ar5416_get_eep4k_rev(ahp) < AR5416_EEP_NO_BACK_VER) {
487dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_EEPROM,
488dd1de374Slin wang - Sun Microsystems - Beijing China 		    "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
489dd1de374Slin wang - Sun Microsystems - Beijing China 		    sum, ar5416_get_eep4k_ver(ahp)));
490dd1de374Slin wang - Sun Microsystems - Beijing China 		return (EINVAL);
491dd1de374Slin wang - Sun Microsystems - Beijing China 	}
492dd1de374Slin wang - Sun Microsystems - Beijing China 
493dd1de374Slin wang - Sun Microsystems - Beijing China 	return (0);
494dd1de374Slin wang - Sun Microsystems - Beijing China #undef EEPROM_4K_SIZE
495dd1de374Slin wang - Sun Microsystems - Beijing China }
496dd1de374Slin wang - Sun Microsystems - Beijing China 
497dd1de374Slin wang - Sun Microsystems - Beijing China static int
498dd1de374Slin wang - Sun Microsystems - Beijing China (*ath9k_check_eeprom[]) (struct ath_hal *) = {
499dd1de374Slin wang - Sun Microsystems - Beijing China     ath9k_hw_check_def_eeprom,
500dd1de374Slin wang - Sun Microsystems - Beijing China     ath9k_hw_check_4k_eeprom
501dd1de374Slin wang - Sun Microsystems - Beijing China };
502dd1de374Slin wang - Sun Microsystems - Beijing China 
503dd1de374Slin wang - Sun Microsystems - Beijing China static inline int
504dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_check_eeprom(struct ath_hal *ah)
505dd1de374Slin wang - Sun Microsystems - Beijing China {
506dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
507dd1de374Slin wang - Sun Microsystems - Beijing China 
508dd1de374Slin wang - Sun Microsystems - Beijing China 	return (ath9k_check_eeprom[ahp->ah_eep_map](ah));
509dd1de374Slin wang - Sun Microsystems - Beijing China }
510dd1de374Slin wang - Sun Microsystems - Beijing China 
511dd1de374Slin wang - Sun Microsystems - Beijing China static inline boolean_t
512dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_fill_vpd_table(uint8_t pwrMin, uint8_t pwrMax, uint8_t *pPwrList,
513dd1de374Slin wang - Sun Microsystems - Beijing China     uint8_t *pVpdList, uint16_t numIntercepts, uint8_t *pRetVpdList)
514dd1de374Slin wang - Sun Microsystems - Beijing China {
515dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t i, k;
516dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t currPwr = pwrMin;
517dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t idxL = 0, idxR = 0;
518dd1de374Slin wang - Sun Microsystems - Beijing China 
519dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i <= (pwrMax - pwrMin) / 2; i++) {
520dd1de374Slin wang - Sun Microsystems - Beijing China 		(void) ath9k_hw_get_lower_upper_index(currPwr, pPwrList,
521dd1de374Slin wang - Sun Microsystems - Beijing China 		    numIntercepts, &(idxL), &(idxR));
522dd1de374Slin wang - Sun Microsystems - Beijing China 		if (idxR < 1)
523dd1de374Slin wang - Sun Microsystems - Beijing China 			idxR = 1;
524dd1de374Slin wang - Sun Microsystems - Beijing China 		if (idxL == numIntercepts - 1)
525dd1de374Slin wang - Sun Microsystems - Beijing China 			idxL = (uint16_t)(numIntercepts - 2);
526dd1de374Slin wang - Sun Microsystems - Beijing China 		if (pPwrList[idxL] == pPwrList[idxR])
527dd1de374Slin wang - Sun Microsystems - Beijing China 			k = pVpdList[idxL];
528dd1de374Slin wang - Sun Microsystems - Beijing China 		else
529dd1de374Slin wang - Sun Microsystems - Beijing China 			k = (uint16_t)
530dd1de374Slin wang - Sun Microsystems - Beijing China 			    (((currPwr - pPwrList[idxL]) * pVpdList[idxR] +
531dd1de374Slin wang - Sun Microsystems - Beijing China 			    (pPwrList[idxR] - currPwr) * pVpdList[idxL]) /
532dd1de374Slin wang - Sun Microsystems - Beijing China 			    (pPwrList[idxR] - pPwrList[idxL]));
533dd1de374Slin wang - Sun Microsystems - Beijing China 		pRetVpdList[i] = (uint8_t)k;
534dd1de374Slin wang - Sun Microsystems - Beijing China 		currPwr += 2;
535dd1de374Slin wang - Sun Microsystems - Beijing China 	}
536dd1de374Slin wang - Sun Microsystems - Beijing China 
537dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
538dd1de374Slin wang - Sun Microsystems - Beijing China }
539dd1de374Slin wang - Sun Microsystems - Beijing China 
540dd1de374Slin wang - Sun Microsystems - Beijing China static void
541dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_get_4k_gain_boundaries_pdadcs(struct ath_hal *ah,
542dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan,
543dd1de374Slin wang - Sun Microsystems - Beijing China     struct cal_data_per_freq_4k *pRawDataSet,
544dd1de374Slin wang - Sun Microsystems - Beijing China     uint8_t *bChans, uint16_t availPiers,
545dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t tPdGainOverlap, int16_t *pMinCalPower,
546dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t *pPdGainBoundaries, uint8_t *pPDADCValues,
547dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t numXpdGains)
548dd1de374Slin wang - Sun Microsystems - Beijing China {
549dd1de374Slin wang - Sun Microsystems - Beijing China #define	TMP_VAL_VPD_TABLE \
550dd1de374Slin wang - Sun Microsystems - Beijing China 	((vpdTableI[i][sizeCurrVpdTable - 1] + (ss - maxIndex + 1) * vpdStep));
551dd1de374Slin wang - Sun Microsystems - Beijing China 	int i, j, k;
552dd1de374Slin wang - Sun Microsystems - Beijing China 	int16_t ss;
553dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t idxL = 0, idxR = 0, numPiers;
554dd1de374Slin wang - Sun Microsystems - Beijing China 	static uint8_t vpdTableL[AR5416_EEP4K_NUM_PD_GAINS]
555dd1de374Slin wang - Sun Microsystems - Beijing China 	    [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
556dd1de374Slin wang - Sun Microsystems - Beijing China 	static uint8_t vpdTableR[AR5416_EEP4K_NUM_PD_GAINS]
557dd1de374Slin wang - Sun Microsystems - Beijing China 	    [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
558dd1de374Slin wang - Sun Microsystems - Beijing China 	static uint8_t vpdTableI[AR5416_EEP4K_NUM_PD_GAINS]
559dd1de374Slin wang - Sun Microsystems - Beijing China 	    [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
560dd1de374Slin wang - Sun Microsystems - Beijing China 
561dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t *pVpdL, *pVpdR, *pPwrL, *pPwrR;
562dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t minPwrT4[AR5416_EEP4K_NUM_PD_GAINS];
563dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t maxPwrT4[AR5416_EEP4K_NUM_PD_GAINS];
564dd1de374Slin wang - Sun Microsystems - Beijing China 	int16_t vpdStep;
565dd1de374Slin wang - Sun Microsystems - Beijing China 	int16_t tmpVal;
566dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t sizeCurrVpdTable, maxIndex, tgtIndex;
567dd1de374Slin wang - Sun Microsystems - Beijing China 	boolean_t match;
568dd1de374Slin wang - Sun Microsystems - Beijing China 	int16_t minDelta = 0;
569dd1de374Slin wang - Sun Microsystems - Beijing China 	struct chan_centers centers;
570dd1de374Slin wang - Sun Microsystems - Beijing China #define	PD_GAIN_BOUNDARY_DEFAULT	58;
571dd1de374Slin wang - Sun Microsystems - Beijing China 
572dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_get_channel_centers(ah, chan, &centers);
573dd1de374Slin wang - Sun Microsystems - Beijing China 
574dd1de374Slin wang - Sun Microsystems - Beijing China 	for (numPiers = 0; numPiers < availPiers; numPiers++) {
575dd1de374Slin wang - Sun Microsystems - Beijing China 		if (bChans[numPiers] == AR5416_BCHAN_UNUSED)
576dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
577dd1de374Slin wang - Sun Microsystems - Beijing China 	}
578dd1de374Slin wang - Sun Microsystems - Beijing China 
579dd1de374Slin wang - Sun Microsystems - Beijing China 	match = ath9k_hw_get_lower_upper_index(
580dd1de374Slin wang - Sun Microsystems - Beijing China 	    (uint8_t)FREQ2FBIN(centers.synth_center,
581dd1de374Slin wang - Sun Microsystems - Beijing China 	    IS_CHAN_2GHZ(chan)), bChans, numPiers,
582dd1de374Slin wang - Sun Microsystems - Beijing China 	    &idxL, &idxR);
583dd1de374Slin wang - Sun Microsystems - Beijing China 
584dd1de374Slin wang - Sun Microsystems - Beijing China 	if (match) {
585dd1de374Slin wang - Sun Microsystems - Beijing China 		for (i = 0; i < numXpdGains; i++) {
586dd1de374Slin wang - Sun Microsystems - Beijing China 			minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0];
587dd1de374Slin wang - Sun Microsystems - Beijing China 			maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4];
588dd1de374Slin wang - Sun Microsystems - Beijing China 			(void) ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
589dd1de374Slin wang - Sun Microsystems - Beijing China 			    pRawDataSet[idxL].pwrPdg[i],
590dd1de374Slin wang - Sun Microsystems - Beijing China 			    pRawDataSet[idxL].vpdPdg[i],
591dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR5416_EEP4K_PD_GAIN_ICEPTS,
592dd1de374Slin wang - Sun Microsystems - Beijing China 			    vpdTableI[i]);
593dd1de374Slin wang - Sun Microsystems - Beijing China 		}
594dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
595dd1de374Slin wang - Sun Microsystems - Beijing China 		for (i = 0; i < numXpdGains; i++) {
596dd1de374Slin wang - Sun Microsystems - Beijing China 			pVpdL = pRawDataSet[idxL].vpdPdg[i];
597dd1de374Slin wang - Sun Microsystems - Beijing China 			pPwrL = pRawDataSet[idxL].pwrPdg[i];
598dd1de374Slin wang - Sun Microsystems - Beijing China 			pVpdR = pRawDataSet[idxR].vpdPdg[i];
599dd1de374Slin wang - Sun Microsystems - Beijing China 			pPwrR = pRawDataSet[idxR].pwrPdg[i];
600dd1de374Slin wang - Sun Microsystems - Beijing China 
601dd1de374Slin wang - Sun Microsystems - Beijing China 			minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
602dd1de374Slin wang - Sun Microsystems - Beijing China 
603dd1de374Slin wang - Sun Microsystems - Beijing China 			maxPwrT4[i] =
604dd1de374Slin wang - Sun Microsystems - Beijing China 			    min(pPwrL[AR5416_EEP4K_PD_GAIN_ICEPTS - 1],
605dd1de374Slin wang - Sun Microsystems - Beijing China 			    pPwrR[AR5416_EEP4K_PD_GAIN_ICEPTS - 1]);
606dd1de374Slin wang - Sun Microsystems - Beijing China 
607dd1de374Slin wang - Sun Microsystems - Beijing China 
608dd1de374Slin wang - Sun Microsystems - Beijing China 			(void) ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
609dd1de374Slin wang - Sun Microsystems - Beijing China 			    pPwrL, pVpdL,
610dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR5416_EEP4K_PD_GAIN_ICEPTS,
611dd1de374Slin wang - Sun Microsystems - Beijing China 			    vpdTableL[i]);
612dd1de374Slin wang - Sun Microsystems - Beijing China 			(void) ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
613dd1de374Slin wang - Sun Microsystems - Beijing China 			    pPwrR, pVpdR,
614dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR5416_EEP4K_PD_GAIN_ICEPTS,
615dd1de374Slin wang - Sun Microsystems - Beijing China 			    vpdTableR[i]);
616dd1de374Slin wang - Sun Microsystems - Beijing China 
617dd1de374Slin wang - Sun Microsystems - Beijing China 			for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
618dd1de374Slin wang - Sun Microsystems - Beijing China 				vpdTableI[i][j] =
619dd1de374Slin wang - Sun Microsystems - Beijing China 				    (uint8_t)(ath9k_hw_interpolate((uint16_t)
620dd1de374Slin wang - Sun Microsystems - Beijing China 				    FREQ2FBIN(centers.
621dd1de374Slin wang - Sun Microsystems - Beijing China 				    synth_center,
622dd1de374Slin wang - Sun Microsystems - Beijing China 				    IS_CHAN_2GHZ
623dd1de374Slin wang - Sun Microsystems - Beijing China 				    (chan)),
624dd1de374Slin wang - Sun Microsystems - Beijing China 				    bChans[idxL], bChans[idxR],
625dd1de374Slin wang - Sun Microsystems - Beijing China 				    vpdTableL[i][j], vpdTableR[i][j]));
626dd1de374Slin wang - Sun Microsystems - Beijing China 			}
627dd1de374Slin wang - Sun Microsystems - Beijing China 		}
628dd1de374Slin wang - Sun Microsystems - Beijing China 	}
629dd1de374Slin wang - Sun Microsystems - Beijing China 
630dd1de374Slin wang - Sun Microsystems - Beijing China 	*pMinCalPower = (int16_t)(minPwrT4[0] / 2);
631dd1de374Slin wang - Sun Microsystems - Beijing China 
632dd1de374Slin wang - Sun Microsystems - Beijing China 	k = 0;
633dd1de374Slin wang - Sun Microsystems - Beijing China 
634dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < numXpdGains; i++) {
635dd1de374Slin wang - Sun Microsystems - Beijing China 		if (i == (numXpdGains - 1))
636dd1de374Slin wang - Sun Microsystems - Beijing China 			pPdGainBoundaries[i] =
637dd1de374Slin wang - Sun Microsystems - Beijing China 			    (uint16_t)(maxPwrT4[i] / 2);
638dd1de374Slin wang - Sun Microsystems - Beijing China 		else
639dd1de374Slin wang - Sun Microsystems - Beijing China 			pPdGainBoundaries[i] =
640dd1de374Slin wang - Sun Microsystems - Beijing China 			    (uint16_t)((maxPwrT4[i] + minPwrT4[i + 1]) / 4);
641dd1de374Slin wang - Sun Microsystems - Beijing China 
642dd1de374Slin wang - Sun Microsystems - Beijing China 		pPdGainBoundaries[i] =
643dd1de374Slin wang - Sun Microsystems - Beijing China 		    min((uint16_t)AR5416_MAX_RATE_POWER, pPdGainBoundaries[i]);
644dd1de374Slin wang - Sun Microsystems - Beijing China 
645dd1de374Slin wang - Sun Microsystems - Beijing China 		if ((i == 0) && !AR_SREV_5416_V20_OR_LATER(ah)) {
646dd1de374Slin wang - Sun Microsystems - Beijing China 			minDelta = pPdGainBoundaries[0] - 23;
647dd1de374Slin wang - Sun Microsystems - Beijing China 			pPdGainBoundaries[0] = 23;
648dd1de374Slin wang - Sun Microsystems - Beijing China 		} else {
649dd1de374Slin wang - Sun Microsystems - Beijing China 			minDelta = 0;
650dd1de374Slin wang - Sun Microsystems - Beijing China 		}
651dd1de374Slin wang - Sun Microsystems - Beijing China 
652dd1de374Slin wang - Sun Microsystems - Beijing China 		if (i == 0) {
653dd1de374Slin wang - Sun Microsystems - Beijing China 			if (AR_SREV_9280_10_OR_LATER(ah))
654dd1de374Slin wang - Sun Microsystems - Beijing China 				ss = (int16_t)(0 - (minPwrT4[i] / 2));
655dd1de374Slin wang - Sun Microsystems - Beijing China 			else
656dd1de374Slin wang - Sun Microsystems - Beijing China 				ss = 0;
657dd1de374Slin wang - Sun Microsystems - Beijing China 		} else {
658dd1de374Slin wang - Sun Microsystems - Beijing China 			ss = (int16_t)((pPdGainBoundaries[i - 1] -
659dd1de374Slin wang - Sun Microsystems - Beijing China 			    (minPwrT4[i] / 2)) -
660dd1de374Slin wang - Sun Microsystems - Beijing China 			    tPdGainOverlap + 1 + minDelta);
661dd1de374Slin wang - Sun Microsystems - Beijing China 		}
662dd1de374Slin wang - Sun Microsystems - Beijing China 		vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
663dd1de374Slin wang - Sun Microsystems - Beijing China 		vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
664dd1de374Slin wang - Sun Microsystems - Beijing China 
665dd1de374Slin wang - Sun Microsystems - Beijing China 		while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
666dd1de374Slin wang - Sun Microsystems - Beijing China 			tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
667dd1de374Slin wang - Sun Microsystems - Beijing China 			pPDADCValues[k++] =
668dd1de374Slin wang - Sun Microsystems - Beijing China 			    (uint8_t)((tmpVal < 0) ? 0 : tmpVal);
669dd1de374Slin wang - Sun Microsystems - Beijing China 			ss++;
670dd1de374Slin wang - Sun Microsystems - Beijing China 		}
671dd1de374Slin wang - Sun Microsystems - Beijing China 
672dd1de374Slin wang - Sun Microsystems - Beijing China 		sizeCurrVpdTable =
673dd1de374Slin wang - Sun Microsystems - Beijing China 		    (uint8_t)((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
674dd1de374Slin wang - Sun Microsystems - Beijing China 		tgtIndex = (uint8_t)
675dd1de374Slin wang - Sun Microsystems - Beijing China 		    (pPdGainBoundaries[i] + tPdGainOverlap - (minPwrT4[i] / 2));
676dd1de374Slin wang - Sun Microsystems - Beijing China 		maxIndex =
677dd1de374Slin wang - Sun Microsystems - Beijing China 		    (tgtIndex < sizeCurrVpdTable) ? tgtIndex : sizeCurrVpdTable;
678dd1de374Slin wang - Sun Microsystems - Beijing China 
679dd1de374Slin wang - Sun Microsystems - Beijing China 		while ((ss < maxIndex) && (k < (AR5416_NUM_PDADC_VALUES - 1)))
680dd1de374Slin wang - Sun Microsystems - Beijing China 			pPDADCValues[k++] = vpdTableI[i][ss++];
681dd1de374Slin wang - Sun Microsystems - Beijing China 
682dd1de374Slin wang - Sun Microsystems - Beijing China 		vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
683dd1de374Slin wang - Sun Microsystems - Beijing China 		    vpdTableI[i][sizeCurrVpdTable - 2]);
684dd1de374Slin wang - Sun Microsystems - Beijing China 		vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
685dd1de374Slin wang - Sun Microsystems - Beijing China 
686dd1de374Slin wang - Sun Microsystems - Beijing China 		if (tgtIndex > maxIndex) {
687dd1de374Slin wang - Sun Microsystems - Beijing China 			while ((ss <= tgtIndex) &&
688dd1de374Slin wang - Sun Microsystems - Beijing China 			    (k < (AR5416_NUM_PDADC_VALUES - 1))) {
689dd1de374Slin wang - Sun Microsystems - Beijing China 				tmpVal = (int16_t)TMP_VAL_VPD_TABLE;
690dd1de374Slin wang - Sun Microsystems - Beijing China 				pPDADCValues[k++] = (uint8_t)
691dd1de374Slin wang - Sun Microsystems - Beijing China 				    ((tmpVal > 255) ? 255 : tmpVal);
692dd1de374Slin wang - Sun Microsystems - Beijing China 				ss++;
693dd1de374Slin wang - Sun Microsystems - Beijing China 			}
694dd1de374Slin wang - Sun Microsystems - Beijing China 		}
695dd1de374Slin wang - Sun Microsystems - Beijing China 	}
696dd1de374Slin wang - Sun Microsystems - Beijing China 
697dd1de374Slin wang - Sun Microsystems - Beijing China 	while (i < AR5416_EEP4K_PD_GAINS_IN_MASK) {
698dd1de374Slin wang - Sun Microsystems - Beijing China 		pPdGainBoundaries[i] = PD_GAIN_BOUNDARY_DEFAULT;
699dd1de374Slin wang - Sun Microsystems - Beijing China 		i++;
700dd1de374Slin wang - Sun Microsystems - Beijing China 	}
701dd1de374Slin wang - Sun Microsystems - Beijing China 
702dd1de374Slin wang - Sun Microsystems - Beijing China 	while (k < AR5416_NUM_PDADC_VALUES) {
703dd1de374Slin wang - Sun Microsystems - Beijing China 		pPDADCValues[k] = pPDADCValues[k - 1];
704dd1de374Slin wang - Sun Microsystems - Beijing China 		k++;
705dd1de374Slin wang - Sun Microsystems - Beijing China 	}
706dd1de374Slin wang - Sun Microsystems - Beijing China 
707dd1de374Slin wang - Sun Microsystems - Beijing China 	return;
708dd1de374Slin wang - Sun Microsystems - Beijing China #undef TMP_VAL_VPD_TABLE
709dd1de374Slin wang - Sun Microsystems - Beijing China }
710dd1de374Slin wang - Sun Microsystems - Beijing China 
711dd1de374Slin wang - Sun Microsystems - Beijing China static void
712dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_get_def_gain_boundaries_pdadcs(struct ath_hal *ah,
713dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan,
714dd1de374Slin wang - Sun Microsystems - Beijing China     struct cal_data_per_freq *pRawDataSet,
715dd1de374Slin wang - Sun Microsystems - Beijing China     uint8_t *bChans, uint16_t availPiers,
716dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t tPdGainOverlap, int16_t *pMinCalPower,
717dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t *pPdGainBoundaries, uint8_t *pPDADCValues,
718dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t numXpdGains)
719dd1de374Slin wang - Sun Microsystems - Beijing China {
720dd1de374Slin wang - Sun Microsystems - Beijing China 	int i, j, k;
721dd1de374Slin wang - Sun Microsystems - Beijing China 	int16_t ss;
722dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t idxL = 0, idxR = 0, numPiers;
723dd1de374Slin wang - Sun Microsystems - Beijing China 	static uint8_t vpdTableL[AR5416_NUM_PD_GAINS]
724dd1de374Slin wang - Sun Microsystems - Beijing China 	    [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
725dd1de374Slin wang - Sun Microsystems - Beijing China 	static uint8_t vpdTableR[AR5416_NUM_PD_GAINS]
726dd1de374Slin wang - Sun Microsystems - Beijing China 	    [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
727dd1de374Slin wang - Sun Microsystems - Beijing China 	static uint8_t vpdTableI[AR5416_NUM_PD_GAINS]
728dd1de374Slin wang - Sun Microsystems - Beijing China 	    [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
729dd1de374Slin wang - Sun Microsystems - Beijing China 
730dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t *pVpdL, *pVpdR, *pPwrL, *pPwrR;
731dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t minPwrT4[AR5416_NUM_PD_GAINS];
732dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t maxPwrT4[AR5416_NUM_PD_GAINS];
733dd1de374Slin wang - Sun Microsystems - Beijing China 	int16_t vpdStep;
734dd1de374Slin wang - Sun Microsystems - Beijing China 	int16_t tmpVal;
735dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t sizeCurrVpdTable, maxIndex, tgtIndex;
736dd1de374Slin wang - Sun Microsystems - Beijing China 	boolean_t match;
737dd1de374Slin wang - Sun Microsystems - Beijing China 	int16_t minDelta = 0;
738dd1de374Slin wang - Sun Microsystems - Beijing China 	struct chan_centers centers;
739dd1de374Slin wang - Sun Microsystems - Beijing China 
740dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_get_channel_centers(ah, chan, &centers);
741dd1de374Slin wang - Sun Microsystems - Beijing China 
742dd1de374Slin wang - Sun Microsystems - Beijing China 	for (numPiers = 0; numPiers < availPiers; numPiers++) {
743dd1de374Slin wang - Sun Microsystems - Beijing China 		if (bChans[numPiers] == AR5416_BCHAN_UNUSED)
744dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
745dd1de374Slin wang - Sun Microsystems - Beijing China 	}
746dd1de374Slin wang - Sun Microsystems - Beijing China 
747dd1de374Slin wang - Sun Microsystems - Beijing China 	match =
748dd1de374Slin wang - Sun Microsystems - Beijing China 	    ath9k_hw_get_lower_upper_index(
749dd1de374Slin wang - Sun Microsystems - Beijing China 	    (uint8_t)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)),
750dd1de374Slin wang - Sun Microsystems - Beijing China 	    bChans, numPiers, &idxL, &idxR);
751dd1de374Slin wang - Sun Microsystems - Beijing China 
752dd1de374Slin wang - Sun Microsystems - Beijing China 	if (match) {
753dd1de374Slin wang - Sun Microsystems - Beijing China 		for (i = 0; i < numXpdGains; i++) {
754dd1de374Slin wang - Sun Microsystems - Beijing China 			minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0];
755dd1de374Slin wang - Sun Microsystems - Beijing China 			maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4];
756dd1de374Slin wang - Sun Microsystems - Beijing China 			(void) ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
757dd1de374Slin wang - Sun Microsystems - Beijing China 			    pRawDataSet[idxL].pwrPdg[i],
758dd1de374Slin wang - Sun Microsystems - Beijing China 			    pRawDataSet[idxL].vpdPdg[i],
759dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR5416_PD_GAIN_ICEPTS,
760dd1de374Slin wang - Sun Microsystems - Beijing China 			    vpdTableI[i]);
761dd1de374Slin wang - Sun Microsystems - Beijing China 		}
762dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
763dd1de374Slin wang - Sun Microsystems - Beijing China 		for (i = 0; i < numXpdGains; i++) {
764dd1de374Slin wang - Sun Microsystems - Beijing China 			pVpdL = pRawDataSet[idxL].vpdPdg[i];
765dd1de374Slin wang - Sun Microsystems - Beijing China 			pPwrL = pRawDataSet[idxL].pwrPdg[i];
766dd1de374Slin wang - Sun Microsystems - Beijing China 			pVpdR = pRawDataSet[idxR].vpdPdg[i];
767dd1de374Slin wang - Sun Microsystems - Beijing China 			pPwrR = pRawDataSet[idxR].pwrPdg[i];
768dd1de374Slin wang - Sun Microsystems - Beijing China 
769dd1de374Slin wang - Sun Microsystems - Beijing China 			minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
770dd1de374Slin wang - Sun Microsystems - Beijing China 
771dd1de374Slin wang - Sun Microsystems - Beijing China 			maxPwrT4[i] =
772dd1de374Slin wang - Sun Microsystems - Beijing China 			    min(pPwrL[AR5416_PD_GAIN_ICEPTS - 1],
773dd1de374Slin wang - Sun Microsystems - Beijing China 			    pPwrR[AR5416_PD_GAIN_ICEPTS - 1]);
774dd1de374Slin wang - Sun Microsystems - Beijing China 
775dd1de374Slin wang - Sun Microsystems - Beijing China 
776dd1de374Slin wang - Sun Microsystems - Beijing China 			(void) ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
777dd1de374Slin wang - Sun Microsystems - Beijing China 			    pPwrL, pVpdL,
778dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR5416_PD_GAIN_ICEPTS,
779dd1de374Slin wang - Sun Microsystems - Beijing China 			    vpdTableL[i]);
780dd1de374Slin wang - Sun Microsystems - Beijing China 			(void) ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
781dd1de374Slin wang - Sun Microsystems - Beijing China 			    pPwrR, pVpdR,
782dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR5416_PD_GAIN_ICEPTS,
783dd1de374Slin wang - Sun Microsystems - Beijing China 			    vpdTableR[i]);
784dd1de374Slin wang - Sun Microsystems - Beijing China 
785dd1de374Slin wang - Sun Microsystems - Beijing China 			for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
786dd1de374Slin wang - Sun Microsystems - Beijing China 				vpdTableI[i][j] =
787dd1de374Slin wang - Sun Microsystems - Beijing China 				    (uint8_t)(ath9k_hw_interpolate((uint16_t)
788dd1de374Slin wang - Sun Microsystems - Beijing China 				    FREQ2FBIN(centers.
789dd1de374Slin wang - Sun Microsystems - Beijing China 				    synth_center,
790dd1de374Slin wang - Sun Microsystems - Beijing China 				    IS_CHAN_2GHZ
791dd1de374Slin wang - Sun Microsystems - Beijing China 				    (chan)),
792dd1de374Slin wang - Sun Microsystems - Beijing China 				    bChans[idxL], bChans[idxR],
793dd1de374Slin wang - Sun Microsystems - Beijing China 				    vpdTableL[i][j], vpdTableR[i][j]));
794dd1de374Slin wang - Sun Microsystems - Beijing China 			}
795dd1de374Slin wang - Sun Microsystems - Beijing China 		}
796dd1de374Slin wang - Sun Microsystems - Beijing China 	}
797dd1de374Slin wang - Sun Microsystems - Beijing China 
798dd1de374Slin wang - Sun Microsystems - Beijing China 	*pMinCalPower = (int16_t)(minPwrT4[0] / 2);
799dd1de374Slin wang - Sun Microsystems - Beijing China 
800dd1de374Slin wang - Sun Microsystems - Beijing China 	k = 0;
801dd1de374Slin wang - Sun Microsystems - Beijing China 
802dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < numXpdGains; i++) {
803dd1de374Slin wang - Sun Microsystems - Beijing China 		if (i == (numXpdGains - 1))
804dd1de374Slin wang - Sun Microsystems - Beijing China 			pPdGainBoundaries[i] =
805dd1de374Slin wang - Sun Microsystems - Beijing China 			    (uint16_t)(maxPwrT4[i] / 2);
806dd1de374Slin wang - Sun Microsystems - Beijing China 		else
807dd1de374Slin wang - Sun Microsystems - Beijing China 			pPdGainBoundaries[i] =
808dd1de374Slin wang - Sun Microsystems - Beijing China 			    (uint16_t)((maxPwrT4[i] + minPwrT4[i + 1]) / 4);
809dd1de374Slin wang - Sun Microsystems - Beijing China 
810dd1de374Slin wang - Sun Microsystems - Beijing China 		pPdGainBoundaries[i] =
811dd1de374Slin wang - Sun Microsystems - Beijing China 		    min((uint16_t)AR5416_MAX_RATE_POWER, pPdGainBoundaries[i]);
812dd1de374Slin wang - Sun Microsystems - Beijing China 
813dd1de374Slin wang - Sun Microsystems - Beijing China 		if ((i == 0) && !AR_SREV_5416_V20_OR_LATER(ah)) {
814dd1de374Slin wang - Sun Microsystems - Beijing China 			minDelta = pPdGainBoundaries[0] - 23;
815dd1de374Slin wang - Sun Microsystems - Beijing China 			pPdGainBoundaries[0] = 23;
816dd1de374Slin wang - Sun Microsystems - Beijing China 		} else {
817dd1de374Slin wang - Sun Microsystems - Beijing China 			minDelta = 0;
818dd1de374Slin wang - Sun Microsystems - Beijing China 		}
819dd1de374Slin wang - Sun Microsystems - Beijing China 
820dd1de374Slin wang - Sun Microsystems - Beijing China 		if (i == 0) {
821dd1de374Slin wang - Sun Microsystems - Beijing China 			if (AR_SREV_9280_10_OR_LATER(ah))
822dd1de374Slin wang - Sun Microsystems - Beijing China 				ss = (int16_t)(0 - (minPwrT4[i] / 2));
823dd1de374Slin wang - Sun Microsystems - Beijing China 			else
824dd1de374Slin wang - Sun Microsystems - Beijing China 				ss = 0;
825dd1de374Slin wang - Sun Microsystems - Beijing China 		} else {
826dd1de374Slin wang - Sun Microsystems - Beijing China 			ss = (int16_t)((pPdGainBoundaries[i - 1] -
827dd1de374Slin wang - Sun Microsystems - Beijing China 			    (minPwrT4[i] / 2)) -
828dd1de374Slin wang - Sun Microsystems - Beijing China 			    tPdGainOverlap + 1 + minDelta);
829dd1de374Slin wang - Sun Microsystems - Beijing China 		}
830dd1de374Slin wang - Sun Microsystems - Beijing China 		vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
831dd1de374Slin wang - Sun Microsystems - Beijing China 		vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
832dd1de374Slin wang - Sun Microsystems - Beijing China 
833dd1de374Slin wang - Sun Microsystems - Beijing China 		while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
834dd1de374Slin wang - Sun Microsystems - Beijing China 			tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
835dd1de374Slin wang - Sun Microsystems - Beijing China 			pPDADCValues[k++] =
836dd1de374Slin wang - Sun Microsystems - Beijing China 			    (uint8_t)((tmpVal < 0) ? 0 : tmpVal);
837dd1de374Slin wang - Sun Microsystems - Beijing China 			ss++;
838dd1de374Slin wang - Sun Microsystems - Beijing China 		}
839dd1de374Slin wang - Sun Microsystems - Beijing China 
840dd1de374Slin wang - Sun Microsystems - Beijing China 		sizeCurrVpdTable =
841dd1de374Slin wang - Sun Microsystems - Beijing China 		    (uint8_t)((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
842dd1de374Slin wang - Sun Microsystems - Beijing China 		tgtIndex = (uint8_t)(pPdGainBoundaries[i] + tPdGainOverlap -
843dd1de374Slin wang - Sun Microsystems - Beijing China 		    (minPwrT4[i] / 2));
844dd1de374Slin wang - Sun Microsystems - Beijing China 		maxIndex = (tgtIndex < sizeCurrVpdTable) ?
845dd1de374Slin wang - Sun Microsystems - Beijing China 		    tgtIndex : sizeCurrVpdTable;
846dd1de374Slin wang - Sun Microsystems - Beijing China 
847dd1de374Slin wang - Sun Microsystems - Beijing China 		while ((ss < maxIndex) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
848dd1de374Slin wang - Sun Microsystems - Beijing China 			pPDADCValues[k++] = vpdTableI[i][ss++];
849dd1de374Slin wang - Sun Microsystems - Beijing China 		}
850dd1de374Slin wang - Sun Microsystems - Beijing China 
851dd1de374Slin wang - Sun Microsystems - Beijing China 		vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
852dd1de374Slin wang - Sun Microsystems - Beijing China 		    vpdTableI[i][sizeCurrVpdTable - 2]);
853dd1de374Slin wang - Sun Microsystems - Beijing China 		vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
854dd1de374Slin wang - Sun Microsystems - Beijing China 
855dd1de374Slin wang - Sun Microsystems - Beijing China 		if (tgtIndex > maxIndex) {
856dd1de374Slin wang - Sun Microsystems - Beijing China 			while ((ss <= tgtIndex) &&
857dd1de374Slin wang - Sun Microsystems - Beijing China 			    (k < (AR5416_NUM_PDADC_VALUES - 1))) {
858dd1de374Slin wang - Sun Microsystems - Beijing China 				tmpVal =
859dd1de374Slin wang - Sun Microsystems - Beijing China 				    (int16_t)
860dd1de374Slin wang - Sun Microsystems - Beijing China 				    ((vpdTableI[i][sizeCurrVpdTable - 1] +
861dd1de374Slin wang - Sun Microsystems - Beijing China 				    (ss - maxIndex + 1) * vpdStep));
862dd1de374Slin wang - Sun Microsystems - Beijing China 				pPDADCValues[k++] = (uint8_t)((tmpVal > 255) ?
863dd1de374Slin wang - Sun Microsystems - Beijing China 				    255 : tmpVal);
864dd1de374Slin wang - Sun Microsystems - Beijing China 				ss++;
865dd1de374Slin wang - Sun Microsystems - Beijing China 			}
866dd1de374Slin wang - Sun Microsystems - Beijing China 		}
867dd1de374Slin wang - Sun Microsystems - Beijing China 	}
868dd1de374Slin wang - Sun Microsystems - Beijing China 
869dd1de374Slin wang - Sun Microsystems - Beijing China 	while (i < AR5416_PD_GAINS_IN_MASK) {
870dd1de374Slin wang - Sun Microsystems - Beijing China 		pPdGainBoundaries[i] = pPdGainBoundaries[i - 1];
871dd1de374Slin wang - Sun Microsystems - Beijing China 		i++;
872dd1de374Slin wang - Sun Microsystems - Beijing China 	}
873dd1de374Slin wang - Sun Microsystems - Beijing China 
874dd1de374Slin wang - Sun Microsystems - Beijing China 	while (k < AR5416_NUM_PDADC_VALUES) {
875dd1de374Slin wang - Sun Microsystems - Beijing China 		pPDADCValues[k] = pPDADCValues[k - 1];
876dd1de374Slin wang - Sun Microsystems - Beijing China 		k++;
877dd1de374Slin wang - Sun Microsystems - Beijing China 	}
878dd1de374Slin wang - Sun Microsystems - Beijing China }
879dd1de374Slin wang - Sun Microsystems - Beijing China 
880dd1de374Slin wang - Sun Microsystems - Beijing China static void
881dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_get_legacy_target_powers(struct ath_hal *ah,
882dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan,
883dd1de374Slin wang - Sun Microsystems - Beijing China     struct cal_target_power_leg *powInfo,
884dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t numChannels,
885dd1de374Slin wang - Sun Microsystems - Beijing China     struct cal_target_power_leg *pNewPower,
886dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t numRates, boolean_t isExtTarget)
887dd1de374Slin wang - Sun Microsystems - Beijing China {
888dd1de374Slin wang - Sun Microsystems - Beijing China 	struct chan_centers centers;
889dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t clo, chi;
890dd1de374Slin wang - Sun Microsystems - Beijing China 	int i;
891dd1de374Slin wang - Sun Microsystems - Beijing China 	int matchIndex = -1, lowIndex = -1;
892dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t freq;
893dd1de374Slin wang - Sun Microsystems - Beijing China 
894dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_get_channel_centers(ah, chan, &centers);
895dd1de374Slin wang - Sun Microsystems - Beijing China 	freq = (isExtTarget) ? centers.ext_center : centers.ctl_center;
896dd1de374Slin wang - Sun Microsystems - Beijing China 
897dd1de374Slin wang - Sun Microsystems - Beijing China 	if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel,
898dd1de374Slin wang - Sun Microsystems - Beijing China 	    IS_CHAN_2GHZ(chan))) {
899dd1de374Slin wang - Sun Microsystems - Beijing China 		matchIndex = 0;
900dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
901dd1de374Slin wang - Sun Microsystems - Beijing China 		for (i = 0; (i < numChannels) &&
902dd1de374Slin wang - Sun Microsystems - Beijing China 		    (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
903dd1de374Slin wang - Sun Microsystems - Beijing China 			if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel,
904dd1de374Slin wang - Sun Microsystems - Beijing China 			    IS_CHAN_2GHZ(chan))) {
905dd1de374Slin wang - Sun Microsystems - Beijing China 				matchIndex = i;
906dd1de374Slin wang - Sun Microsystems - Beijing China 				break;
907dd1de374Slin wang - Sun Microsystems - Beijing China 			} else if ((freq <
908dd1de374Slin wang - Sun Microsystems - Beijing China 			    ath9k_hw_fbin2freq(powInfo[i].bChannel,
909dd1de374Slin wang - Sun Microsystems - Beijing China 			    IS_CHAN_2GHZ(chan))) &&
910dd1de374Slin wang - Sun Microsystems - Beijing China 			    (freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel,
911dd1de374Slin wang - Sun Microsystems - Beijing China 			    IS_CHAN_2GHZ(chan)))) {
912dd1de374Slin wang - Sun Microsystems - Beijing China 				lowIndex = i - 1;
913dd1de374Slin wang - Sun Microsystems - Beijing China 				break;
914dd1de374Slin wang - Sun Microsystems - Beijing China 			}
915dd1de374Slin wang - Sun Microsystems - Beijing China 		}
916dd1de374Slin wang - Sun Microsystems - Beijing China 		if ((matchIndex == -1) && (lowIndex == -1))
917dd1de374Slin wang - Sun Microsystems - Beijing China 			matchIndex = i - 1;
918dd1de374Slin wang - Sun Microsystems - Beijing China 	}
919dd1de374Slin wang - Sun Microsystems - Beijing China 
920dd1de374Slin wang - Sun Microsystems - Beijing China 	if (matchIndex != -1) {
921dd1de374Slin wang - Sun Microsystems - Beijing China 		*pNewPower = powInfo[matchIndex];
922dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
923dd1de374Slin wang - Sun Microsystems - Beijing China 		clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel,
924dd1de374Slin wang - Sun Microsystems - Beijing China 		    IS_CHAN_2GHZ(chan));
925dd1de374Slin wang - Sun Microsystems - Beijing China 		chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel,
926dd1de374Slin wang - Sun Microsystems - Beijing China 		    IS_CHAN_2GHZ(chan));
927dd1de374Slin wang - Sun Microsystems - Beijing China 
928dd1de374Slin wang - Sun Microsystems - Beijing China 		for (i = 0; i < numRates; i++) {
929dd1de374Slin wang - Sun Microsystems - Beijing China 			pNewPower->tPow2x[i] =
930dd1de374Slin wang - Sun Microsystems - Beijing China 			    (uint8_t)ath9k_hw_interpolate(freq, clo, chi,
931dd1de374Slin wang - Sun Microsystems - Beijing China 			    powInfo[lowIndex].tPow2x[i],
932dd1de374Slin wang - Sun Microsystems - Beijing China 			    powInfo[lowIndex + 1].tPow2x[i]);
933dd1de374Slin wang - Sun Microsystems - Beijing China 		}
934dd1de374Slin wang - Sun Microsystems - Beijing China 	}
935dd1de374Slin wang - Sun Microsystems - Beijing China }
936dd1de374Slin wang - Sun Microsystems - Beijing China 
937dd1de374Slin wang - Sun Microsystems - Beijing China static void
938dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_get_target_powers(struct ath_hal *ah,
939dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan,
940dd1de374Slin wang - Sun Microsystems - Beijing China     struct cal_target_power_ht *powInfo,
941dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t numChannels,
942dd1de374Slin wang - Sun Microsystems - Beijing China     struct cal_target_power_ht *pNewPower,
943dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t numRates, boolean_t isHt40Target)
944dd1de374Slin wang - Sun Microsystems - Beijing China {
945dd1de374Slin wang - Sun Microsystems - Beijing China 	struct chan_centers centers;
946dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t clo, chi;
947dd1de374Slin wang - Sun Microsystems - Beijing China 	int i;
948dd1de374Slin wang - Sun Microsystems - Beijing China 	int matchIndex = -1, lowIndex = -1;
949dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t freq;
950dd1de374Slin wang - Sun Microsystems - Beijing China 
951dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_get_channel_centers(ah, chan, &centers);
952dd1de374Slin wang - Sun Microsystems - Beijing China 	freq = isHt40Target ? centers.synth_center : centers.ctl_center;
953dd1de374Slin wang - Sun Microsystems - Beijing China 
954dd1de374Slin wang - Sun Microsystems - Beijing China 	if (freq <=
955dd1de374Slin wang - Sun Microsystems - Beijing China 	    ath9k_hw_fbin2freq(powInfo[0].bChannel, IS_CHAN_2GHZ(chan))) {
956dd1de374Slin wang - Sun Microsystems - Beijing China 		matchIndex = 0;
957dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
958dd1de374Slin wang - Sun Microsystems - Beijing China 		for (i = 0; (i < numChannels) &&
959dd1de374Slin wang - Sun Microsystems - Beijing China 		    (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
960dd1de374Slin wang - Sun Microsystems - Beijing China 			if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel,
961dd1de374Slin wang - Sun Microsystems - Beijing China 			    IS_CHAN_2GHZ(chan))) {
962dd1de374Slin wang - Sun Microsystems - Beijing China 				matchIndex = i;
963dd1de374Slin wang - Sun Microsystems - Beijing China 				break;
964dd1de374Slin wang - Sun Microsystems - Beijing China 			} else
965dd1de374Slin wang - Sun Microsystems - Beijing China 				if ((freq <
966dd1de374Slin wang - Sun Microsystems - Beijing China 				    ath9k_hw_fbin2freq(powInfo[i].bChannel,
967dd1de374Slin wang - Sun Microsystems - Beijing China 				    IS_CHAN_2GHZ(chan))) &&
968dd1de374Slin wang - Sun Microsystems - Beijing China 				    (freq > ath9k_hw_fbin2freq
969dd1de374Slin wang - Sun Microsystems - Beijing China 				    (powInfo[i - 1].bChannel,
970dd1de374Slin wang - Sun Microsystems - Beijing China 				    IS_CHAN_2GHZ(chan)))) {
971dd1de374Slin wang - Sun Microsystems - Beijing China 					lowIndex = i - 1;
972dd1de374Slin wang - Sun Microsystems - Beijing China 					break;
973dd1de374Slin wang - Sun Microsystems - Beijing China 				}
974dd1de374Slin wang - Sun Microsystems - Beijing China 		}
975dd1de374Slin wang - Sun Microsystems - Beijing China 		if ((matchIndex == -1) && (lowIndex == -1))
976dd1de374Slin wang - Sun Microsystems - Beijing China 			matchIndex = i - 1;
977dd1de374Slin wang - Sun Microsystems - Beijing China 	}
978dd1de374Slin wang - Sun Microsystems - Beijing China 
979dd1de374Slin wang - Sun Microsystems - Beijing China 	if (matchIndex != -1) {
980dd1de374Slin wang - Sun Microsystems - Beijing China 		*pNewPower = powInfo[matchIndex];
981dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
982dd1de374Slin wang - Sun Microsystems - Beijing China 		clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel,
983dd1de374Slin wang - Sun Microsystems - Beijing China 		    IS_CHAN_2GHZ(chan));
984dd1de374Slin wang - Sun Microsystems - Beijing China 		chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel,
985dd1de374Slin wang - Sun Microsystems - Beijing China 		    IS_CHAN_2GHZ(chan));
986dd1de374Slin wang - Sun Microsystems - Beijing China 
987dd1de374Slin wang - Sun Microsystems - Beijing China 		for (i = 0; i < numRates; i++) {
988dd1de374Slin wang - Sun Microsystems - Beijing China 			pNewPower->tPow2x[i] =
989dd1de374Slin wang - Sun Microsystems - Beijing China 			    (uint8_t)ath9k_hw_interpolate(freq,
990dd1de374Slin wang - Sun Microsystems - Beijing China 			    clo, chi,
991dd1de374Slin wang - Sun Microsystems - Beijing China 			    powInfo[lowIndex].tPow2x[i],
992dd1de374Slin wang - Sun Microsystems - Beijing China 			    powInfo[lowIndex + 1].tPow2x[i]);
993dd1de374Slin wang - Sun Microsystems - Beijing China 		}
994dd1de374Slin wang - Sun Microsystems - Beijing China 	}
995dd1de374Slin wang - Sun Microsystems - Beijing China }
996dd1de374Slin wang - Sun Microsystems - Beijing China 
997dd1de374Slin wang - Sun Microsystems - Beijing China static uint16_t
998dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_get_max_edge_power(uint16_t freq,
999dd1de374Slin wang - Sun Microsystems - Beijing China     struct cal_ctl_edges *pRdEdgesPower,
1000dd1de374Slin wang - Sun Microsystems - Beijing China     boolean_t is2GHz, int num_band_edges)
1001dd1de374Slin wang - Sun Microsystems - Beijing China {
1002dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
1003dd1de374Slin wang - Sun Microsystems - Beijing China 	int i;
1004dd1de374Slin wang - Sun Microsystems - Beijing China 
1005dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; (i < num_band_edges) &&
1006dd1de374Slin wang - Sun Microsystems - Beijing China 	    (pRdEdgesPower[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
1007dd1de374Slin wang - Sun Microsystems - Beijing China 		if (freq == ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel,
1008dd1de374Slin wang - Sun Microsystems - Beijing China 		    is2GHz)) {
1009dd1de374Slin wang - Sun Microsystems - Beijing China 			twiceMaxEdgePower = pRdEdgesPower[i].tPower;
1010dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
1011dd1de374Slin wang - Sun Microsystems - Beijing China 		} else if ((i > 0) &&
1012dd1de374Slin wang - Sun Microsystems - Beijing China 		    (freq < ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel,
1013dd1de374Slin wang - Sun Microsystems - Beijing China 		    is2GHz))) {
1014dd1de374Slin wang - Sun Microsystems - Beijing China 			if (ath9k_hw_fbin2freq(pRdEdgesPower[i - 1].bChannel,
1015dd1de374Slin wang - Sun Microsystems - Beijing China 			    is2GHz) < freq &&
1016dd1de374Slin wang - Sun Microsystems - Beijing China 			    pRdEdgesPower[i - 1].flag) {
1017dd1de374Slin wang - Sun Microsystems - Beijing China 				twiceMaxEdgePower =
1018dd1de374Slin wang - Sun Microsystems - Beijing China 				    pRdEdgesPower[i - 1].tPower;
1019dd1de374Slin wang - Sun Microsystems - Beijing China 			}
1020dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
1021dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1022dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1023dd1de374Slin wang - Sun Microsystems - Beijing China 
1024dd1de374Slin wang - Sun Microsystems - Beijing China 	return (twiceMaxEdgePower);
1025dd1de374Slin wang - Sun Microsystems - Beijing China }
1026dd1de374Slin wang - Sun Microsystems - Beijing China 
1027dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t
1028dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_def_power_cal_table(struct ath_hal *ah,
1029dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan, int16_t *pTxPowerIndexOffset)
1030dd1de374Slin wang - Sun Microsystems - Beijing China {
1031dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
1032dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ar5416_eeprom_def *pEepData = &ahp->ah_eeprom.def;
1033dd1de374Slin wang - Sun Microsystems - Beijing China 	struct cal_data_per_freq *pRawDataset;
1034dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t *pCalBChans = NULL;
1035dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t pdGainOverlap_t2;
1036dd1de374Slin wang - Sun Microsystems - Beijing China 	static uint8_t pdadcValues[AR5416_NUM_PDADC_VALUES];
1037dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t gainBoundaries[AR5416_PD_GAINS_IN_MASK];
1038dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t numPiers, i, j;
1039dd1de374Slin wang - Sun Microsystems - Beijing China 	int16_t tMinCalPower;
1040dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t numXpdGain, xpdMask;
1041dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t xpdGainValues[AR5416_NUM_PD_GAINS] = { 0, 0, 0, 0 };
1042dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t reg32, regOffset, regChainOffset;
1043dd1de374Slin wang - Sun Microsystems - Beijing China 	int16_t modalIdx;
1044dd1de374Slin wang - Sun Microsystems - Beijing China 
1045dd1de374Slin wang - Sun Microsystems - Beijing China 	modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
1046dd1de374Slin wang - Sun Microsystems - Beijing China 	xpdMask = pEepData->modalHeader[modalIdx].xpdGain;
1047dd1de374Slin wang - Sun Microsystems - Beijing China 
1048dd1de374Slin wang - Sun Microsystems - Beijing China 	if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1049dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR5416_EEP_MINOR_VER_2) {
1050dd1de374Slin wang - Sun Microsystems - Beijing China 		pdGainOverlap_t2 =
1051dd1de374Slin wang - Sun Microsystems - Beijing China 		    pEepData->modalHeader[modalIdx].pdGainOverlap;
1052dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
1053dd1de374Slin wang - Sun Microsystems - Beijing China 		pdGainOverlap_t2 =
1054dd1de374Slin wang - Sun Microsystems - Beijing China 		    (uint16_t)(MS(REG_READ(ah, AR_PHY_TPCRG5),
1055dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
1056dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1057dd1de374Slin wang - Sun Microsystems - Beijing China 
1058dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_2GHZ(chan)) {
1059dd1de374Slin wang - Sun Microsystems - Beijing China 		pCalBChans = pEepData->calFreqPier2G;
1060dd1de374Slin wang - Sun Microsystems - Beijing China 		numPiers = AR5416_NUM_2G_CAL_PIERS;
1061dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
1062dd1de374Slin wang - Sun Microsystems - Beijing China 		pCalBChans = pEepData->calFreqPier5G;
1063dd1de374Slin wang - Sun Microsystems - Beijing China 		numPiers = AR5416_NUM_5G_CAL_PIERS;
1064dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1065dd1de374Slin wang - Sun Microsystems - Beijing China 
1066dd1de374Slin wang - Sun Microsystems - Beijing China 	numXpdGain = 0;
1067dd1de374Slin wang - Sun Microsystems - Beijing China 
1068dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
1069dd1de374Slin wang - Sun Microsystems - Beijing China 		if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
1070dd1de374Slin wang - Sun Microsystems - Beijing China 			if (numXpdGain >= AR5416_NUM_PD_GAINS)
1071dd1de374Slin wang - Sun Microsystems - Beijing China 				break;
1072dd1de374Slin wang - Sun Microsystems - Beijing China 			xpdGainValues[numXpdGain] =
1073dd1de374Slin wang - Sun Microsystems - Beijing China 			    (uint16_t)(AR5416_PD_GAINS_IN_MASK - i);
1074dd1de374Slin wang - Sun Microsystems - Beijing China 			numXpdGain++;
1075dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1076dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1077dd1de374Slin wang - Sun Microsystems - Beijing China 
1078dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
1079dd1de374Slin wang - Sun Microsystems - Beijing China 	    (numXpdGain - 1) & 0x3);
1080dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
1081dd1de374Slin wang - Sun Microsystems - Beijing China 	    xpdGainValues[0]);
1082dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
1083dd1de374Slin wang - Sun Microsystems - Beijing China 	    xpdGainValues[1]);
1084dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
1085dd1de374Slin wang - Sun Microsystems - Beijing China 	    xpdGainValues[2]);
1086dd1de374Slin wang - Sun Microsystems - Beijing China 
1087dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < AR5416_MAX_CHAINS; i++) {
1088dd1de374Slin wang - Sun Microsystems - Beijing China 		if (AR_SREV_5416_V20_OR_LATER(ah) &&
1089dd1de374Slin wang - Sun Microsystems - Beijing China 		    (ahp->ah_rxchainmask == 5 || ahp->ah_txchainmask == 5) &&
1090dd1de374Slin wang - Sun Microsystems - Beijing China 		    (i != 0)) {
1091dd1de374Slin wang - Sun Microsystems - Beijing China 			regChainOffset = (i == 1) ? 0x2000 : 0x1000;
1092dd1de374Slin wang - Sun Microsystems - Beijing China 		} else
1093dd1de374Slin wang - Sun Microsystems - Beijing China 			regChainOffset = i * 0x1000;
1094dd1de374Slin wang - Sun Microsystems - Beijing China 
1095dd1de374Slin wang - Sun Microsystems - Beijing China 		if (pEepData->baseEepHeader.txMask & (1 << i)) {
1096dd1de374Slin wang - Sun Microsystems - Beijing China 			if (IS_CHAN_2GHZ(chan))
1097dd1de374Slin wang - Sun Microsystems - Beijing China 				pRawDataset = pEepData->calPierData2G[i];
1098dd1de374Slin wang - Sun Microsystems - Beijing China 			else
1099dd1de374Slin wang - Sun Microsystems - Beijing China 				pRawDataset = pEepData->calPierData5G[i];
1100dd1de374Slin wang - Sun Microsystems - Beijing China 
1101dd1de374Slin wang - Sun Microsystems - Beijing China 			ath9k_hw_get_def_gain_boundaries_pdadcs(ah, chan,
1102dd1de374Slin wang - Sun Microsystems - Beijing China 			    pRawDataset, pCalBChans,
1103dd1de374Slin wang - Sun Microsystems - Beijing China 			    numPiers, pdGainOverlap_t2,
1104dd1de374Slin wang - Sun Microsystems - Beijing China 			    &tMinCalPower, gainBoundaries,
1105dd1de374Slin wang - Sun Microsystems - Beijing China 			    pdadcValues, numXpdGain);
1106dd1de374Slin wang - Sun Microsystems - Beijing China 
1107dd1de374Slin wang - Sun Microsystems - Beijing China 			if ((i == 0) || AR_SREV_5416_V20_OR_LATER(ah)) {
1108dd1de374Slin wang - Sun Microsystems - Beijing China 				REG_WRITE(ah,
1109dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR_PHY_TPCRG5 + regChainOffset,
1110dd1de374Slin wang - Sun Microsystems - Beijing China 				    SM(pdGainOverlap_t2,
1111dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
1112dd1de374Slin wang - Sun Microsystems - Beijing China 				    SM(gainBoundaries[0],
1113dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1) |
1114dd1de374Slin wang - Sun Microsystems - Beijing China 				    SM(gainBoundaries[1],
1115dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2) |
1116dd1de374Slin wang - Sun Microsystems - Beijing China 				    SM(gainBoundaries[2],
1117dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3) |
1118dd1de374Slin wang - Sun Microsystems - Beijing China 				    SM(gainBoundaries[3],
1119dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
1120dd1de374Slin wang - Sun Microsystems - Beijing China 			}
1121dd1de374Slin wang - Sun Microsystems - Beijing China 
1122dd1de374Slin wang - Sun Microsystems - Beijing China 			regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
1123dd1de374Slin wang - Sun Microsystems - Beijing China 			for (j = 0; j < 32; j++) {
1124dd1de374Slin wang - Sun Microsystems - Beijing China 				reg32 = ((pdadcValues[4 * j + 0] & 0xFF) << 0) |
1125dd1de374Slin wang - Sun Microsystems - Beijing China 				    ((pdadcValues[4 * j + 1] & 0xFF) << 8) |
1126dd1de374Slin wang - Sun Microsystems - Beijing China 				    ((pdadcValues[4 * j + 2] & 0xFF) << 16)|
1127dd1de374Slin wang - Sun Microsystems - Beijing China 				    ((pdadcValues[4 * j + 3] & 0xFF) << 24);
1128dd1de374Slin wang - Sun Microsystems - Beijing China 				REG_WRITE(ah, regOffset, reg32);
1129dd1de374Slin wang - Sun Microsystems - Beijing China 
1130dd1de374Slin wang - Sun Microsystems - Beijing China 				ARN_DBG((ARN_DBG_REG_IO,
1131dd1de374Slin wang - Sun Microsystems - Beijing China 				    "PDADC (%d,%4x): %4.4x %8.8x\n",
1132dd1de374Slin wang - Sun Microsystems - Beijing China 				    i, regChainOffset, regOffset,
1133dd1de374Slin wang - Sun Microsystems - Beijing China 				    reg32));
1134dd1de374Slin wang - Sun Microsystems - Beijing China 				ARN_DBG((ARN_DBG_REG_IO,
1135dd1de374Slin wang - Sun Microsystems - Beijing China 				    "PDADC: Chain %d | PDADC %3d "
1136dd1de374Slin wang - Sun Microsystems - Beijing China 				    "Value %3d | PDADC %3d Value %3d | "
1137dd1de374Slin wang - Sun Microsystems - Beijing China 				    "PDADC %3d Value %3d | PDADC %3d "
1138dd1de374Slin wang - Sun Microsystems - Beijing China 				    "Value %3d |\n",
1139dd1de374Slin wang - Sun Microsystems - Beijing China 				    i, 4 * j, pdadcValues[4 * j],
1140dd1de374Slin wang - Sun Microsystems - Beijing China 				    4 * j + 1, pdadcValues[4 * j + 1],
1141dd1de374Slin wang - Sun Microsystems - Beijing China 				    4 * j + 2, pdadcValues[4 * j + 2],
1142dd1de374Slin wang - Sun Microsystems - Beijing China 				    4 * j + 3,
1143dd1de374Slin wang - Sun Microsystems - Beijing China 				    pdadcValues[4 * j + 3]));
1144dd1de374Slin wang - Sun Microsystems - Beijing China 
1145dd1de374Slin wang - Sun Microsystems - Beijing China 				regOffset += 4;
1146dd1de374Slin wang - Sun Microsystems - Beijing China 			}
1147dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1148dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1149dd1de374Slin wang - Sun Microsystems - Beijing China 
1150dd1de374Slin wang - Sun Microsystems - Beijing China 	*pTxPowerIndexOffset = 0;
1151dd1de374Slin wang - Sun Microsystems - Beijing China 
1152dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
1153dd1de374Slin wang - Sun Microsystems - Beijing China }
1154dd1de374Slin wang - Sun Microsystems - Beijing China 
1155dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t
1156dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_4k_power_cal_table(struct ath_hal *ah,
1157dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan, int16_t *pTxPowerIndexOffset)
1158dd1de374Slin wang - Sun Microsystems - Beijing China {
1159dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
1160dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ar5416_eeprom_4k *pEepData = &ahp->ah_eeprom.map4k;
1161dd1de374Slin wang - Sun Microsystems - Beijing China 	struct cal_data_per_freq_4k *pRawDataset;
1162dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t *pCalBChans = NULL;
1163dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t pdGainOverlap_t2;
1164dd1de374Slin wang - Sun Microsystems - Beijing China 	static uint8_t pdadcValues[AR5416_NUM_PDADC_VALUES];
1165dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t gainBoundaries[AR5416_PD_GAINS_IN_MASK];
1166dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t numPiers, i, j;
1167dd1de374Slin wang - Sun Microsystems - Beijing China 	int16_t tMinCalPower;
1168dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t numXpdGain, xpdMask;
1169dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t xpdGainValues[AR5416_NUM_PD_GAINS] = { 0, 0, 0, 0 };
1170dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t reg32, regOffset, regChainOffset;
1171dd1de374Slin wang - Sun Microsystems - Beijing China 
1172dd1de374Slin wang - Sun Microsystems - Beijing China 	xpdMask = pEepData->modalHeader.xpdGain;
1173dd1de374Slin wang - Sun Microsystems - Beijing China 
1174dd1de374Slin wang - Sun Microsystems - Beijing China 	if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1175dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR5416_EEP_MINOR_VER_2) {
1176dd1de374Slin wang - Sun Microsystems - Beijing China 		pdGainOverlap_t2 =
1177dd1de374Slin wang - Sun Microsystems - Beijing China 		    pEepData->modalHeader.pdGainOverlap;
1178dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
1179dd1de374Slin wang - Sun Microsystems - Beijing China 		pdGainOverlap_t2 = (uint16_t)(MS(REG_READ(ah, AR_PHY_TPCRG5),
1180dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
1181dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1182dd1de374Slin wang - Sun Microsystems - Beijing China 
1183dd1de374Slin wang - Sun Microsystems - Beijing China 	pCalBChans = pEepData->calFreqPier2G;
1184dd1de374Slin wang - Sun Microsystems - Beijing China 	numPiers = AR5416_NUM_2G_CAL_PIERS;
1185dd1de374Slin wang - Sun Microsystems - Beijing China 
1186dd1de374Slin wang - Sun Microsystems - Beijing China 	numXpdGain = 0;
1187dd1de374Slin wang - Sun Microsystems - Beijing China 
1188dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
1189dd1de374Slin wang - Sun Microsystems - Beijing China 		if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
1190dd1de374Slin wang - Sun Microsystems - Beijing China 			if (numXpdGain >= AR5416_NUM_PD_GAINS)
1191dd1de374Slin wang - Sun Microsystems - Beijing China 				break;
1192dd1de374Slin wang - Sun Microsystems - Beijing China 			xpdGainValues[numXpdGain] =
1193dd1de374Slin wang - Sun Microsystems - Beijing China 			    (uint16_t)(AR5416_PD_GAINS_IN_MASK - i);
1194dd1de374Slin wang - Sun Microsystems - Beijing China 			numXpdGain++;
1195dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1196dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1197dd1de374Slin wang - Sun Microsystems - Beijing China 
1198dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
1199dd1de374Slin wang - Sun Microsystems - Beijing China 	    (numXpdGain - 1) & 0x3);
1200dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
1201dd1de374Slin wang - Sun Microsystems - Beijing China 	    xpdGainValues[0]);
1202dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
1203dd1de374Slin wang - Sun Microsystems - Beijing China 	    xpdGainValues[1]);
1204dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
1205dd1de374Slin wang - Sun Microsystems - Beijing China 	    xpdGainValues[2]);
1206dd1de374Slin wang - Sun Microsystems - Beijing China 
1207dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < AR5416_MAX_CHAINS; i++) {
1208dd1de374Slin wang - Sun Microsystems - Beijing China 		if (AR_SREV_5416_V20_OR_LATER(ah) &&
1209dd1de374Slin wang - Sun Microsystems - Beijing China 		    (ahp->ah_rxchainmask == 5 || ahp->ah_txchainmask == 5) &&
1210dd1de374Slin wang - Sun Microsystems - Beijing China 		    (i != 0)) {
1211dd1de374Slin wang - Sun Microsystems - Beijing China 			regChainOffset = (i == 1) ? 0x2000 : 0x1000;
1212dd1de374Slin wang - Sun Microsystems - Beijing China 		} else
1213dd1de374Slin wang - Sun Microsystems - Beijing China 			regChainOffset = i * 0x1000;
1214dd1de374Slin wang - Sun Microsystems - Beijing China 
1215dd1de374Slin wang - Sun Microsystems - Beijing China 		if (pEepData->baseEepHeader.txMask & (1 << i)) {
1216dd1de374Slin wang - Sun Microsystems - Beijing China 			pRawDataset = pEepData->calPierData2G[i];
1217dd1de374Slin wang - Sun Microsystems - Beijing China 
1218dd1de374Slin wang - Sun Microsystems - Beijing China 			ath9k_hw_get_4k_gain_boundaries_pdadcs(ah, chan,
1219dd1de374Slin wang - Sun Microsystems - Beijing China 			    pRawDataset, pCalBChans,
1220dd1de374Slin wang - Sun Microsystems - Beijing China 			    numPiers, pdGainOverlap_t2,
1221dd1de374Slin wang - Sun Microsystems - Beijing China 			    &tMinCalPower, gainBoundaries,
1222dd1de374Slin wang - Sun Microsystems - Beijing China 			    pdadcValues, numXpdGain);
1223dd1de374Slin wang - Sun Microsystems - Beijing China 
1224dd1de374Slin wang - Sun Microsystems - Beijing China 			if ((i == 0) || AR_SREV_5416_V20_OR_LATER(ah)) {
1225dd1de374Slin wang - Sun Microsystems - Beijing China 				REG_WRITE(ah, AR_PHY_TPCRG5 + regChainOffset,
1226dd1de374Slin wang - Sun Microsystems - Beijing China 				    SM(pdGainOverlap_t2,
1227dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
1228dd1de374Slin wang - Sun Microsystems - Beijing China 				    SM(gainBoundaries[0],
1229dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1) |
1230dd1de374Slin wang - Sun Microsystems - Beijing China 				    SM(gainBoundaries[1],
1231dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2) |
1232dd1de374Slin wang - Sun Microsystems - Beijing China 				    SM(gainBoundaries[2],
1233dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3) |
1234dd1de374Slin wang - Sun Microsystems - Beijing China 				    SM(gainBoundaries[3],
1235dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
1236dd1de374Slin wang - Sun Microsystems - Beijing China 			}
1237dd1de374Slin wang - Sun Microsystems - Beijing China 
1238dd1de374Slin wang - Sun Microsystems - Beijing China 			regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
1239dd1de374Slin wang - Sun Microsystems - Beijing China 			for (j = 0; j < 32; j++) {
1240dd1de374Slin wang - Sun Microsystems - Beijing China 				reg32 = ((pdadcValues[4 * j + 0] & 0xFF) << 0) |
1241dd1de374Slin wang - Sun Microsystems - Beijing China 				    ((pdadcValues[4 * j + 1] & 0xFF) << 8) |
1242dd1de374Slin wang - Sun Microsystems - Beijing China 				    ((pdadcValues[4 * j + 2] & 0xFF) << 16)|
1243dd1de374Slin wang - Sun Microsystems - Beijing China 				    ((pdadcValues[4 * j + 3] & 0xFF) << 24);
1244dd1de374Slin wang - Sun Microsystems - Beijing China 				REG_WRITE(ah, regOffset, reg32);
1245dd1de374Slin wang - Sun Microsystems - Beijing China 
1246dd1de374Slin wang - Sun Microsystems - Beijing China 				ARN_DBG((ARN_DBG_REG_IO,
1247dd1de374Slin wang - Sun Microsystems - Beijing China 				    "PDADC (%d,%4x): %4.4x %8.8x\n",
1248dd1de374Slin wang - Sun Microsystems - Beijing China 				    i, regChainOffset, regOffset,
1249dd1de374Slin wang - Sun Microsystems - Beijing China 				    reg32));
1250dd1de374Slin wang - Sun Microsystems - Beijing China 				ARN_DBG((ARN_DBG_REG_IO,
1251dd1de374Slin wang - Sun Microsystems - Beijing China 				    "PDADC: Chain %d | "
1252dd1de374Slin wang - Sun Microsystems - Beijing China 				    "PDADC %3d Value %3d | "
1253dd1de374Slin wang - Sun Microsystems - Beijing China 				    "PDADC %3d Value %3d | "
1254dd1de374Slin wang - Sun Microsystems - Beijing China 				    "PDADC %3d Value %3d | "
1255dd1de374Slin wang - Sun Microsystems - Beijing China 				    "PDADC %3d Value %3d |\n",
1256dd1de374Slin wang - Sun Microsystems - Beijing China 				    i, 4 * j, pdadcValues[4 * j],
1257dd1de374Slin wang - Sun Microsystems - Beijing China 				    4 * j + 1, pdadcValues[4 * j + 1],
1258dd1de374Slin wang - Sun Microsystems - Beijing China 				    4 * j + 2, pdadcValues[4 * j + 2],
1259dd1de374Slin wang - Sun Microsystems - Beijing China 				    4 * j + 3,
1260dd1de374Slin wang - Sun Microsystems - Beijing China 				    pdadcValues[4 * j + 3]));
1261dd1de374Slin wang - Sun Microsystems - Beijing China 
1262dd1de374Slin wang - Sun Microsystems - Beijing China 				regOffset += 4;
1263dd1de374Slin wang - Sun Microsystems - Beijing China 			}
1264dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1265dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1266dd1de374Slin wang - Sun Microsystems - Beijing China 
1267dd1de374Slin wang - Sun Microsystems - Beijing China 	*pTxPowerIndexOffset = 0;
1268dd1de374Slin wang - Sun Microsystems - Beijing China 
1269dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
1270dd1de374Slin wang - Sun Microsystems - Beijing China }
1271dd1de374Slin wang - Sun Microsystems - Beijing China 
1272dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t
1273dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_def_power_per_rate_table(struct ath_hal *ah,
1274dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan,
1275dd1de374Slin wang - Sun Microsystems - Beijing China     int16_t *ratesArray,
1276dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t cfgCtl,
1277dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t AntennaReduction,
1278dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t twiceMaxRegulatoryPower,
1279dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t powerLimit)
1280dd1de374Slin wang - Sun Microsystems - Beijing China {
1281dd1de374Slin wang - Sun Microsystems - Beijing China #define	REDUCE_SCALED_POWER_BY_TWO_CHAIN	6  /* 10*log10(2)*2 */
1282dd1de374Slin wang - Sun Microsystems - Beijing China #define	REDUCE_SCALED_POWER_BY_THREE_CHAIN	10 /* 10*log10(3)*2 */
1283dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
1284dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ar5416_eeprom_def *pEepData = &ahp->ah_eeprom.def;
1285dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
1286dd1de374Slin wang - Sun Microsystems - Beijing China 	static const uint16_t tpScaleReductionTable[5] =
1287dd1de374Slin wang - Sun Microsystems - Beijing China 	    { 0, 3, 6, 9, AR5416_MAX_RATE_POWER };
1288dd1de374Slin wang - Sun Microsystems - Beijing China 
1289dd1de374Slin wang - Sun Microsystems - Beijing China 	int i;
1290dd1de374Slin wang - Sun Microsystems - Beijing China 	int8_t twiceLargestAntenna;
1291dd1de374Slin wang - Sun Microsystems - Beijing China 	struct cal_ctl_data *rep;
1292dd1de374Slin wang - Sun Microsystems - Beijing China 	struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
1293dd1de374Slin wang - Sun Microsystems - Beijing China 		0, { 0, 0, 0, 0}
1294dd1de374Slin wang - Sun Microsystems - Beijing China 	};
1295dd1de374Slin wang - Sun Microsystems - Beijing China 	struct cal_target_power_leg targetPowerOfdmExt = {
1296dd1de374Slin wang - Sun Microsystems - Beijing China 		0, { 0, 0, 0, 0} }, targetPowerCckExt = {
1297dd1de374Slin wang - Sun Microsystems - Beijing China 		0, { 0, 0, 0, 0 }
1298dd1de374Slin wang - Sun Microsystems - Beijing China 	};
1299dd1de374Slin wang - Sun Microsystems - Beijing China 	struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
1300dd1de374Slin wang - Sun Microsystems - Beijing China 		0, {0, 0, 0, 0}
1301dd1de374Slin wang - Sun Microsystems - Beijing China 	};
1302dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t scaledPower = 0, minCtlPower, maxRegAllowedPower;
1303dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t ctlModesFor11a[] =
1304dd1de374Slin wang - Sun Microsystems - Beijing China 		{ CTL_11A, CTL_5GHT20, CTL_11A_EXT, CTL_5GHT40 };
1305dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t ctlModesFor11g[] =
1306dd1de374Slin wang - Sun Microsystems - Beijing China 		{ CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT,
1307dd1de374Slin wang - Sun Microsystems - Beijing China 		    CTL_2GHT40
1308dd1de374Slin wang - Sun Microsystems - Beijing China 		};
1309dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t numCtlModes, *pCtlMode, ctlMode, freq;
1310dd1de374Slin wang - Sun Microsystems - Beijing China 	struct chan_centers centers;
1311dd1de374Slin wang - Sun Microsystems - Beijing China 	int tx_chainmask;
1312dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t twiceMinEdgePower;
1313dd1de374Slin wang - Sun Microsystems - Beijing China 
1314dd1de374Slin wang - Sun Microsystems - Beijing China 	tx_chainmask = ahp->ah_txchainmask;
1315dd1de374Slin wang - Sun Microsystems - Beijing China 
1316dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_get_channel_centers(ah, chan, &centers);
1317dd1de374Slin wang - Sun Microsystems - Beijing China 
1318dd1de374Slin wang - Sun Microsystems - Beijing China 	twiceLargestAntenna = max(
1319dd1de374Slin wang - Sun Microsystems - Beijing China 	    pEepData->modalHeader
1320dd1de374Slin wang - Sun Microsystems - Beijing China 	    [IS_CHAN_2GHZ(chan)].antennaGainCh[0],
1321dd1de374Slin wang - Sun Microsystems - Beijing China 	    pEepData->modalHeader
1322dd1de374Slin wang - Sun Microsystems - Beijing China 	    [IS_CHAN_2GHZ(chan)].antennaGainCh[1]);
1323dd1de374Slin wang - Sun Microsystems - Beijing China 
1324dd1de374Slin wang - Sun Microsystems - Beijing China 	twiceLargestAntenna =
1325dd1de374Slin wang - Sun Microsystems - Beijing China 	    max((uint8_t)twiceLargestAntenna,
1326dd1de374Slin wang - Sun Microsystems - Beijing China 	    pEepData->modalHeader
1327dd1de374Slin wang - Sun Microsystems - Beijing China 	    [IS_CHAN_2GHZ(chan)].antennaGainCh[2]);
1328dd1de374Slin wang - Sun Microsystems - Beijing China 
1329dd1de374Slin wang - Sun Microsystems - Beijing China 	twiceLargestAntenna =
1330dd1de374Slin wang - Sun Microsystems - Beijing China 	    (int16_t)min(AntennaReduction - twiceLargestAntenna, 0);
1331dd1de374Slin wang - Sun Microsystems - Beijing China 
1332dd1de374Slin wang - Sun Microsystems - Beijing China 	maxRegAllowedPower =
1333dd1de374Slin wang - Sun Microsystems - Beijing China 	    twiceMaxRegulatoryPower + twiceLargestAntenna;
1334dd1de374Slin wang - Sun Microsystems - Beijing China 
1335dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ah->ah_tpScale != ATH9K_TP_SCALE_MAX) {
1336dd1de374Slin wang - Sun Microsystems - Beijing China 		maxRegAllowedPower -=
1337dd1de374Slin wang - Sun Microsystems - Beijing China 		    (tpScaleReductionTable[(ah->ah_tpScale)] * 2);
1338dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1339dd1de374Slin wang - Sun Microsystems - Beijing China 
1340dd1de374Slin wang - Sun Microsystems - Beijing China 	scaledPower = min(powerLimit, maxRegAllowedPower);
1341dd1de374Slin wang - Sun Microsystems - Beijing China 
1342dd1de374Slin wang - Sun Microsystems - Beijing China 	switch (ar5416_get_ntxchains(tx_chainmask)) {
1343dd1de374Slin wang - Sun Microsystems - Beijing China 	case 1:
1344dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
1345dd1de374Slin wang - Sun Microsystems - Beijing China 	case 2:
1346dd1de374Slin wang - Sun Microsystems - Beijing China 		scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
1347dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
1348dd1de374Slin wang - Sun Microsystems - Beijing China 	case 3:
1349dd1de374Slin wang - Sun Microsystems - Beijing China 		scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
1350dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
1351dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1352dd1de374Slin wang - Sun Microsystems - Beijing China 
1353dd1de374Slin wang - Sun Microsystems - Beijing China 	scaledPower = max((uint16_t)0, scaledPower);
1354dd1de374Slin wang - Sun Microsystems - Beijing China 
1355dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_2GHZ(chan)) {
1356dd1de374Slin wang - Sun Microsystems - Beijing China 		numCtlModes = ARRAY_SIZE(ctlModesFor11g) -
1357dd1de374Slin wang - Sun Microsystems - Beijing China 		    SUB_NUM_CTL_MODES_AT_2G_40;
1358dd1de374Slin wang - Sun Microsystems - Beijing China 		pCtlMode = ctlModesFor11g;
1359dd1de374Slin wang - Sun Microsystems - Beijing China 
1360dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_get_legacy_target_powers(ah, chan,
1361dd1de374Slin wang - Sun Microsystems - Beijing China 		    pEepData->calTargetPowerCck,
1362dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR5416_NUM_2G_CCK_TARGET_POWERS,
1363dd1de374Slin wang - Sun Microsystems - Beijing China 		    &targetPowerCck, 4, B_FALSE);
1364dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_get_legacy_target_powers(ah, chan,
1365dd1de374Slin wang - Sun Microsystems - Beijing China 		    pEepData->calTargetPower2G,
1366dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR5416_NUM_2G_20_TARGET_POWERS,
1367dd1de374Slin wang - Sun Microsystems - Beijing China 		    &targetPowerOfdm, 4, B_FALSE);
1368dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_get_target_powers(ah, chan,
1369dd1de374Slin wang - Sun Microsystems - Beijing China 		    pEepData->calTargetPower2GHT20,
1370dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR5416_NUM_2G_20_TARGET_POWERS,
1371dd1de374Slin wang - Sun Microsystems - Beijing China 		    &targetPowerHt20, 8, B_FALSE);
1372dd1de374Slin wang - Sun Microsystems - Beijing China 
1373dd1de374Slin wang - Sun Microsystems - Beijing China 		if (IS_CHAN_HT40(chan)) {
1374dd1de374Slin wang - Sun Microsystems - Beijing China 			numCtlModes = ARRAY_SIZE(ctlModesFor11g);
1375dd1de374Slin wang - Sun Microsystems - Beijing China 			ath9k_hw_get_target_powers(ah, chan,
1376dd1de374Slin wang - Sun Microsystems - Beijing China 			    pEepData->calTargetPower2GHT40,
1377dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR5416_NUM_2G_40_TARGET_POWERS,
1378dd1de374Slin wang - Sun Microsystems - Beijing China 			    &targetPowerHt40, 8, B_TRUE);
1379dd1de374Slin wang - Sun Microsystems - Beijing China 			ath9k_hw_get_legacy_target_powers(ah, chan,
1380dd1de374Slin wang - Sun Microsystems - Beijing China 			    pEepData->calTargetPowerCck,
1381dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR5416_NUM_2G_CCK_TARGET_POWERS,
1382dd1de374Slin wang - Sun Microsystems - Beijing China 			    &targetPowerCckExt, 4, B_TRUE);
1383dd1de374Slin wang - Sun Microsystems - Beijing China 			ath9k_hw_get_legacy_target_powers(ah, chan,
1384dd1de374Slin wang - Sun Microsystems - Beijing China 			    pEepData->calTargetPower2G,
1385dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR5416_NUM_2G_20_TARGET_POWERS,
1386dd1de374Slin wang - Sun Microsystems - Beijing China 			    &targetPowerOfdmExt, 4, B_TRUE);
1387dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1388dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
1389dd1de374Slin wang - Sun Microsystems - Beijing China 		numCtlModes = ARRAY_SIZE(ctlModesFor11a) -
1390dd1de374Slin wang - Sun Microsystems - Beijing China 		    SUB_NUM_CTL_MODES_AT_5G_40;
1391dd1de374Slin wang - Sun Microsystems - Beijing China 		pCtlMode = ctlModesFor11a;
1392dd1de374Slin wang - Sun Microsystems - Beijing China 
1393dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_get_legacy_target_powers(ah, chan,
1394dd1de374Slin wang - Sun Microsystems - Beijing China 		    pEepData->calTargetPower5G,
1395dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR5416_NUM_5G_20_TARGET_POWERS,
1396dd1de374Slin wang - Sun Microsystems - Beijing China 		    &targetPowerOfdm, 4, B_FALSE);
1397dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_get_target_powers(ah, chan,
1398dd1de374Slin wang - Sun Microsystems - Beijing China 		    pEepData->calTargetPower5GHT20,
1399dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR5416_NUM_5G_20_TARGET_POWERS,
1400dd1de374Slin wang - Sun Microsystems - Beijing China 		    &targetPowerHt20, 8, B_FALSE);
1401dd1de374Slin wang - Sun Microsystems - Beijing China 
1402dd1de374Slin wang - Sun Microsystems - Beijing China 		if (IS_CHAN_HT40(chan)) {
1403dd1de374Slin wang - Sun Microsystems - Beijing China 			numCtlModes = ARRAY_SIZE(ctlModesFor11a);
1404dd1de374Slin wang - Sun Microsystems - Beijing China 			ath9k_hw_get_target_powers(ah, chan,
1405dd1de374Slin wang - Sun Microsystems - Beijing China 			    pEepData->calTargetPower5GHT40,
1406dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR5416_NUM_5G_40_TARGET_POWERS,
1407dd1de374Slin wang - Sun Microsystems - Beijing China 			    &targetPowerHt40, 8, B_TRUE);
1408dd1de374Slin wang - Sun Microsystems - Beijing China 			ath9k_hw_get_legacy_target_powers(ah, chan,
1409dd1de374Slin wang - Sun Microsystems - Beijing China 			    pEepData->calTargetPower5G,
1410dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR5416_NUM_5G_20_TARGET_POWERS,
1411dd1de374Slin wang - Sun Microsystems - Beijing China 			    &targetPowerOfdmExt, 4, B_TRUE);
1412dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1413dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1414dd1de374Slin wang - Sun Microsystems - Beijing China 
1415dd1de374Slin wang - Sun Microsystems - Beijing China 	for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
1416dd1de374Slin wang - Sun Microsystems - Beijing China 		boolean_t isHt40CtlMode =
1417dd1de374Slin wang - Sun Microsystems - Beijing China 		    (pCtlMode[ctlMode] == CTL_5GHT40) ||
1418dd1de374Slin wang - Sun Microsystems - Beijing China 		    (pCtlMode[ctlMode] == CTL_2GHT40);
1419dd1de374Slin wang - Sun Microsystems - Beijing China 		if (isHt40CtlMode)
1420dd1de374Slin wang - Sun Microsystems - Beijing China 			freq = centers.synth_center;
1421dd1de374Slin wang - Sun Microsystems - Beijing China 		else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
1422dd1de374Slin wang - Sun Microsystems - Beijing China 			freq = centers.ext_center;
1423dd1de374Slin wang - Sun Microsystems - Beijing China 		else
1424dd1de374Slin wang - Sun Microsystems - Beijing China 			freq = centers.ctl_center;
1425dd1de374Slin wang - Sun Microsystems - Beijing China 
1426dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ar5416_get_eep_ver(ahp) == 14 &&
1427dd1de374Slin wang - Sun Microsystems - Beijing China 		    ar5416_get_eep_rev(ahp) <= 2)
1428dd1de374Slin wang - Sun Microsystems - Beijing China 			twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
1429dd1de374Slin wang - Sun Microsystems - Beijing China 
1430dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_EEPROM, "arn: "
1431dd1de374Slin wang - Sun Microsystems - Beijing China 		    "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, "
1432dd1de374Slin wang - Sun Microsystems - Beijing China 		    "EXT_ADDITIVE %d\n",
1433dd1de374Slin wang - Sun Microsystems - Beijing China 		    ctlMode, numCtlModes, isHt40CtlMode,
1434dd1de374Slin wang - Sun Microsystems - Beijing China 		    (pCtlMode[ctlMode] & EXT_ADDITIVE)));
1435dd1de374Slin wang - Sun Microsystems - Beijing China 
1436dd1de374Slin wang - Sun Microsystems - Beijing China 		for (i = 0; (i < AR5416_NUM_CTLS) && pEepData->ctlIndex[i];
1437dd1de374Slin wang - Sun Microsystems - Beijing China 		    i++) {
1438dd1de374Slin wang - Sun Microsystems - Beijing China 
1439dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_EEPROM, "arn: "
1440dd1de374Slin wang - Sun Microsystems - Beijing China 			    "LOOP-Ctlidx %d: cfgCtl 0x%2.2x "
1441dd1de374Slin wang - Sun Microsystems - Beijing China 			    "pCtlMode 0x%2.2x ctlIndex 0x%2.2x "
1442dd1de374Slin wang - Sun Microsystems - Beijing China 			    "chan %d\n",
1443dd1de374Slin wang - Sun Microsystems - Beijing China 			    i, cfgCtl, pCtlMode[ctlMode],
1444dd1de374Slin wang - Sun Microsystems - Beijing China 			    pEepData->ctlIndex[i], chan->channel));
1445dd1de374Slin wang - Sun Microsystems - Beijing China 
1446dd1de374Slin wang - Sun Microsystems - Beijing China 			if ((((cfgCtl & ~CTL_MODE_M) |
1447dd1de374Slin wang - Sun Microsystems - Beijing China 			    (pCtlMode[ctlMode] & CTL_MODE_M)) ==
1448dd1de374Slin wang - Sun Microsystems - Beijing China 			    pEepData->ctlIndex[i]) ||
1449dd1de374Slin wang - Sun Microsystems - Beijing China 			    (((cfgCtl & ~CTL_MODE_M) |
1450dd1de374Slin wang - Sun Microsystems - Beijing China 			    (pCtlMode[ctlMode] & CTL_MODE_M)) ==
1451dd1de374Slin wang - Sun Microsystems - Beijing China 			    ((pEepData->ctlIndex[i] & CTL_MODE_M) |
1452dd1de374Slin wang - Sun Microsystems - Beijing China 			    SD_NO_CTL))) {
1453dd1de374Slin wang - Sun Microsystems - Beijing China 				rep = &(pEepData->ctlData[i]);
1454dd1de374Slin wang - Sun Microsystems - Beijing China 
1455dd1de374Slin wang - Sun Microsystems - Beijing China 				twiceMinEdgePower =
1456dd1de374Slin wang - Sun Microsystems - Beijing China 				    ath9k_hw_get_max_edge_power(freq,
1457dd1de374Slin wang - Sun Microsystems - Beijing China 				    rep->ctlEdges[ar5416_get_ntxchains
1458dd1de374Slin wang - Sun Microsystems - Beijing China 				    (tx_chainmask) - 1],
1459dd1de374Slin wang - Sun Microsystems - Beijing China 				    IS_CHAN_2GHZ(chan), AR5416_NUM_BAND_EDGES);
1460dd1de374Slin wang - Sun Microsystems - Beijing China 
1461dd1de374Slin wang - Sun Microsystems - Beijing China 				ARN_DBG((ARN_DBG_EEPROM, "arn: "
1462dd1de374Slin wang - Sun Microsystems - Beijing China 				    "MATCH-EE_IDX %d: ch %d is2 %d "
1463dd1de374Slin wang - Sun Microsystems - Beijing China 				    "2xMinEdge %d chainmask %d chains %d\n",
1464dd1de374Slin wang - Sun Microsystems - Beijing China 				    i, freq, IS_CHAN_2GHZ(chan),
1465dd1de374Slin wang - Sun Microsystems - Beijing China 				    twiceMinEdgePower, tx_chainmask,
1466dd1de374Slin wang - Sun Microsystems - Beijing China 				    ar5416_get_ntxchains(tx_chainmask)));
1467dd1de374Slin wang - Sun Microsystems - Beijing China 
1468dd1de374Slin wang - Sun Microsystems - Beijing China 				if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
1469dd1de374Slin wang - Sun Microsystems - Beijing China 					twiceMaxEdgePower =
1470dd1de374Slin wang - Sun Microsystems - Beijing China 					    min(twiceMaxEdgePower,
1471dd1de374Slin wang - Sun Microsystems - Beijing China 					    twiceMinEdgePower);
1472dd1de374Slin wang - Sun Microsystems - Beijing China 				} else {
1473dd1de374Slin wang - Sun Microsystems - Beijing China 					twiceMaxEdgePower = twiceMinEdgePower;
1474dd1de374Slin wang - Sun Microsystems - Beijing China 					break;
1475dd1de374Slin wang - Sun Microsystems - Beijing China 				}
1476dd1de374Slin wang - Sun Microsystems - Beijing China 			}
1477dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1478dd1de374Slin wang - Sun Microsystems - Beijing China 
1479dd1de374Slin wang - Sun Microsystems - Beijing China 		minCtlPower = min(twiceMaxEdgePower, scaledPower);
1480dd1de374Slin wang - Sun Microsystems - Beijing China 
1481dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_EEPROM, "arn: "
1482dd1de374Slin wang - Sun Microsystems - Beijing China 		    "SEL-Min ctlMode %d pCtlMode %d "
1483dd1de374Slin wang - Sun Microsystems - Beijing China 		    "2xMaxEdge %d sP %d minCtlPwr %d\n",
1484dd1de374Slin wang - Sun Microsystems - Beijing China 		    ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower,
1485dd1de374Slin wang - Sun Microsystems - Beijing China 		    scaledPower, minCtlPower));
1486dd1de374Slin wang - Sun Microsystems - Beijing China 
1487dd1de374Slin wang - Sun Microsystems - Beijing China 		switch (pCtlMode[ctlMode]) {
1488dd1de374Slin wang - Sun Microsystems - Beijing China 		case CTL_11B:
1489dd1de374Slin wang - Sun Microsystems - Beijing China 			for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x);
1490dd1de374Slin wang - Sun Microsystems - Beijing China 			    i++) {
1491dd1de374Slin wang - Sun Microsystems - Beijing China 				targetPowerCck.tPow2x[i] =
1492dd1de374Slin wang - Sun Microsystems - Beijing China 				    min((uint16_t)targetPowerCck.tPow2x[i],
1493dd1de374Slin wang - Sun Microsystems - Beijing China 				    minCtlPower);
1494dd1de374Slin wang - Sun Microsystems - Beijing China 			}
1495dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
1496dd1de374Slin wang - Sun Microsystems - Beijing China 		case CTL_11A:
1497dd1de374Slin wang - Sun Microsystems - Beijing China 		case CTL_11G:
1498dd1de374Slin wang - Sun Microsystems - Beijing China 			for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x);
1499dd1de374Slin wang - Sun Microsystems - Beijing China 			    i++) {
1500dd1de374Slin wang - Sun Microsystems - Beijing China 				targetPowerOfdm.tPow2x[i] =
1501dd1de374Slin wang - Sun Microsystems - Beijing China 				    min((uint16_t)targetPowerOfdm.tPow2x[i],
1502dd1de374Slin wang - Sun Microsystems - Beijing China 				    minCtlPower);
1503dd1de374Slin wang - Sun Microsystems - Beijing China 			}
1504dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
1505dd1de374Slin wang - Sun Microsystems - Beijing China 		case CTL_5GHT20:
1506dd1de374Slin wang - Sun Microsystems - Beijing China 		case CTL_2GHT20:
1507dd1de374Slin wang - Sun Microsystems - Beijing China 			for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x);
1508dd1de374Slin wang - Sun Microsystems - Beijing China 			    i++) {
1509dd1de374Slin wang - Sun Microsystems - Beijing China 				targetPowerHt20.tPow2x[i] =
1510dd1de374Slin wang - Sun Microsystems - Beijing China 				    min((uint16_t)targetPowerHt20.tPow2x[i],
1511dd1de374Slin wang - Sun Microsystems - Beijing China 				    minCtlPower);
1512dd1de374Slin wang - Sun Microsystems - Beijing China 			}
1513dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
1514dd1de374Slin wang - Sun Microsystems - Beijing China 		case CTL_11B_EXT:
1515dd1de374Slin wang - Sun Microsystems - Beijing China 			targetPowerCckExt.tPow2x[0] =
1516dd1de374Slin wang - Sun Microsystems - Beijing China 			    min((uint16_t)targetPowerCckExt.tPow2x[0],
1517dd1de374Slin wang - Sun Microsystems - Beijing China 			    minCtlPower);
1518dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
1519dd1de374Slin wang - Sun Microsystems - Beijing China 		case CTL_11A_EXT:
1520dd1de374Slin wang - Sun Microsystems - Beijing China 		case CTL_11G_EXT:
1521dd1de374Slin wang - Sun Microsystems - Beijing China 			targetPowerOfdmExt.tPow2x[0] =
1522dd1de374Slin wang - Sun Microsystems - Beijing China 			    min((uint16_t)targetPowerOfdmExt.tPow2x[0],
1523dd1de374Slin wang - Sun Microsystems - Beijing China 			    minCtlPower);
1524dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
1525dd1de374Slin wang - Sun Microsystems - Beijing China 		case CTL_5GHT40:
1526dd1de374Slin wang - Sun Microsystems - Beijing China 		case CTL_2GHT40:
1527dd1de374Slin wang - Sun Microsystems - Beijing China 			for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x);
1528dd1de374Slin wang - Sun Microsystems - Beijing China 			    i++) {
1529dd1de374Slin wang - Sun Microsystems - Beijing China 				targetPowerHt40.tPow2x[i] =
1530dd1de374Slin wang - Sun Microsystems - Beijing China 				    min((uint16_t)targetPowerHt40.tPow2x[i],
1531dd1de374Slin wang - Sun Microsystems - Beijing China 				    minCtlPower);
1532dd1de374Slin wang - Sun Microsystems - Beijing China 			}
1533dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
1534dd1de374Slin wang - Sun Microsystems - Beijing China 		default:
1535dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
1536dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1537dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1538dd1de374Slin wang - Sun Microsystems - Beijing China 
1539dd1de374Slin wang - Sun Microsystems - Beijing China 	ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] =
1540dd1de374Slin wang - Sun Microsystems - Beijing China 	    ratesArray[rate18mb] = ratesArray[rate24mb] =
1541dd1de374Slin wang - Sun Microsystems - Beijing China 	    targetPowerOfdm.tPow2x[0];
1542dd1de374Slin wang - Sun Microsystems - Beijing China 	ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
1543dd1de374Slin wang - Sun Microsystems - Beijing China 	ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
1544dd1de374Slin wang - Sun Microsystems - Beijing China 	ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
1545dd1de374Slin wang - Sun Microsystems - Beijing China 	ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
1546dd1de374Slin wang - Sun Microsystems - Beijing China 
1547dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
1548dd1de374Slin wang - Sun Microsystems - Beijing China 		ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
1549dd1de374Slin wang - Sun Microsystems - Beijing China 
1550dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_2GHZ(chan)) {
1551dd1de374Slin wang - Sun Microsystems - Beijing China 		ratesArray[rate1l] = targetPowerCck.tPow2x[0];
1552dd1de374Slin wang - Sun Microsystems - Beijing China 		ratesArray[rate2s] = ratesArray[rate2l] =
1553dd1de374Slin wang - Sun Microsystems - Beijing China 		    targetPowerCck.tPow2x[1];
1554dd1de374Slin wang - Sun Microsystems - Beijing China 		ratesArray[rate5_5s] = ratesArray[rate5_5l] =
1555dd1de374Slin wang - Sun Microsystems - Beijing China 		    targetPowerCck.tPow2x[2];
1556dd1de374Slin wang - Sun Microsystems - Beijing China 		;
1557dd1de374Slin wang - Sun Microsystems - Beijing China 		ratesArray[rate11s] = ratesArray[rate11l] =
1558dd1de374Slin wang - Sun Microsystems - Beijing China 		    targetPowerCck.tPow2x[3];
1559dd1de374Slin wang - Sun Microsystems - Beijing China 		;
1560dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1561dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_HT40(chan)) {
1562dd1de374Slin wang - Sun Microsystems - Beijing China 		for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
1563dd1de374Slin wang - Sun Microsystems - Beijing China 			ratesArray[rateHt40_0 + i] =
1564dd1de374Slin wang - Sun Microsystems - Beijing China 			    targetPowerHt40.tPow2x[i];
1565dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1566dd1de374Slin wang - Sun Microsystems - Beijing China 		ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
1567dd1de374Slin wang - Sun Microsystems - Beijing China 		ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
1568dd1de374Slin wang - Sun Microsystems - Beijing China 		ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
1569dd1de374Slin wang - Sun Microsystems - Beijing China 		if (IS_CHAN_2GHZ(chan)) {
1570dd1de374Slin wang - Sun Microsystems - Beijing China 			ratesArray[rateExtCck] =
1571dd1de374Slin wang - Sun Microsystems - Beijing China 			    targetPowerCckExt.tPow2x[0];
1572dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1573dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1574dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
1575dd1de374Slin wang - Sun Microsystems - Beijing China }
1576dd1de374Slin wang - Sun Microsystems - Beijing China 
1577dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t
1578dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_4k_power_per_rate_table(struct ath_hal *ah,
1579dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan,
1580dd1de374Slin wang - Sun Microsystems - Beijing China     int16_t *ratesArray,
1581dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t cfgCtl,
1582dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t AntennaReduction,
1583dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t twiceMaxRegulatoryPower,
1584dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t powerLimit)
1585dd1de374Slin wang - Sun Microsystems - Beijing China {
1586dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
1587dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ar5416_eeprom_4k *pEepData = &ahp->ah_eeprom.map4k;
1588dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
1589dd1de374Slin wang - Sun Microsystems - Beijing China 	static const uint16_t tpScaleReductionTable[5] =
1590dd1de374Slin wang - Sun Microsystems - Beijing China 		{ 0, 3, 6, 9, AR5416_MAX_RATE_POWER };
1591dd1de374Slin wang - Sun Microsystems - Beijing China 
1592dd1de374Slin wang - Sun Microsystems - Beijing China 	int i;
1593dd1de374Slin wang - Sun Microsystems - Beijing China 	int16_t twiceLargestAntenna;
1594dd1de374Slin wang - Sun Microsystems - Beijing China 	struct cal_ctl_data_4k *rep;
1595dd1de374Slin wang - Sun Microsystems - Beijing China 	struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
1596dd1de374Slin wang - Sun Microsystems - Beijing China 		0, { 0, 0, 0, 0}
1597dd1de374Slin wang - Sun Microsystems - Beijing China 	};
1598dd1de374Slin wang - Sun Microsystems - Beijing China 	struct cal_target_power_leg targetPowerOfdmExt = {
1599dd1de374Slin wang - Sun Microsystems - Beijing China 		0, { 0, 0, 0, 0} }, targetPowerCckExt = {
1600dd1de374Slin wang - Sun Microsystems - Beijing China 		0, { 0, 0, 0, 0 }
1601dd1de374Slin wang - Sun Microsystems - Beijing China 	};
1602dd1de374Slin wang - Sun Microsystems - Beijing China 	struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
1603dd1de374Slin wang - Sun Microsystems - Beijing China 		0, {0, 0, 0, 0}
1604dd1de374Slin wang - Sun Microsystems - Beijing China 	};
1605dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t scaledPower = 0, minCtlPower, maxRegAllowedPower;
1606dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t ctlModesFor11g[] =
1607dd1de374Slin wang - Sun Microsystems - Beijing China 	    { CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT,
1608dd1de374Slin wang - Sun Microsystems - Beijing China 	    CTL_2GHT40
1609dd1de374Slin wang - Sun Microsystems - Beijing China 	    };
1610dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t numCtlModes, *pCtlMode, ctlMode, freq;
1611dd1de374Slin wang - Sun Microsystems - Beijing China 	struct chan_centers centers;
1612dd1de374Slin wang - Sun Microsystems - Beijing China 	int tx_chainmask;
1613dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t twiceMinEdgePower;
1614dd1de374Slin wang - Sun Microsystems - Beijing China 
1615dd1de374Slin wang - Sun Microsystems - Beijing China 	tx_chainmask = ahp->ah_txchainmask;
1616dd1de374Slin wang - Sun Microsystems - Beijing China 
1617dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_get_channel_centers(ah, chan, &centers);
1618dd1de374Slin wang - Sun Microsystems - Beijing China 
1619dd1de374Slin wang - Sun Microsystems - Beijing China 	twiceLargestAntenna = pEepData->modalHeader.antennaGainCh[0];
1620dd1de374Slin wang - Sun Microsystems - Beijing China 
1621dd1de374Slin wang - Sun Microsystems - Beijing China 	twiceLargestAntenna =
1622dd1de374Slin wang - Sun Microsystems - Beijing China 	    (int16_t)min(AntennaReduction - twiceLargestAntenna, 0);
1623dd1de374Slin wang - Sun Microsystems - Beijing China 
1624dd1de374Slin wang - Sun Microsystems - Beijing China 	maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
1625dd1de374Slin wang - Sun Microsystems - Beijing China 
1626dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ah->ah_tpScale != ATH9K_TP_SCALE_MAX) {
1627dd1de374Slin wang - Sun Microsystems - Beijing China 		maxRegAllowedPower -=
1628dd1de374Slin wang - Sun Microsystems - Beijing China 		    (tpScaleReductionTable[(ah->ah_tpScale)] * 2);
1629dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1630dd1de374Slin wang - Sun Microsystems - Beijing China 
1631dd1de374Slin wang - Sun Microsystems - Beijing China 	scaledPower = min(powerLimit, maxRegAllowedPower);
1632dd1de374Slin wang - Sun Microsystems - Beijing China 	scaledPower = max((uint16_t)0, scaledPower);
1633dd1de374Slin wang - Sun Microsystems - Beijing China 
1634dd1de374Slin wang - Sun Microsystems - Beijing China 	numCtlModes = ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40;
1635dd1de374Slin wang - Sun Microsystems - Beijing China 	pCtlMode = ctlModesFor11g;
1636dd1de374Slin wang - Sun Microsystems - Beijing China 
1637dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_get_legacy_target_powers(ah, chan,
1638dd1de374Slin wang - Sun Microsystems - Beijing China 	    pEepData->calTargetPowerCck,
1639dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR5416_NUM_2G_CCK_TARGET_POWERS,
1640dd1de374Slin wang - Sun Microsystems - Beijing China 	    &targetPowerCck, 4, B_FALSE);
1641dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_get_legacy_target_powers(ah, chan,
1642dd1de374Slin wang - Sun Microsystems - Beijing China 	    pEepData->calTargetPower2G,
1643dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR5416_NUM_2G_20_TARGET_POWERS,
1644dd1de374Slin wang - Sun Microsystems - Beijing China 	    &targetPowerOfdm, 4, B_FALSE);
1645dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_get_target_powers(ah, chan,
1646dd1de374Slin wang - Sun Microsystems - Beijing China 	    pEepData->calTargetPower2GHT20,
1647dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR5416_NUM_2G_20_TARGET_POWERS,
1648dd1de374Slin wang - Sun Microsystems - Beijing China 	    &targetPowerHt20, 8, B_FALSE);
1649dd1de374Slin wang - Sun Microsystems - Beijing China 
1650dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_HT40(chan)) {
1651dd1de374Slin wang - Sun Microsystems - Beijing China 		numCtlModes = ARRAY_SIZE(ctlModesFor11g);
1652dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_get_target_powers(ah, chan,
1653dd1de374Slin wang - Sun Microsystems - Beijing China 		    pEepData->calTargetPower2GHT40,
1654dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR5416_NUM_2G_40_TARGET_POWERS,
1655dd1de374Slin wang - Sun Microsystems - Beijing China 		    &targetPowerHt40, 8, B_TRUE);
1656dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_get_legacy_target_powers(ah, chan,
1657dd1de374Slin wang - Sun Microsystems - Beijing China 		    pEepData->calTargetPowerCck,
1658dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR5416_NUM_2G_CCK_TARGET_POWERS,
1659dd1de374Slin wang - Sun Microsystems - Beijing China 		    &targetPowerCckExt, 4, B_TRUE);
1660dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_get_legacy_target_powers(ah, chan,
1661dd1de374Slin wang - Sun Microsystems - Beijing China 		    pEepData->calTargetPower2G,
1662dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR5416_NUM_2G_20_TARGET_POWERS,
1663dd1de374Slin wang - Sun Microsystems - Beijing China 		    &targetPowerOfdmExt, 4, B_TRUE);
1664dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1665dd1de374Slin wang - Sun Microsystems - Beijing China 
1666dd1de374Slin wang - Sun Microsystems - Beijing China 	for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
1667dd1de374Slin wang - Sun Microsystems - Beijing China 		boolean_t isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
1668dd1de374Slin wang - Sun Microsystems - Beijing China 		    (pCtlMode[ctlMode] == CTL_2GHT40);
1669dd1de374Slin wang - Sun Microsystems - Beijing China 		if (isHt40CtlMode)
1670dd1de374Slin wang - Sun Microsystems - Beijing China 			freq = centers.synth_center;
1671dd1de374Slin wang - Sun Microsystems - Beijing China 		else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
1672dd1de374Slin wang - Sun Microsystems - Beijing China 			freq = centers.ext_center;
1673dd1de374Slin wang - Sun Microsystems - Beijing China 		else
1674dd1de374Slin wang - Sun Microsystems - Beijing China 			freq = centers.ctl_center;
1675dd1de374Slin wang - Sun Microsystems - Beijing China 
1676dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ar5416_get_eep_ver(ahp) == 14 &&
1677dd1de374Slin wang - Sun Microsystems - Beijing China 		    ar5416_get_eep_rev(ahp) <= 2)
1678dd1de374Slin wang - Sun Microsystems - Beijing China 			twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
1679dd1de374Slin wang - Sun Microsystems - Beijing China 
1680dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_POWER_MGMT,
1681dd1de374Slin wang - Sun Microsystems - Beijing China 		    "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, "
1682dd1de374Slin wang - Sun Microsystems - Beijing China 		    "EXT_ADDITIVE %d\n",
1683dd1de374Slin wang - Sun Microsystems - Beijing China 		    ctlMode, numCtlModes, isHt40CtlMode,
1684dd1de374Slin wang - Sun Microsystems - Beijing China 		    (pCtlMode[ctlMode] & EXT_ADDITIVE)));
1685dd1de374Slin wang - Sun Microsystems - Beijing China 
1686dd1de374Slin wang - Sun Microsystems - Beijing China 		for (i = 0; (i < AR5416_NUM_CTLS) &&
1687dd1de374Slin wang - Sun Microsystems - Beijing China 		    pEepData->ctlIndex[i]; i++) {
1688dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_POWER_MGMT,
1689dd1de374Slin wang - Sun Microsystems - Beijing China 			    "  LOOP-Ctlidx %d: cfgCtl 0x%2.2x "
1690dd1de374Slin wang - Sun Microsystems - Beijing China 			    "pCtlMode 0x%2.2x ctlIndex 0x%2.2x "
1691dd1de374Slin wang - Sun Microsystems - Beijing China 			    "chan %d\n",
1692dd1de374Slin wang - Sun Microsystems - Beijing China 			    i, cfgCtl, pCtlMode[ctlMode],
1693dd1de374Slin wang - Sun Microsystems - Beijing China 			    pEepData->ctlIndex[i], chan->channel));
1694dd1de374Slin wang - Sun Microsystems - Beijing China 
1695dd1de374Slin wang - Sun Microsystems - Beijing China 			if ((((cfgCtl & ~CTL_MODE_M) |
1696dd1de374Slin wang - Sun Microsystems - Beijing China 			    (pCtlMode[ctlMode] & CTL_MODE_M)) ==
1697dd1de374Slin wang - Sun Microsystems - Beijing China 			    pEepData->ctlIndex[i]) ||
1698dd1de374Slin wang - Sun Microsystems - Beijing China 			    (((cfgCtl & ~CTL_MODE_M) |
1699dd1de374Slin wang - Sun Microsystems - Beijing China 			    (pCtlMode[ctlMode] & CTL_MODE_M)) ==
1700dd1de374Slin wang - Sun Microsystems - Beijing China 			    ((pEepData->ctlIndex[i] & CTL_MODE_M) |
1701dd1de374Slin wang - Sun Microsystems - Beijing China 			    SD_NO_CTL))) {
1702dd1de374Slin wang - Sun Microsystems - Beijing China 				rep = &(pEepData->ctlData[i]);
1703dd1de374Slin wang - Sun Microsystems - Beijing China 
1704dd1de374Slin wang - Sun Microsystems - Beijing China 				twiceMinEdgePower =
1705dd1de374Slin wang - Sun Microsystems - Beijing China 				    ath9k_hw_get_max_edge_power(freq,
1706dd1de374Slin wang - Sun Microsystems - Beijing China 				    rep->ctlEdges[ar5416_get_ntxchains
1707dd1de374Slin wang - Sun Microsystems - Beijing China 				    (tx_chainmask) - 1],
1708dd1de374Slin wang - Sun Microsystems - Beijing China 				    IS_CHAN_2GHZ(chan),
1709dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR5416_EEP4K_NUM_BAND_EDGES);
1710dd1de374Slin wang - Sun Microsystems - Beijing China 
1711dd1de374Slin wang - Sun Microsystems - Beijing China 				ARN_DBG((ARN_DBG_POWER_MGMT,
1712dd1de374Slin wang - Sun Microsystems - Beijing China 				    "   MATCH-EE_IDX %d: ch %d is2 %d "
1713dd1de374Slin wang - Sun Microsystems - Beijing China 				    "2xMinEdge %d chainmask %d chains %d\n",
1714dd1de374Slin wang - Sun Microsystems - Beijing China 				    i, freq, IS_CHAN_2GHZ(chan),
1715dd1de374Slin wang - Sun Microsystems - Beijing China 				    twiceMinEdgePower, tx_chainmask,
1716dd1de374Slin wang - Sun Microsystems - Beijing China 				    ar5416_get_ntxchains
1717dd1de374Slin wang - Sun Microsystems - Beijing China 				    (tx_chainmask)));
1718dd1de374Slin wang - Sun Microsystems - Beijing China 				if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
1719dd1de374Slin wang - Sun Microsystems - Beijing China 					twiceMaxEdgePower =
1720dd1de374Slin wang - Sun Microsystems - Beijing China 					    min(twiceMaxEdgePower,
1721dd1de374Slin wang - Sun Microsystems - Beijing China 					    twiceMinEdgePower);
1722dd1de374Slin wang - Sun Microsystems - Beijing China 				} else {
1723dd1de374Slin wang - Sun Microsystems - Beijing China 					twiceMaxEdgePower = twiceMinEdgePower;
1724dd1de374Slin wang - Sun Microsystems - Beijing China 					break;
1725dd1de374Slin wang - Sun Microsystems - Beijing China 				}
1726dd1de374Slin wang - Sun Microsystems - Beijing China 			}
1727dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1728dd1de374Slin wang - Sun Microsystems - Beijing China 
1729dd1de374Slin wang - Sun Microsystems - Beijing China 		minCtlPower = (uint8_t)min(twiceMaxEdgePower, scaledPower);
1730dd1de374Slin wang - Sun Microsystems - Beijing China 
1731dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_POWER_MGMT,
1732dd1de374Slin wang - Sun Microsystems - Beijing China 		    "    SEL-Min ctlMode %d pCtlMode %d "
1733dd1de374Slin wang - Sun Microsystems - Beijing China 		    "2xMaxEdge %d sP %d minCtlPwr %d\n",
1734dd1de374Slin wang - Sun Microsystems - Beijing China 		    ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower,
1735dd1de374Slin wang - Sun Microsystems - Beijing China 		    scaledPower, minCtlPower));
1736dd1de374Slin wang - Sun Microsystems - Beijing China 
1737dd1de374Slin wang - Sun Microsystems - Beijing China 		switch (pCtlMode[ctlMode]) {
1738dd1de374Slin wang - Sun Microsystems - Beijing China 		case CTL_11B:
1739dd1de374Slin wang - Sun Microsystems - Beijing China 			for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x);
1740dd1de374Slin wang - Sun Microsystems - Beijing China 			    i++) {
1741dd1de374Slin wang - Sun Microsystems - Beijing China 				targetPowerCck.tPow2x[i] =
1742dd1de374Slin wang - Sun Microsystems - Beijing China 				    min((uint16_t)targetPowerCck.tPow2x[i],
1743dd1de374Slin wang - Sun Microsystems - Beijing China 				    minCtlPower);
1744dd1de374Slin wang - Sun Microsystems - Beijing China 			}
1745dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
1746dd1de374Slin wang - Sun Microsystems - Beijing China 		case CTL_11G:
1747dd1de374Slin wang - Sun Microsystems - Beijing China 			for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x);
1748dd1de374Slin wang - Sun Microsystems - Beijing China 			    i++) {
1749dd1de374Slin wang - Sun Microsystems - Beijing China 				targetPowerOfdm.tPow2x[i] =
1750dd1de374Slin wang - Sun Microsystems - Beijing China 				    min((uint16_t)targetPowerOfdm.tPow2x[i],
1751dd1de374Slin wang - Sun Microsystems - Beijing China 				    minCtlPower);
1752dd1de374Slin wang - Sun Microsystems - Beijing China 			}
1753dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
1754dd1de374Slin wang - Sun Microsystems - Beijing China 		case CTL_2GHT20:
1755dd1de374Slin wang - Sun Microsystems - Beijing China 			for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x);
1756dd1de374Slin wang - Sun Microsystems - Beijing China 			    i++) {
1757dd1de374Slin wang - Sun Microsystems - Beijing China 				targetPowerHt20.tPow2x[i] =
1758dd1de374Slin wang - Sun Microsystems - Beijing China 				    min((uint16_t)targetPowerHt20.tPow2x[i],
1759dd1de374Slin wang - Sun Microsystems - Beijing China 				    minCtlPower);
1760dd1de374Slin wang - Sun Microsystems - Beijing China 			}
1761dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
1762dd1de374Slin wang - Sun Microsystems - Beijing China 		case CTL_11B_EXT:
1763dd1de374Slin wang - Sun Microsystems - Beijing China 			targetPowerCckExt.tPow2x[0] = min((uint16_t)
1764dd1de374Slin wang - Sun Microsystems - Beijing China 			    targetPowerCckExt.tPow2x[0],
1765dd1de374Slin wang - Sun Microsystems - Beijing China 			    minCtlPower);
1766dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
1767dd1de374Slin wang - Sun Microsystems - Beijing China 		case CTL_11G_EXT:
1768dd1de374Slin wang - Sun Microsystems - Beijing China 			targetPowerOfdmExt.tPow2x[0] = min((uint16_t)
1769dd1de374Slin wang - Sun Microsystems - Beijing China 			    targetPowerOfdmExt.tPow2x[0],
1770dd1de374Slin wang - Sun Microsystems - Beijing China 			    minCtlPower);
1771dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
1772dd1de374Slin wang - Sun Microsystems - Beijing China 		case CTL_2GHT40:
1773dd1de374Slin wang - Sun Microsystems - Beijing China 			for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x);
1774dd1de374Slin wang - Sun Microsystems - Beijing China 			    i++) {
1775dd1de374Slin wang - Sun Microsystems - Beijing China 				targetPowerHt40.tPow2x[i] =
1776dd1de374Slin wang - Sun Microsystems - Beijing China 				    min((uint16_t)targetPowerHt40.tPow2x[i],
1777dd1de374Slin wang - Sun Microsystems - Beijing China 				    minCtlPower);
1778dd1de374Slin wang - Sun Microsystems - Beijing China 			}
1779dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
1780dd1de374Slin wang - Sun Microsystems - Beijing China 		default:
1781dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
1782dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1783dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1784dd1de374Slin wang - Sun Microsystems - Beijing China 
1785dd1de374Slin wang - Sun Microsystems - Beijing China 	ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] =
1786dd1de374Slin wang - Sun Microsystems - Beijing China 	    ratesArray[rate18mb] = ratesArray[rate24mb] =
1787dd1de374Slin wang - Sun Microsystems - Beijing China 	    targetPowerOfdm.tPow2x[0];
1788dd1de374Slin wang - Sun Microsystems - Beijing China 	ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
1789dd1de374Slin wang - Sun Microsystems - Beijing China 	ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
1790dd1de374Slin wang - Sun Microsystems - Beijing China 	ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
1791dd1de374Slin wang - Sun Microsystems - Beijing China 	ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
1792dd1de374Slin wang - Sun Microsystems - Beijing China 
1793dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
1794dd1de374Slin wang - Sun Microsystems - Beijing China 		ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
1795dd1de374Slin wang - Sun Microsystems - Beijing China 
1796dd1de374Slin wang - Sun Microsystems - Beijing China 	ratesArray[rate1l] = targetPowerCck.tPow2x[0];
1797dd1de374Slin wang - Sun Microsystems - Beijing China 	ratesArray[rate2s] = ratesArray[rate2l] = targetPowerCck.tPow2x[1];
1798dd1de374Slin wang - Sun Microsystems - Beijing China 	ratesArray[rate5_5s] = ratesArray[rate5_5l] = targetPowerCck.tPow2x[2];
1799dd1de374Slin wang - Sun Microsystems - Beijing China 	ratesArray[rate11s] = ratesArray[rate11l] = targetPowerCck.tPow2x[3];
1800dd1de374Slin wang - Sun Microsystems - Beijing China 
1801dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_HT40(chan)) {
1802dd1de374Slin wang - Sun Microsystems - Beijing China 		for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
1803dd1de374Slin wang - Sun Microsystems - Beijing China 			ratesArray[rateHt40_0 + i] =
1804dd1de374Slin wang - Sun Microsystems - Beijing China 			    targetPowerHt40.tPow2x[i];
1805dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1806dd1de374Slin wang - Sun Microsystems - Beijing China 		ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
1807dd1de374Slin wang - Sun Microsystems - Beijing China 		ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
1808dd1de374Slin wang - Sun Microsystems - Beijing China 		ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
1809dd1de374Slin wang - Sun Microsystems - Beijing China 		ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0];
1810dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1811dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
1812dd1de374Slin wang - Sun Microsystems - Beijing China }
1813dd1de374Slin wang - Sun Microsystems - Beijing China 
1814dd1de374Slin wang - Sun Microsystems - Beijing China static int
1815dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_def_set_txpower(struct ath_hal *ah, struct ath9k_channel *chan,
1816dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t cfgCtl, uint8_t twiceAntennaReduction,
1817dd1de374Slin wang - Sun Microsystems - Beijing China     uint8_t twiceMaxRegulatoryPower, uint8_t powerLimit)
1818dd1de374Slin wang - Sun Microsystems - Beijing China {
1819dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
1820dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ar5416_eeprom_def *pEepData = &ahp->ah_eeprom.def;
1821dd1de374Slin wang - Sun Microsystems - Beijing China 	struct modal_eep_header *pModal =
1822dd1de374Slin wang - Sun Microsystems - Beijing China 	    &(pEepData->modalHeader[IS_CHAN_2GHZ(chan)]);
1823dd1de374Slin wang - Sun Microsystems - Beijing China 	int16_t ratesArray[Ar5416RateSize];
1824dd1de374Slin wang - Sun Microsystems - Beijing China 	int16_t txPowerIndexOffset = 0;
1825dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t ht40PowerIncForPdadc = 2;
1826dd1de374Slin wang - Sun Microsystems - Beijing China 	int i;
1827dd1de374Slin wang - Sun Microsystems - Beijing China 
1828dd1de374Slin wang - Sun Microsystems - Beijing China 	(void) memset(ratesArray, 0, sizeof (ratesArray));
1829dd1de374Slin wang - Sun Microsystems - Beijing China 
1830dd1de374Slin wang - Sun Microsystems - Beijing China 	if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1831dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR5416_EEP_MINOR_VER_2) {
1832dd1de374Slin wang - Sun Microsystems - Beijing China 		ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
1833dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1834dd1de374Slin wang - Sun Microsystems - Beijing China 
1835dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_set_def_power_per_rate_table(ah, chan,
1836dd1de374Slin wang - Sun Microsystems - Beijing China 	    &ratesArray[0], cfgCtl,
1837dd1de374Slin wang - Sun Microsystems - Beijing China 	    twiceAntennaReduction,
1838dd1de374Slin wang - Sun Microsystems - Beijing China 	    twiceMaxRegulatoryPower,
1839dd1de374Slin wang - Sun Microsystems - Beijing China 	    powerLimit)) {
1840dd1de374Slin wang - Sun Microsystems - Beijing China 
1841dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_EEPROM,
1842dd1de374Slin wang - Sun Microsystems - Beijing China 		    "ath9k_hw_set_txpower: unable to set "
1843dd1de374Slin wang - Sun Microsystems - Beijing China 		    "tx power per rate table\n"));
1844dd1de374Slin wang - Sun Microsystems - Beijing China 
1845dd1de374Slin wang - Sun Microsystems - Beijing China 		return (EIO);
1846dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1847dd1de374Slin wang - Sun Microsystems - Beijing China 
1848dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_set_def_power_cal_table(ah, chan, &txPowerIndexOffset)) {
1849dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_EEPROM, "ath9k: "
1850dd1de374Slin wang - Sun Microsystems - Beijing China 		    "ath9k_hw_set_txpower: unable to set power table\n"));
1851dd1de374Slin wang - Sun Microsystems - Beijing China 		return (EIO);
1852dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1853dd1de374Slin wang - Sun Microsystems - Beijing China 
1854dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
1855dd1de374Slin wang - Sun Microsystems - Beijing China 		ratesArray[i] =	(int16_t)(txPowerIndexOffset + ratesArray[i]);
1856dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ratesArray[i] > AR5416_MAX_RATE_POWER)
1857dd1de374Slin wang - Sun Microsystems - Beijing China 			ratesArray[i] = AR5416_MAX_RATE_POWER;
1858dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1859dd1de374Slin wang - Sun Microsystems - Beijing China 
1860dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280_10_OR_LATER(ah)) {
1861dd1de374Slin wang - Sun Microsystems - Beijing China 		for (i = 0; i < Ar5416RateSize; i++)
1862dd1de374Slin wang - Sun Microsystems - Beijing China 			ratesArray[i] -= AR5416_PWR_TABLE_OFFSET * 2;
1863dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1864dd1de374Slin wang - Sun Microsystems - Beijing China 
1865dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
1866dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rate18mb], 24) |
1867dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rate12mb], 16) |
1868dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rate9mb], 8) |
1869dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rate6mb], 0));
1870dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
1871dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rate54mb], 24) |
1872dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rate48mb], 16) |
1873dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rate36mb], 8) |
1874dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rate24mb], 0));
1875dd1de374Slin wang - Sun Microsystems - Beijing China 
1876dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_2GHZ(chan)) {
1877dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
1878dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rate2s], 24) |
1879dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rate2l], 16) |
1880dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateXr], 8) |
1881dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rate1l], 0));
1882dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
1883dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rate11s], 24) |
1884dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rate11l], 16) |
1885dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rate5_5s], 8) |
1886dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rate5_5l], 0));
1887dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1888dd1de374Slin wang - Sun Microsystems - Beijing China 
1889dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
1890dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rateHt20_3], 24) |
1891dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rateHt20_2], 16) |
1892dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rateHt20_1], 8) |
1893dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
1894dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
1895dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rateHt20_7], 24) |
1896dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rateHt20_6], 16) |
1897dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rateHt20_5], 8) |
1898dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
1899dd1de374Slin wang - Sun Microsystems - Beijing China 
1900dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_HT40(chan)) {
1901dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
1902dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateHt40_3] +
1903dd1de374Slin wang - Sun Microsystems - Beijing China 		    ht40PowerIncForPdadc, 24) |
1904dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateHt40_2] +
1905dd1de374Slin wang - Sun Microsystems - Beijing China 		    ht40PowerIncForPdadc, 16) |
1906dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateHt40_1] +
1907dd1de374Slin wang - Sun Microsystems - Beijing China 		    ht40PowerIncForPdadc, 8) |
1908dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateHt40_0] +
1909dd1de374Slin wang - Sun Microsystems - Beijing China 		    ht40PowerIncForPdadc, 0));
1910dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
1911dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateHt40_7] +
1912dd1de374Slin wang - Sun Microsystems - Beijing China 		    ht40PowerIncForPdadc, 24) |
1913dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateHt40_6] +
1914dd1de374Slin wang - Sun Microsystems - Beijing China 		    ht40PowerIncForPdadc, 16) |
1915dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateHt40_5] +
1916dd1de374Slin wang - Sun Microsystems - Beijing China 		    ht40PowerIncForPdadc, 8) |
1917dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateHt40_4] +
1918dd1de374Slin wang - Sun Microsystems - Beijing China 		    ht40PowerIncForPdadc, 0));
1919dd1de374Slin wang - Sun Microsystems - Beijing China 
1920dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
1921dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateExtOfdm], 24) |
1922dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateExtCck], 16) |
1923dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateDupOfdm], 8) |
1924dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateDupCck], 0));
1925dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1926dd1de374Slin wang - Sun Microsystems - Beijing China 
1927dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_POWER_TX_SUB,
1928dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(pModal->pwrDecreaseFor3Chain, 6) |
1929dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(pModal->pwrDecreaseFor2Chain, 0));
1930dd1de374Slin wang - Sun Microsystems - Beijing China 
1931dd1de374Slin wang - Sun Microsystems - Beijing China 	i = rate6mb;
1932dd1de374Slin wang - Sun Microsystems - Beijing China 
1933dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_HT40(chan))
1934dd1de374Slin wang - Sun Microsystems - Beijing China 		i = rateHt40_0;
1935dd1de374Slin wang - Sun Microsystems - Beijing China 	else if (IS_CHAN_HT20(chan))
1936dd1de374Slin wang - Sun Microsystems - Beijing China 		i = rateHt20_0;
1937dd1de374Slin wang - Sun Microsystems - Beijing China 
1938dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280_10_OR_LATER(ah))
1939dd1de374Slin wang - Sun Microsystems - Beijing China 		ah->ah_maxPowerLevel =
1940dd1de374Slin wang - Sun Microsystems - Beijing China 		    ratesArray[i] + AR5416_PWR_TABLE_OFFSET * 2;
1941dd1de374Slin wang - Sun Microsystems - Beijing China 	else
1942dd1de374Slin wang - Sun Microsystems - Beijing China 		ah->ah_maxPowerLevel = ratesArray[i];
1943dd1de374Slin wang - Sun Microsystems - Beijing China 
1944dd1de374Slin wang - Sun Microsystems - Beijing China 	return (0);
1945dd1de374Slin wang - Sun Microsystems - Beijing China }
1946dd1de374Slin wang - Sun Microsystems - Beijing China 
1947dd1de374Slin wang - Sun Microsystems - Beijing China static int
1948dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_4k_set_txpower(struct ath_hal *ah,
1949dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan,
1950dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t cfgCtl,
1951dd1de374Slin wang - Sun Microsystems - Beijing China     uint8_t twiceAntennaReduction,
1952dd1de374Slin wang - Sun Microsystems - Beijing China     uint8_t twiceMaxRegulatoryPower,
1953dd1de374Slin wang - Sun Microsystems - Beijing China     uint8_t powerLimit)
1954dd1de374Slin wang - Sun Microsystems - Beijing China {
1955dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
1956dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ar5416_eeprom_4k *pEepData = &ahp->ah_eeprom.map4k;
1957dd1de374Slin wang - Sun Microsystems - Beijing China 	struct modal_eep_4k_header *pModal = &pEepData->modalHeader;
1958dd1de374Slin wang - Sun Microsystems - Beijing China 	int16_t ratesArray[Ar5416RateSize];
1959dd1de374Slin wang - Sun Microsystems - Beijing China 	int16_t txPowerIndexOffset = 0;
1960dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t ht40PowerIncForPdadc = 2;
1961dd1de374Slin wang - Sun Microsystems - Beijing China 	int i;
1962dd1de374Slin wang - Sun Microsystems - Beijing China 
1963dd1de374Slin wang - Sun Microsystems - Beijing China 	(void) memset(ratesArray, 0, sizeof (ratesArray));
1964dd1de374Slin wang - Sun Microsystems - Beijing China 
1965dd1de374Slin wang - Sun Microsystems - Beijing China 	if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1966dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR5416_EEP_MINOR_VER_2) {
1967dd1de374Slin wang - Sun Microsystems - Beijing China 		ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
1968dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1969dd1de374Slin wang - Sun Microsystems - Beijing China 
1970dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_set_4k_power_per_rate_table(ah, chan,
1971dd1de374Slin wang - Sun Microsystems - Beijing China 	    &ratesArray[0], cfgCtl,
1972dd1de374Slin wang - Sun Microsystems - Beijing China 	    twiceAntennaReduction,
1973dd1de374Slin wang - Sun Microsystems - Beijing China 	    twiceMaxRegulatoryPower,
1974dd1de374Slin wang - Sun Microsystems - Beijing China 	    powerLimit)) {
1975dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_EEPROM,
1976dd1de374Slin wang - Sun Microsystems - Beijing China 		    "ath9k_hw_set_txpower: unable to set "
1977dd1de374Slin wang - Sun Microsystems - Beijing China 		    "tx power per rate table\n"));
1978dd1de374Slin wang - Sun Microsystems - Beijing China 		return (EIO);
1979dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1980dd1de374Slin wang - Sun Microsystems - Beijing China 
1981dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_set_4k_power_cal_table(ah, chan, &txPowerIndexOffset)) {
1982dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_EEPROM,
1983dd1de374Slin wang - Sun Microsystems - Beijing China 		    "ath9k_hw_set_txpower: unable to set power table\n"));
1984dd1de374Slin wang - Sun Microsystems - Beijing China 		return (EIO);
1985dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1986dd1de374Slin wang - Sun Microsystems - Beijing China 
1987dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
1988dd1de374Slin wang - Sun Microsystems - Beijing China 		ratesArray[i] =	(int16_t)(txPowerIndexOffset + ratesArray[i]);
1989dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ratesArray[i] > AR5416_MAX_RATE_POWER)
1990dd1de374Slin wang - Sun Microsystems - Beijing China 			ratesArray[i] = AR5416_MAX_RATE_POWER;
1991dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1992dd1de374Slin wang - Sun Microsystems - Beijing China 
1993dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280_10_OR_LATER(ah)) {
1994dd1de374Slin wang - Sun Microsystems - Beijing China 		for (i = 0; i < Ar5416RateSize; i++)
1995dd1de374Slin wang - Sun Microsystems - Beijing China 			ratesArray[i] -= AR5416_PWR_TABLE_OFFSET * 2;
1996dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1997dd1de374Slin wang - Sun Microsystems - Beijing China 
1998dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
1999dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rate18mb], 24) |
2000dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rate12mb], 16) |
2001dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rate9mb], 8) |
2002dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rate6mb], 0));
2003dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
2004dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rate54mb], 24) |
2005dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rate48mb], 16) |
2006dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rate36mb], 8) |
2007dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rate24mb], 0));
2008dd1de374Slin wang - Sun Microsystems - Beijing China 
2009dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_2GHZ(chan)) {
2010dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
2011dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rate2s], 24) |
2012dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rate2l], 16) |
2013dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateXr], 8) |
2014dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rate1l], 0));
2015dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
2016dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rate11s], 24) |
2017dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rate11l], 16) |
2018dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rate5_5s], 8) |
2019dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rate5_5l], 0));
2020dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2021dd1de374Slin wang - Sun Microsystems - Beijing China 
2022dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
2023dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rateHt20_3], 24) |
2024dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rateHt20_2], 16) |
2025dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rateHt20_1], 8) |
2026dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
2027dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
2028dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rateHt20_7], 24) |
2029dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rateHt20_6], 16) |
2030dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rateHt20_5], 8) |
2031dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
2032dd1de374Slin wang - Sun Microsystems - Beijing China 
2033dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_HT40(chan)) {
2034dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
2035dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateHt40_3] +
2036dd1de374Slin wang - Sun Microsystems - Beijing China 		    ht40PowerIncForPdadc, 24) |
2037dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateHt40_2] +
2038dd1de374Slin wang - Sun Microsystems - Beijing China 		    ht40PowerIncForPdadc, 16) |
2039dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateHt40_1] +
2040dd1de374Slin wang - Sun Microsystems - Beijing China 		    ht40PowerIncForPdadc, 8) |
2041dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateHt40_0] +
2042dd1de374Slin wang - Sun Microsystems - Beijing China 		    ht40PowerIncForPdadc, 0));
2043dd1de374Slin wang - Sun Microsystems - Beijing China 
2044dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
2045dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateHt40_7] +
2046dd1de374Slin wang - Sun Microsystems - Beijing China 		    ht40PowerIncForPdadc, 24) |
2047dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateHt40_6] +
2048dd1de374Slin wang - Sun Microsystems - Beijing China 		    ht40PowerIncForPdadc, 16) |
2049dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateHt40_5] +
2050dd1de374Slin wang - Sun Microsystems - Beijing China 		    ht40PowerIncForPdadc, 8) |
2051dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateHt40_4] +
2052dd1de374Slin wang - Sun Microsystems - Beijing China 		    ht40PowerIncForPdadc, 0));
2053dd1de374Slin wang - Sun Microsystems - Beijing China 
2054dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
2055dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateExtOfdm], 24) |
2056dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateExtCck], 16) |
2057dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateDupOfdm], 8) |
2058dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_POW_SM(ratesArray[rateDupCck], 0));
2059dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2060dd1de374Slin wang - Sun Microsystems - Beijing China 
2061dd1de374Slin wang - Sun Microsystems - Beijing China 	i = rate6mb;
2062dd1de374Slin wang - Sun Microsystems - Beijing China 
2063dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_HT40(chan))
2064dd1de374Slin wang - Sun Microsystems - Beijing China 		i = rateHt40_0;
2065dd1de374Slin wang - Sun Microsystems - Beijing China 	else if (IS_CHAN_HT20(chan))
2066dd1de374Slin wang - Sun Microsystems - Beijing China 		i = rateHt20_0;
2067dd1de374Slin wang - Sun Microsystems - Beijing China 
2068dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280_10_OR_LATER(ah))
2069dd1de374Slin wang - Sun Microsystems - Beijing China 		ah->ah_maxPowerLevel =
2070dd1de374Slin wang - Sun Microsystems - Beijing China 		    ratesArray[i] + AR5416_PWR_TABLE_OFFSET * 2;
2071dd1de374Slin wang - Sun Microsystems - Beijing China 	else
2072dd1de374Slin wang - Sun Microsystems - Beijing China 		ah->ah_maxPowerLevel = ratesArray[i];
2073dd1de374Slin wang - Sun Microsystems - Beijing China 
2074dd1de374Slin wang - Sun Microsystems - Beijing China 	return (0);
2075dd1de374Slin wang - Sun Microsystems - Beijing China }
2076dd1de374Slin wang - Sun Microsystems - Beijing China 
2077dd1de374Slin wang - Sun Microsystems - Beijing China int
2078dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_txpower(struct ath_hal *ah,
2079dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan,
2080dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t cfgCtl,
2081dd1de374Slin wang - Sun Microsystems - Beijing China     uint8_t twiceAntennaReduction,
2082dd1de374Slin wang - Sun Microsystems - Beijing China     uint8_t twiceMaxRegulatoryPower,
2083dd1de374Slin wang - Sun Microsystems - Beijing China     uint8_t powerLimit)
2084dd1de374Slin wang - Sun Microsystems - Beijing China {
2085dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
2086dd1de374Slin wang - Sun Microsystems - Beijing China 	int val;
2087dd1de374Slin wang - Sun Microsystems - Beijing China 
2088dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ahp->ah_eep_map == EEP_MAP_DEFAULT)
2089dd1de374Slin wang - Sun Microsystems - Beijing China 		val = ath9k_hw_def_set_txpower(ah, chan, cfgCtl,
2090dd1de374Slin wang - Sun Microsystems - Beijing China 		    twiceAntennaReduction, twiceMaxRegulatoryPower,
2091dd1de374Slin wang - Sun Microsystems - Beijing China 		    powerLimit);
2092dd1de374Slin wang - Sun Microsystems - Beijing China 	else if (ahp->ah_eep_map == EEP_MAP_4KBITS)
2093dd1de374Slin wang - Sun Microsystems - Beijing China 		val = ath9k_hw_4k_set_txpower(ah, chan, cfgCtl,
2094dd1de374Slin wang - Sun Microsystems - Beijing China 		    twiceAntennaReduction, twiceMaxRegulatoryPower,
2095dd1de374Slin wang - Sun Microsystems - Beijing China 		    powerLimit);
2096dd1de374Slin wang - Sun Microsystems - Beijing China 	return (val);
2097dd1de374Slin wang - Sun Microsystems - Beijing China }
2098dd1de374Slin wang - Sun Microsystems - Beijing China 
2099dd1de374Slin wang - Sun Microsystems - Beijing China static void
2100dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_def_addac(struct ath_hal *ah, struct ath9k_channel *chan)
2101dd1de374Slin wang - Sun Microsystems - Beijing China {
2102dd1de374Slin wang - Sun Microsystems - Beijing China #define	XPA_LVL_FREQ(cnt)	(pModal->xpaBiasLvlFreq[cnt])
2103dd1de374Slin wang - Sun Microsystems - Beijing China 	struct modal_eep_header *pModal;
2104dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
2105dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ar5416_eeprom_def *eep = &ahp->ah_eeprom.def;
2106dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t biaslevel;
2107dd1de374Slin wang - Sun Microsystems - Beijing China 
2108dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ah->ah_macVersion != AR_SREV_VERSION_9160)
2109dd1de374Slin wang - Sun Microsystems - Beijing China 		return;
2110dd1de374Slin wang - Sun Microsystems - Beijing China 
2111dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ar5416_get_eep_rev(ahp) < AR5416_EEP_MINOR_VER_7)
2112dd1de374Slin wang - Sun Microsystems - Beijing China 		return;
2113dd1de374Slin wang - Sun Microsystems - Beijing China 
2114dd1de374Slin wang - Sun Microsystems - Beijing China 	pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
2115dd1de374Slin wang - Sun Microsystems - Beijing China 
2116dd1de374Slin wang - Sun Microsystems - Beijing China 	if (pModal->xpaBiasLvl != 0xff) {
2117dd1de374Slin wang - Sun Microsystems - Beijing China 		biaslevel = pModal->xpaBiasLvl;
2118dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
2119dd1de374Slin wang - Sun Microsystems - Beijing China 		uint16_t resetFreqBin, freqBin, freqCount = 0;
2120dd1de374Slin wang - Sun Microsystems - Beijing China 		struct chan_centers centers;
2121dd1de374Slin wang - Sun Microsystems - Beijing China 
2122dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_get_channel_centers(ah, chan, &centers);
2123dd1de374Slin wang - Sun Microsystems - Beijing China 
2124dd1de374Slin wang - Sun Microsystems - Beijing China 		resetFreqBin =
2125dd1de374Slin wang - Sun Microsystems - Beijing China 		    FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan));
2126dd1de374Slin wang - Sun Microsystems - Beijing China 		freqBin = XPA_LVL_FREQ(freqCount) & 0xff;
2127dd1de374Slin wang - Sun Microsystems - Beijing China 		biaslevel = (uint8_t)(XPA_LVL_FREQ(0) >> 14);
2128dd1de374Slin wang - Sun Microsystems - Beijing China 
2129dd1de374Slin wang - Sun Microsystems - Beijing China 		freqCount++;
2130dd1de374Slin wang - Sun Microsystems - Beijing China 
2131dd1de374Slin wang - Sun Microsystems - Beijing China 		while (freqCount < 3) {
2132dd1de374Slin wang - Sun Microsystems - Beijing China 			if (XPA_LVL_FREQ(freqCount) == 0x0)
2133dd1de374Slin wang - Sun Microsystems - Beijing China 				break;
2134dd1de374Slin wang - Sun Microsystems - Beijing China 
2135dd1de374Slin wang - Sun Microsystems - Beijing China 			freqBin = XPA_LVL_FREQ(freqCount) & 0xff;
2136dd1de374Slin wang - Sun Microsystems - Beijing China 			if (resetFreqBin >= freqBin) {
2137dd1de374Slin wang - Sun Microsystems - Beijing China 				biaslevel =
2138dd1de374Slin wang - Sun Microsystems - Beijing China 				    (uint8_t)
2139dd1de374Slin wang - Sun Microsystems - Beijing China 				    (XPA_LVL_FREQ(freqCount) >> 14);
2140dd1de374Slin wang - Sun Microsystems - Beijing China 			} else {
2141dd1de374Slin wang - Sun Microsystems - Beijing China 				break;
2142dd1de374Slin wang - Sun Microsystems - Beijing China 			}
2143dd1de374Slin wang - Sun Microsystems - Beijing China 			freqCount++;
2144dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2145dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2146dd1de374Slin wang - Sun Microsystems - Beijing China 
2147dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_2GHZ(chan)) {
2148dd1de374Slin wang - Sun Microsystems - Beijing China 		INI_RA(&ahp->ah_iniAddac, 7, 1) =
2149dd1de374Slin wang - Sun Microsystems - Beijing China 		    (INI_RA(&ahp->ah_iniAddac, 7, 1) &
2150dd1de374Slin wang - Sun Microsystems - Beijing China 		    (~0x18)) | biaslevel << 3;
2151dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
2152dd1de374Slin wang - Sun Microsystems - Beijing China 		INI_RA(&ahp->ah_iniAddac, 6, 1) =
2153dd1de374Slin wang - Sun Microsystems - Beijing China 		    (INI_RA(&ahp->ah_iniAddac, 6, 1) &
2154dd1de374Slin wang - Sun Microsystems - Beijing China 		    (~0xc0)) | biaslevel << 6;
2155dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2156dd1de374Slin wang - Sun Microsystems - Beijing China #undef XPA_LVL_FREQ
2157dd1de374Slin wang - Sun Microsystems - Beijing China }
2158dd1de374Slin wang - Sun Microsystems - Beijing China 
2159dd1de374Slin wang - Sun Microsystems - Beijing China /* ARGSUSED */
2160dd1de374Slin wang - Sun Microsystems - Beijing China static void
2161dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_4k_addac(struct ath_hal *ah, struct ath9k_channel *chan)
2162dd1de374Slin wang - Sun Microsystems - Beijing China {
2163dd1de374Slin wang - Sun Microsystems - Beijing China 	struct modal_eep_4k_header *pModal;
2164dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
2165dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ar5416_eeprom_4k *eep = &ahp->ah_eeprom.map4k;
2166dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t biaslevel;
2167dd1de374Slin wang - Sun Microsystems - Beijing China 
2168dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ah->ah_macVersion != AR_SREV_VERSION_9160)
2169dd1de374Slin wang - Sun Microsystems - Beijing China 		return;
2170dd1de374Slin wang - Sun Microsystems - Beijing China 
2171dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ar5416_get_eep_rev(ahp) < AR5416_EEP_MINOR_VER_7)
2172dd1de374Slin wang - Sun Microsystems - Beijing China 		return;
2173dd1de374Slin wang - Sun Microsystems - Beijing China 
2174dd1de374Slin wang - Sun Microsystems - Beijing China 	pModal = &eep->modalHeader;
2175dd1de374Slin wang - Sun Microsystems - Beijing China 
2176dd1de374Slin wang - Sun Microsystems - Beijing China 	if (pModal->xpaBiasLvl != 0xff) {
2177dd1de374Slin wang - Sun Microsystems - Beijing China 		biaslevel = pModal->xpaBiasLvl;
2178dd1de374Slin wang - Sun Microsystems - Beijing China 		INI_RA(&ahp->ah_iniAddac, 7, 1) =
2179dd1de374Slin wang - Sun Microsystems - Beijing China 		    (INI_RA(&ahp->ah_iniAddac, 7, 1) & (~0x18)) |
2180dd1de374Slin wang - Sun Microsystems - Beijing China 		    biaslevel << 3;
2181dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2182dd1de374Slin wang - Sun Microsystems - Beijing China }
2183dd1de374Slin wang - Sun Microsystems - Beijing China 
2184dd1de374Slin wang - Sun Microsystems - Beijing China void
2185dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_addac(struct ath_hal *ah, struct ath9k_channel *chan)
2186dd1de374Slin wang - Sun Microsystems - Beijing China {
2187dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
2188dd1de374Slin wang - Sun Microsystems - Beijing China 
2189dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ahp->ah_eep_map == EEP_MAP_DEFAULT)
2190dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_set_def_addac(ah, chan);
2191dd1de374Slin wang - Sun Microsystems - Beijing China 	else if (ahp->ah_eep_map == EEP_MAP_4KBITS)
2192dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_set_4k_addac(ah, chan);
2193dd1de374Slin wang - Sun Microsystems - Beijing China }
2194dd1de374Slin wang - Sun Microsystems - Beijing China 
2195dd1de374Slin wang - Sun Microsystems - Beijing China /* XXX: Clean me up, make me more legible */
2196dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t
2197dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_eeprom_set_def_board_values(struct ath_hal *ah,
2198dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan)
2199dd1de374Slin wang - Sun Microsystems - Beijing China {
2200dd1de374Slin wang - Sun Microsystems - Beijing China 	struct modal_eep_header *pModal;
2201dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
2202dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ar5416_eeprom_def *eep = &ahp->ah_eeprom.def;
2203dd1de374Slin wang - Sun Microsystems - Beijing China 	int i, regChainOffset;
2204dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t txRxAttenLocal;
2205dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t ant_config;
2206dd1de374Slin wang - Sun Microsystems - Beijing China 
2207dd1de374Slin wang - Sun Microsystems - Beijing China 	pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
2208dd1de374Slin wang - Sun Microsystems - Beijing China 
2209dd1de374Slin wang - Sun Microsystems - Beijing China 	txRxAttenLocal = IS_CHAN_2GHZ(chan) ? 23 : 44;
2210dd1de374Slin wang - Sun Microsystems - Beijing China 
2211dd1de374Slin wang - Sun Microsystems - Beijing China 	(void) ath9k_hw_get_eeprom_antenna_cfg(ah, chan, 0, &ant_config);
2212dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_SWITCH_COM, ant_config);
2213dd1de374Slin wang - Sun Microsystems - Beijing China 
2214dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < AR5416_MAX_CHAINS; i++) {
2215dd1de374Slin wang - Sun Microsystems - Beijing China 		if (AR_SREV_9280(ah)) {
2216dd1de374Slin wang - Sun Microsystems - Beijing China 			if (i >= 2)
2217dd1de374Slin wang - Sun Microsystems - Beijing China 				break;
2218dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2219dd1de374Slin wang - Sun Microsystems - Beijing China 
2220dd1de374Slin wang - Sun Microsystems - Beijing China 		if (AR_SREV_5416_V20_OR_LATER(ah) &&
2221dd1de374Slin wang - Sun Microsystems - Beijing China 		    (ahp->ah_rxchainmask == 5 || ahp->ah_txchainmask == 5) &&
2222dd1de374Slin wang - Sun Microsystems - Beijing China 		    (i != 0))
2223dd1de374Slin wang - Sun Microsystems - Beijing China 			regChainOffset = (i == 1) ? 0x2000 : 0x1000;
2224dd1de374Slin wang - Sun Microsystems - Beijing China 		else
2225dd1de374Slin wang - Sun Microsystems - Beijing China 			regChainOffset = i * 0x1000;
2226dd1de374Slin wang - Sun Microsystems - Beijing China 
2227dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
2228dd1de374Slin wang - Sun Microsystems - Beijing China 		    pModal->antCtrlChain[i]);
2229dd1de374Slin wang - Sun Microsystems - Beijing China 
2230dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
2231dd1de374Slin wang - Sun Microsystems - Beijing China 		    (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) &
2232dd1de374Slin wang - Sun Microsystems - Beijing China 		    ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
2233dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
2234dd1de374Slin wang - Sun Microsystems - Beijing China 		    SM(pModal->iqCalICh[i],
2235dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
2236dd1de374Slin wang - Sun Microsystems - Beijing China 		    SM(pModal->iqCalQCh[i],
2237dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
2238dd1de374Slin wang - Sun Microsystems - Beijing China 
2239dd1de374Slin wang - Sun Microsystems - Beijing China 		if ((i == 0) || AR_SREV_5416_V20_OR_LATER(ah)) {
2240dd1de374Slin wang - Sun Microsystems - Beijing China 			if ((eep->baseEepHeader.version &
2241dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR5416_EEP_VER_MINOR_MASK) >=
2242dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR5416_EEP_MINOR_VER_3) {
2243dd1de374Slin wang - Sun Microsystems - Beijing China 				txRxAttenLocal = pModal->txRxAttenCh[i];
2244dd1de374Slin wang - Sun Microsystems - Beijing China 				if (AR_SREV_9280_10_OR_LATER(ah)) {
2245dd1de374Slin wang - Sun Microsystems - Beijing China 					REG_RMW_FIELD(ah,
2246dd1de374Slin wang - Sun Microsystems - Beijing China 					    AR_PHY_GAIN_2GHZ +
2247dd1de374Slin wang - Sun Microsystems - Beijing China 					    regChainOffset,
2248dd1de374Slin wang - Sun Microsystems - Beijing China 					    AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
2249dd1de374Slin wang - Sun Microsystems - Beijing China 					    pModal->
2250dd1de374Slin wang - Sun Microsystems - Beijing China 					    bswMargin[i]);
2251dd1de374Slin wang - Sun Microsystems - Beijing China 					REG_RMW_FIELD(ah,
2252dd1de374Slin wang - Sun Microsystems - Beijing China 					    AR_PHY_GAIN_2GHZ +
2253dd1de374Slin wang - Sun Microsystems - Beijing China 					    regChainOffset,
2254dd1de374Slin wang - Sun Microsystems - Beijing China 					    AR_PHY_GAIN_2GHZ_XATTEN1_DB,
2255dd1de374Slin wang - Sun Microsystems - Beijing China 					    pModal->
2256dd1de374Slin wang - Sun Microsystems - Beijing China 					    bswAtten[i]);
2257dd1de374Slin wang - Sun Microsystems - Beijing China 					REG_RMW_FIELD(ah,
2258dd1de374Slin wang - Sun Microsystems - Beijing China 					    AR_PHY_GAIN_2GHZ +
2259dd1de374Slin wang - Sun Microsystems - Beijing China 					    regChainOffset,
2260dd1de374Slin wang - Sun Microsystems - Beijing China 					    AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
2261dd1de374Slin wang - Sun Microsystems - Beijing China 					    pModal->
2262dd1de374Slin wang - Sun Microsystems - Beijing China 					    xatten2Margin[i]);
2263dd1de374Slin wang - Sun Microsystems - Beijing China 					REG_RMW_FIELD(ah,
2264dd1de374Slin wang - Sun Microsystems - Beijing China 					    AR_PHY_GAIN_2GHZ +
2265dd1de374Slin wang - Sun Microsystems - Beijing China 					    regChainOffset,
2266dd1de374Slin wang - Sun Microsystems - Beijing China 					    AR_PHY_GAIN_2GHZ_XATTEN2_DB,
2267dd1de374Slin wang - Sun Microsystems - Beijing China 					    pModal->
2268dd1de374Slin wang - Sun Microsystems - Beijing China 					    xatten2Db[i]);
2269dd1de374Slin wang - Sun Microsystems - Beijing China 				} else {
2270dd1de374Slin wang - Sun Microsystems - Beijing China 					REG_WRITE(ah,
2271dd1de374Slin wang - Sun Microsystems - Beijing China 					    AR_PHY_GAIN_2GHZ +
2272dd1de374Slin wang - Sun Microsystems - Beijing China 					    regChainOffset,
2273dd1de374Slin wang - Sun Microsystems - Beijing China 					    (REG_READ(ah,
2274dd1de374Slin wang - Sun Microsystems - Beijing China 					    AR_PHY_GAIN_2GHZ +
2275dd1de374Slin wang - Sun Microsystems - Beijing China 					    regChainOffset) &
2276dd1de374Slin wang - Sun Microsystems - Beijing China 					    ~AR_PHY_GAIN_2GHZ_BSW_MARGIN)
2277dd1de374Slin wang - Sun Microsystems - Beijing China 					    | SM(pModal->
2278dd1de374Slin wang - Sun Microsystems - Beijing China 					    bswMargin[i],
2279dd1de374Slin wang - Sun Microsystems - Beijing China 					    AR_PHY_GAIN_2GHZ_BSW_MARGIN));
2280dd1de374Slin wang - Sun Microsystems - Beijing China 					REG_WRITE(ah,
2281dd1de374Slin wang - Sun Microsystems - Beijing China 					    AR_PHY_GAIN_2GHZ +
2282dd1de374Slin wang - Sun Microsystems - Beijing China 					    regChainOffset,
2283dd1de374Slin wang - Sun Microsystems - Beijing China 					    (REG_READ(ah,
2284dd1de374Slin wang - Sun Microsystems - Beijing China 					    AR_PHY_GAIN_2GHZ +
2285dd1de374Slin wang - Sun Microsystems - Beijing China 					    regChainOffset) &
2286dd1de374Slin wang - Sun Microsystems - Beijing China 					    ~AR_PHY_GAIN_2GHZ_BSW_ATTEN)
2287dd1de374Slin wang - Sun Microsystems - Beijing China 					    | SM(pModal->bswAtten[i],
2288dd1de374Slin wang - Sun Microsystems - Beijing China 					    AR_PHY_GAIN_2GHZ_BSW_ATTEN));
2289dd1de374Slin wang - Sun Microsystems - Beijing China 				}
2290dd1de374Slin wang - Sun Microsystems - Beijing China 			}
2291dd1de374Slin wang - Sun Microsystems - Beijing China 			if (AR_SREV_9280_10_OR_LATER(ah)) {
2292dd1de374Slin wang - Sun Microsystems - Beijing China 				REG_RMW_FIELD(ah,
2293dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR_PHY_RXGAIN +
2294dd1de374Slin wang - Sun Microsystems - Beijing China 				    regChainOffset,
2295dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR9280_PHY_RXGAIN_TXRX_ATTEN,
2296dd1de374Slin wang - Sun Microsystems - Beijing China 				    txRxAttenLocal);
2297dd1de374Slin wang - Sun Microsystems - Beijing China 				REG_RMW_FIELD(ah,
2298dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR_PHY_RXGAIN +
2299dd1de374Slin wang - Sun Microsystems - Beijing China 				    regChainOffset,
2300dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR9280_PHY_RXGAIN_TXRX_MARGIN,
2301dd1de374Slin wang - Sun Microsystems - Beijing China 				    pModal->rxTxMarginCh[i]);
2302dd1de374Slin wang - Sun Microsystems - Beijing China 			} else {
2303dd1de374Slin wang - Sun Microsystems - Beijing China 				REG_WRITE(ah,
2304dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR_PHY_RXGAIN + regChainOffset,
2305dd1de374Slin wang - Sun Microsystems - Beijing China 				    (REG_READ(ah,
2306dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR_PHY_RXGAIN +
2307dd1de374Slin wang - Sun Microsystems - Beijing China 				    regChainOffset) &
2308dd1de374Slin wang - Sun Microsystems - Beijing China 				    ~AR_PHY_RXGAIN_TXRX_ATTEN) |
2309dd1de374Slin wang - Sun Microsystems - Beijing China 				    SM(txRxAttenLocal,
2310dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR_PHY_RXGAIN_TXRX_ATTEN));
2311dd1de374Slin wang - Sun Microsystems - Beijing China 				REG_WRITE(ah,
2312dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR_PHY_GAIN_2GHZ +
2313dd1de374Slin wang - Sun Microsystems - Beijing China 				    regChainOffset,
2314dd1de374Slin wang - Sun Microsystems - Beijing China 				    (REG_READ(ah,
2315dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR_PHY_GAIN_2GHZ +
2316dd1de374Slin wang - Sun Microsystems - Beijing China 				    regChainOffset) &
2317dd1de374Slin wang - Sun Microsystems - Beijing China 				    ~AR_PHY_GAIN_2GHZ_RXTX_MARGIN) |
2318dd1de374Slin wang - Sun Microsystems - Beijing China 				    SM(pModal->rxTxMarginCh[i],
2319dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR_PHY_GAIN_2GHZ_RXTX_MARGIN));
2320dd1de374Slin wang - Sun Microsystems - Beijing China 			}
2321dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2322dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2323dd1de374Slin wang - Sun Microsystems - Beijing China 
2324dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280_10_OR_LATER(ah)) {
2325dd1de374Slin wang - Sun Microsystems - Beijing China 		if (IS_CHAN_2GHZ(chan)) {
2326dd1de374Slin wang - Sun Microsystems - Beijing China 			ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
2327dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_AN_RF2G1_CH0_OB,
2328dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_AN_RF2G1_CH0_OB_S,
2329dd1de374Slin wang - Sun Microsystems - Beijing China 			    pModal->ob);
2330dd1de374Slin wang - Sun Microsystems - Beijing China 			ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
2331dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_AN_RF2G1_CH0_DB,
2332dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_AN_RF2G1_CH0_DB_S,
2333dd1de374Slin wang - Sun Microsystems - Beijing China 			    pModal->db);
2334dd1de374Slin wang - Sun Microsystems - Beijing China 			ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
2335dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_AN_RF2G1_CH1_OB,
2336dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_AN_RF2G1_CH1_OB_S,
2337dd1de374Slin wang - Sun Microsystems - Beijing China 			    pModal->ob_ch1);
2338dd1de374Slin wang - Sun Microsystems - Beijing China 			ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
2339dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_AN_RF2G1_CH1_DB,
2340dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_AN_RF2G1_CH1_DB_S,
2341dd1de374Slin wang - Sun Microsystems - Beijing China 			    pModal->db_ch1);
2342dd1de374Slin wang - Sun Microsystems - Beijing China 		} else {
2343dd1de374Slin wang - Sun Microsystems - Beijing China 			ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
2344dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_AN_RF5G1_CH0_OB5,
2345dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_AN_RF5G1_CH0_OB5_S,
2346dd1de374Slin wang - Sun Microsystems - Beijing China 			    pModal->ob);
2347dd1de374Slin wang - Sun Microsystems - Beijing China 			ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
2348dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_AN_RF5G1_CH0_DB5,
2349dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_AN_RF5G1_CH0_DB5_S,
2350dd1de374Slin wang - Sun Microsystems - Beijing China 			    pModal->db);
2351dd1de374Slin wang - Sun Microsystems - Beijing China 			ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
2352dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_AN_RF5G1_CH1_OB5,
2353dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_AN_RF5G1_CH1_OB5_S,
2354dd1de374Slin wang - Sun Microsystems - Beijing China 			    pModal->ob_ch1);
2355dd1de374Slin wang - Sun Microsystems - Beijing China 			ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
2356dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_AN_RF5G1_CH1_DB5,
2357dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_AN_RF5G1_CH1_DB5_S,
2358dd1de374Slin wang - Sun Microsystems - Beijing China 			    pModal->db_ch1);
2359dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2360dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
2361dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_AN_TOP2_XPABIAS_LVL,
2362dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_AN_TOP2_XPABIAS_LVL_S,
2363dd1de374Slin wang - Sun Microsystems - Beijing China 		    pModal->xpaBiasLvl);
2364dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
2365dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_AN_TOP2_LOCALBIAS,
2366dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_AN_TOP2_LOCALBIAS_S,
2367dd1de374Slin wang - Sun Microsystems - Beijing China 		    pModal->local_bias);
2368dd1de374Slin wang - Sun Microsystems - Beijing China 
2369dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_EEPROM, "arn: "
2370dd1de374Slin wang - Sun Microsystems - Beijing China 		    "ForceXPAon: %d\n", pModal->force_xpaon));
2371dd1de374Slin wang - Sun Microsystems - Beijing China 
2372dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_RMW_FIELD(ah, AR_PHY_XPA_CFG, AR_PHY_FORCE_XPA_CFG,
2373dd1de374Slin wang - Sun Microsystems - Beijing China 		    pModal->force_xpaon);
2374dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2375dd1de374Slin wang - Sun Microsystems - Beijing China 
2376dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
2377dd1de374Slin wang - Sun Microsystems - Beijing China 	    pModal->switchSettling);
2378dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
2379dd1de374Slin wang - Sun Microsystems - Beijing China 	    pModal->adcDesiredSize);
2380dd1de374Slin wang - Sun Microsystems - Beijing China 
2381dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!AR_SREV_9280_10_OR_LATER(ah))
2382dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
2383dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_DESIRED_SZ_PGA,
2384dd1de374Slin wang - Sun Microsystems - Beijing China 		    pModal->pgaDesiredSize);
2385dd1de374Slin wang - Sun Microsystems - Beijing China 
2386dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_RF_CTL4,
2387dd1de374Slin wang - Sun Microsystems - Beijing China 	    SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF) |
2388dd1de374Slin wang - Sun Microsystems - Beijing China 	    SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF) |
2389dd1de374Slin wang - Sun Microsystems - Beijing China 	    SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON) |
2390dd1de374Slin wang - Sun Microsystems - Beijing China 	    SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
2391dd1de374Slin wang - Sun Microsystems - Beijing China 
2392dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
2393dd1de374Slin wang - Sun Microsystems - Beijing China 	    pModal->txEndToRxOn);
2394dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280_10_OR_LATER(ah)) {
2395dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
2396dd1de374Slin wang - Sun Microsystems - Beijing China 		    pModal->thresh62);
2397dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
2398dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_EXT_CCA0_THRESH62,
2399dd1de374Slin wang - Sun Microsystems - Beijing China 		    pModal->thresh62);
2400dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
2401dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_RMW_FIELD(ah, AR_PHY_CCA, AR_PHY_CCA_THRESH62,
2402dd1de374Slin wang - Sun Microsystems - Beijing China 		    pModal->thresh62);
2403dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
2404dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_EXT_CCA_THRESH62,
2405dd1de374Slin wang - Sun Microsystems - Beijing China 		    pModal->thresh62);
2406dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2407dd1de374Slin wang - Sun Microsystems - Beijing China 
2408dd1de374Slin wang - Sun Microsystems - Beijing China 	if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
2409dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR5416_EEP_MINOR_VER_2) {
2410dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
2411dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_TX_END_DATA_START,
2412dd1de374Slin wang - Sun Microsystems - Beijing China 		    pModal->txFrameToDataStart);
2413dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
2414dd1de374Slin wang - Sun Microsystems - Beijing China 		    pModal->txFrameToPaOn);
2415dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2416dd1de374Slin wang - Sun Microsystems - Beijing China 
2417dd1de374Slin wang - Sun Microsystems - Beijing China 	if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
2418dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR5416_EEP_MINOR_VER_3) {
2419dd1de374Slin wang - Sun Microsystems - Beijing China 		if (IS_CHAN_HT40(chan))
2420dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_RMW_FIELD(ah, AR_PHY_SETTLING,
2421dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_PHY_SETTLING_SWITCH,
2422dd1de374Slin wang - Sun Microsystems - Beijing China 			    pModal->swSettleHt40);
2423dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2424dd1de374Slin wang - Sun Microsystems - Beijing China 
2425dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
2426dd1de374Slin wang - Sun Microsystems - Beijing China }
2427dd1de374Slin wang - Sun Microsystems - Beijing China 
2428dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t
2429dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_eeprom_set_4k_board_values(struct ath_hal *ah,
2430dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan)
2431dd1de374Slin wang - Sun Microsystems - Beijing China {
2432dd1de374Slin wang - Sun Microsystems - Beijing China 	struct modal_eep_4k_header *pModal;
2433dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
2434dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ar5416_eeprom_4k *eep = &ahp->ah_eeprom.map4k;
2435dd1de374Slin wang - Sun Microsystems - Beijing China 	int regChainOffset;
2436dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t txRxAttenLocal;
2437dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t ant_config = 0;
2438dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t ob[5], db1[5], db2[5];
2439dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t ant_div_control1, ant_div_control2;
2440dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t regVal;
2441dd1de374Slin wang - Sun Microsystems - Beijing China 
2442dd1de374Slin wang - Sun Microsystems - Beijing China 
2443dd1de374Slin wang - Sun Microsystems - Beijing China 	pModal = &eep->modalHeader;
2444dd1de374Slin wang - Sun Microsystems - Beijing China 
2445dd1de374Slin wang - Sun Microsystems - Beijing China 	txRxAttenLocal = 23;
2446dd1de374Slin wang - Sun Microsystems - Beijing China 
2447dd1de374Slin wang - Sun Microsystems - Beijing China 	(void) ath9k_hw_get_eeprom_antenna_cfg(ah, chan, 0, &ant_config);
2448dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_SWITCH_COM, ant_config);
2449dd1de374Slin wang - Sun Microsystems - Beijing China 
2450dd1de374Slin wang - Sun Microsystems - Beijing China 	regChainOffset = 0;
2451dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
2452dd1de374Slin wang - Sun Microsystems - Beijing China 	    pModal->antCtrlChain[0]);
2453dd1de374Slin wang - Sun Microsystems - Beijing China 
2454dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
2455dd1de374Slin wang - Sun Microsystems - Beijing China 	    (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) &
2456dd1de374Slin wang - Sun Microsystems - Beijing China 	    ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
2457dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
2458dd1de374Slin wang - Sun Microsystems - Beijing China 	    SM(pModal->iqCalICh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
2459dd1de374Slin wang - Sun Microsystems - Beijing China 	    SM(pModal->iqCalQCh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
2460dd1de374Slin wang - Sun Microsystems - Beijing China 
2461dd1de374Slin wang - Sun Microsystems - Beijing China 	if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
2462dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR5416_EEP_MINOR_VER_3) {
2463dd1de374Slin wang - Sun Microsystems - Beijing China 		txRxAttenLocal = pModal->txRxAttenCh[0];
2464dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
2465dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN, pModal->bswMargin[0]);
2466dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
2467dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_GAIN_2GHZ_XATTEN1_DB, pModal->bswAtten[0]);
2468dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
2469dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
2470dd1de374Slin wang - Sun Microsystems - Beijing China 		    pModal->xatten2Margin[0]);
2471dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
2472dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_GAIN_2GHZ_XATTEN2_DB, pModal->xatten2Db[0]);
2473dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2474dd1de374Slin wang - Sun Microsystems - Beijing China 
2475dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
2476dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
2477dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
2478dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[0]);
2479dd1de374Slin wang - Sun Microsystems - Beijing China 
2480dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9285_11(ah))
2481dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR9285_AN_TOP4, (AR9285_AN_TOP4_DEFAULT | 0x14));
2482dd1de374Slin wang - Sun Microsystems - Beijing China 
2483dd1de374Slin wang - Sun Microsystems - Beijing China 	/* Initialize Ant Diversity settings from EEPROM */
2484dd1de374Slin wang - Sun Microsystems - Beijing China 	if (pModal->version == 3) {
2485dd1de374Slin wang - Sun Microsystems - Beijing China 		ant_div_control1 = ((pModal->ob_234 >> 12) & 0xf);
2486dd1de374Slin wang - Sun Microsystems - Beijing China 		ant_div_control2 = ((pModal->db1_234 >> 12) & 0xf);
2487dd1de374Slin wang - Sun Microsystems - Beijing China 		regVal = REG_READ(ah, 0x99ac);
2488dd1de374Slin wang - Sun Microsystems - Beijing China 		regVal &= (~(0x7f000000));
2489dd1de374Slin wang - Sun Microsystems - Beijing China 		regVal |= ((ant_div_control1 & 0x1) << 24);
2490dd1de374Slin wang - Sun Microsystems - Beijing China 		regVal |= (((ant_div_control1 >> 1) & 0x1) << 29);
2491dd1de374Slin wang - Sun Microsystems - Beijing China 		regVal |= (((ant_div_control1 >> 2) & 0x1) << 30);
2492dd1de374Slin wang - Sun Microsystems - Beijing China 		regVal |= ((ant_div_control2 & 0x3) << 25);
2493dd1de374Slin wang - Sun Microsystems - Beijing China 		regVal |= (((ant_div_control2 >> 2) & 0x3) << 27);
2494dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, 0x99ac, regVal);
2495dd1de374Slin wang - Sun Microsystems - Beijing China 		regVal = REG_READ(ah, 0x99ac);
2496dd1de374Slin wang - Sun Microsystems - Beijing China 		regVal = REG_READ(ah, 0xa208);
2497dd1de374Slin wang - Sun Microsystems - Beijing China 		regVal &= (~(0x1 << 13));
2498dd1de374Slin wang - Sun Microsystems - Beijing China 		regVal |= (((ant_div_control1 >> 3) & 0x1) << 13);
2499dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, 0xa208, regVal);
2500dd1de374Slin wang - Sun Microsystems - Beijing China 		regVal = REG_READ(ah, 0xa208);
2501dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2502dd1de374Slin wang - Sun Microsystems - Beijing China 
2503dd1de374Slin wang - Sun Microsystems - Beijing China 	if (pModal->version >= 2) {
2504dd1de374Slin wang - Sun Microsystems - Beijing China 		ob[0] = (pModal->ob_01 & 0xf);
2505dd1de374Slin wang - Sun Microsystems - Beijing China 		ob[1] = (pModal->ob_01 >> 4) & 0xf;
2506dd1de374Slin wang - Sun Microsystems - Beijing China 		ob[2] = (pModal->ob_234 & 0xf);
2507dd1de374Slin wang - Sun Microsystems - Beijing China 		ob[3] = ((pModal->ob_234 >> 4) & 0xf);
2508dd1de374Slin wang - Sun Microsystems - Beijing China 		ob[4] = ((pModal->ob_234 >> 8) & 0xf);
2509dd1de374Slin wang - Sun Microsystems - Beijing China 
2510dd1de374Slin wang - Sun Microsystems - Beijing China 		db1[0] = (pModal->db1_01 & 0xf);
2511dd1de374Slin wang - Sun Microsystems - Beijing China 		db1[1] = ((pModal->db1_01 >> 4) & 0xf);
2512dd1de374Slin wang - Sun Microsystems - Beijing China 		db1[2] = (pModal->db1_234 & 0xf);
2513dd1de374Slin wang - Sun Microsystems - Beijing China 		db1[3] = ((pModal->db1_234 >> 4) & 0xf);
2514dd1de374Slin wang - Sun Microsystems - Beijing China 		db1[4] = ((pModal->db1_234 >> 8) & 0xf);
2515dd1de374Slin wang - Sun Microsystems - Beijing China 
2516dd1de374Slin wang - Sun Microsystems - Beijing China 		db2[0] = (pModal->db2_01 & 0xf);
2517dd1de374Slin wang - Sun Microsystems - Beijing China 		db2[1] = ((pModal->db2_01 >> 4) & 0xf);
2518dd1de374Slin wang - Sun Microsystems - Beijing China 		db2[2] = (pModal->db2_234 & 0xf);
2519dd1de374Slin wang - Sun Microsystems - Beijing China 		db2[3] = ((pModal->db2_234 >> 4) & 0xf);
2520dd1de374Slin wang - Sun Microsystems - Beijing China 		db2[4] = ((pModal->db2_234 >> 8) & 0xf);
2521dd1de374Slin wang - Sun Microsystems - Beijing China 
2522dd1de374Slin wang - Sun Microsystems - Beijing China 	} else if (pModal->version == 1) {
2523dd1de374Slin wang - Sun Microsystems - Beijing China 
2524dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_EEPROM,
2525dd1de374Slin wang - Sun Microsystems - Beijing China 		    "EEPROM Model version is set to 1 \n"));
2526dd1de374Slin wang - Sun Microsystems - Beijing China 		ob[0] = (pModal->ob_01 & 0xf);
2527dd1de374Slin wang - Sun Microsystems - Beijing China 		ob[1] = ob[2] = ob[3] = ob[4] = (pModal->ob_01 >> 4) & 0xf;
2528dd1de374Slin wang - Sun Microsystems - Beijing China 		db1[0] = (pModal->db1_01 & 0xf);
2529dd1de374Slin wang - Sun Microsystems - Beijing China 		db1[1] = db1[2] = db1[3] = db1[4] =
2530dd1de374Slin wang - Sun Microsystems - Beijing China 		    ((pModal->db1_01 >> 4) & 0xf);
2531dd1de374Slin wang - Sun Microsystems - Beijing China 		db2[0] = (pModal->db2_01 & 0xf);
2532dd1de374Slin wang - Sun Microsystems - Beijing China 		db2[1] = db2[2] = db2[3] = db2[4] =
2533dd1de374Slin wang - Sun Microsystems - Beijing China 		    ((pModal->db2_01 >> 4) & 0xf);
2534dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
2535dd1de374Slin wang - Sun Microsystems - Beijing China 		int i;
2536dd1de374Slin wang - Sun Microsystems - Beijing China 		for (i = 0; i < 5; i++) {
2537dd1de374Slin wang - Sun Microsystems - Beijing China 			ob[i] = pModal->ob_01;
2538dd1de374Slin wang - Sun Microsystems - Beijing China 			db1[i] = pModal->db1_01;
2539dd1de374Slin wang - Sun Microsystems - Beijing China 			db2[i] = pModal->db1_01;
2540dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2541dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2542dd1de374Slin wang - Sun Microsystems - Beijing China 
2543dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
2544dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR9285_AN_RF2G3_OB_0, AR9285_AN_RF2G3_OB_0_S, ob[0]);
2545dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
2546dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR9285_AN_RF2G3_OB_1, AR9285_AN_RF2G3_OB_1_S, ob[1]);
2547dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
2548dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR9285_AN_RF2G3_OB_2, AR9285_AN_RF2G3_OB_2_S, ob[2]);
2549dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
2550dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR9285_AN_RF2G3_OB_3, AR9285_AN_RF2G3_OB_3_S, ob[3]);
2551dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
2552dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR9285_AN_RF2G3_OB_4, AR9285_AN_RF2G3_OB_4_S, ob[4]);
2553dd1de374Slin wang - Sun Microsystems - Beijing China 
2554dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
2555dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR9285_AN_RF2G3_DB1_0, AR9285_AN_RF2G3_DB1_0_S, db1[0]);
2556dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
2557dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR9285_AN_RF2G3_DB1_1, AR9285_AN_RF2G3_DB1_1_S, db1[1]);
2558dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
2559dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR9285_AN_RF2G3_DB1_2, AR9285_AN_RF2G3_DB1_2_S, db1[2]);
2560dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
2561dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR9285_AN_RF2G4_DB1_3, AR9285_AN_RF2G4_DB1_3_S, db1[3]);
2562dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
2563dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR9285_AN_RF2G4_DB1_4, AR9285_AN_RF2G4_DB1_4_S, db1[4]);
2564dd1de374Slin wang - Sun Microsystems - Beijing China 
2565dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
2566dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR9285_AN_RF2G4_DB2_0, AR9285_AN_RF2G4_DB2_0_S, db2[0]);
2567dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
2568dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR9285_AN_RF2G4_DB2_1, AR9285_AN_RF2G4_DB2_1_S, db2[1]);
2569dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
2570dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR9285_AN_RF2G4_DB2_2, AR9285_AN_RF2G4_DB2_2_S, db2[2]);
2571dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
2572dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR9285_AN_RF2G4_DB2_3, AR9285_AN_RF2G4_DB2_3_S, db2[3]);
2573dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
2574dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR9285_AN_RF2G4_DB2_4, AR9285_AN_RF2G4_DB2_4_S, db2[4]);
2575dd1de374Slin wang - Sun Microsystems - Beijing China 
2576dd1de374Slin wang - Sun Microsystems - Beijing China 
2577dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9285_11(ah))
2578dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR9285_AN_TOP4, AR9285_AN_TOP4_DEFAULT);
2579dd1de374Slin wang - Sun Microsystems - Beijing China 
2580dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
2581dd1de374Slin wang - Sun Microsystems - Beijing China 	    pModal->switchSettling);
2582dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
2583dd1de374Slin wang - Sun Microsystems - Beijing China 	    pModal->adcDesiredSize);
2584dd1de374Slin wang - Sun Microsystems - Beijing China 
2585dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_RF_CTL4,
2586dd1de374Slin wang - Sun Microsystems - Beijing China 	    SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF) |
2587dd1de374Slin wang - Sun Microsystems - Beijing China 	    SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF) |
2588dd1de374Slin wang - Sun Microsystems - Beijing China 	    SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON)  |
2589dd1de374Slin wang - Sun Microsystems - Beijing China 	    SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
2590dd1de374Slin wang - Sun Microsystems - Beijing China 
2591dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
2592dd1de374Slin wang - Sun Microsystems - Beijing China 	    pModal->txEndToRxOn);
2593dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
2594dd1de374Slin wang - Sun Microsystems - Beijing China 	    pModal->thresh62);
2595dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0, AR_PHY_EXT_CCA0_THRESH62,
2596dd1de374Slin wang - Sun Microsystems - Beijing China 	    pModal->thresh62);
2597dd1de374Slin wang - Sun Microsystems - Beijing China 
2598dd1de374Slin wang - Sun Microsystems - Beijing China 	if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
2599dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR5416_EEP_MINOR_VER_2) {
2600dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_DATA_START,
2601dd1de374Slin wang - Sun Microsystems - Beijing China 		    pModal->txFrameToDataStart);
2602dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
2603dd1de374Slin wang - Sun Microsystems - Beijing China 		    pModal->txFrameToPaOn);
2604dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2605dd1de374Slin wang - Sun Microsystems - Beijing China 
2606dd1de374Slin wang - Sun Microsystems - Beijing China 	if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
2607dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR5416_EEP_MINOR_VER_3) {
2608dd1de374Slin wang - Sun Microsystems - Beijing China 		if (IS_CHAN_HT40(chan))
2609dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_RMW_FIELD(ah, AR_PHY_SETTLING,
2610dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_PHY_SETTLING_SWITCH, pModal->swSettleHt40);
2611dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2612dd1de374Slin wang - Sun Microsystems - Beijing China 
2613dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
2614dd1de374Slin wang - Sun Microsystems - Beijing China }
2615dd1de374Slin wang - Sun Microsystems - Beijing China 
2616dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
2617dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_eeprom_set_board_values(struct ath_hal *ah, struct ath9k_channel *chan)
2618dd1de374Slin wang - Sun Microsystems - Beijing China {
2619dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
2620dd1de374Slin wang - Sun Microsystems - Beijing China 	boolean_t val;
2621dd1de374Slin wang - Sun Microsystems - Beijing China 
2622dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ahp->ah_eep_map == EEP_MAP_DEFAULT)
2623dd1de374Slin wang - Sun Microsystems - Beijing China 		val = ath9k_hw_eeprom_set_def_board_values(ah, chan);
2624dd1de374Slin wang - Sun Microsystems - Beijing China 	else if (ahp->ah_eep_map == EEP_MAP_4KBITS)
2625dd1de374Slin wang - Sun Microsystems - Beijing China 		val = ath9k_hw_eeprom_set_4k_board_values(ah, chan);
2626dd1de374Slin wang - Sun Microsystems - Beijing China 
2627dd1de374Slin wang - Sun Microsystems - Beijing China 	return (val);
2628dd1de374Slin wang - Sun Microsystems - Beijing China }
2629dd1de374Slin wang - Sun Microsystems - Beijing China 
2630dd1de374Slin wang - Sun Microsystems - Beijing China static int
2631dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_get_def_eeprom_antenna_cfg(struct ath_hal *ah,
2632dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan,
2633dd1de374Slin wang - Sun Microsystems - Beijing China     uint8_t index, uint16_t *config)
2634dd1de374Slin wang - Sun Microsystems - Beijing China {
2635dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
2636dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ar5416_eeprom_def *eep = &ahp->ah_eeprom.def;
2637dd1de374Slin wang - Sun Microsystems - Beijing China 	struct modal_eep_header *pModal =
2638dd1de374Slin wang - Sun Microsystems - Beijing China 	    &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
2639dd1de374Slin wang - Sun Microsystems - Beijing China 	struct base_eep_header *pBase = &eep->baseEepHeader;
2640dd1de374Slin wang - Sun Microsystems - Beijing China 
2641dd1de374Slin wang - Sun Microsystems - Beijing China 	switch (index) {
2642dd1de374Slin wang - Sun Microsystems - Beijing China 	case 0:
2643dd1de374Slin wang - Sun Microsystems - Beijing China 		*config = pModal->antCtrlCommon & 0xFFFF;
2644dd1de374Slin wang - Sun Microsystems - Beijing China 		return (0);
2645dd1de374Slin wang - Sun Microsystems - Beijing China 	case 1:
2646dd1de374Slin wang - Sun Microsystems - Beijing China 		if (pBase->version >= 0x0E0D) {
2647dd1de374Slin wang - Sun Microsystems - Beijing China 			if (pModal->useAnt1) {
2648dd1de374Slin wang - Sun Microsystems - Beijing China 				*config =
2649dd1de374Slin wang - Sun Microsystems - Beijing China 				    ((pModal->antCtrlCommon & 0xFFFF0000)
2650dd1de374Slin wang - Sun Microsystems - Beijing China 				    >> 16);
2651dd1de374Slin wang - Sun Microsystems - Beijing China 				return (0);
2652dd1de374Slin wang - Sun Microsystems - Beijing China 			}
2653dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2654dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
2655dd1de374Slin wang - Sun Microsystems - Beijing China 	default:
2656dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
2657dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2658dd1de374Slin wang - Sun Microsystems - Beijing China 
2659dd1de374Slin wang - Sun Microsystems - Beijing China 	return (-EINVAL);
2660dd1de374Slin wang - Sun Microsystems - Beijing China }
2661dd1de374Slin wang - Sun Microsystems - Beijing China 
2662dd1de374Slin wang - Sun Microsystems - Beijing China /* ARGSUSED */
2663dd1de374Slin wang - Sun Microsystems - Beijing China static int
2664dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_get_4k_eeprom_antenna_cfg(struct ath_hal *ah,
2665dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan,
2666dd1de374Slin wang - Sun Microsystems - Beijing China     uint8_t index, uint16_t *config)
2667dd1de374Slin wang - Sun Microsystems - Beijing China {
2668dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
2669dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ar5416_eeprom_4k *eep = &ahp->ah_eeprom.map4k;
2670dd1de374Slin wang - Sun Microsystems - Beijing China 	struct modal_eep_4k_header *pModal = &eep->modalHeader;
2671dd1de374Slin wang - Sun Microsystems - Beijing China 
2672dd1de374Slin wang - Sun Microsystems - Beijing China 	switch (index) {
2673dd1de374Slin wang - Sun Microsystems - Beijing China 	case 0:
2674dd1de374Slin wang - Sun Microsystems - Beijing China 		*config = pModal->antCtrlCommon & 0xFFFF;
2675dd1de374Slin wang - Sun Microsystems - Beijing China 		return (0);
2676dd1de374Slin wang - Sun Microsystems - Beijing China 	default:
2677dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
2678dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2679dd1de374Slin wang - Sun Microsystems - Beijing China 
2680dd1de374Slin wang - Sun Microsystems - Beijing China 	return (EINVAL);
2681dd1de374Slin wang - Sun Microsystems - Beijing China }
2682dd1de374Slin wang - Sun Microsystems - Beijing China 
2683dd1de374Slin wang - Sun Microsystems - Beijing China int
2684dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_get_eeprom_antenna_cfg(struct ath_hal *ah,
2685dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan,
2686dd1de374Slin wang - Sun Microsystems - Beijing China     uint8_t index, uint16_t *config)
2687dd1de374Slin wang - Sun Microsystems - Beijing China {
2688dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
2689dd1de374Slin wang - Sun Microsystems - Beijing China 	int val;
2690dd1de374Slin wang - Sun Microsystems - Beijing China 
2691dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ahp->ah_eep_map == EEP_MAP_DEFAULT)
2692dd1de374Slin wang - Sun Microsystems - Beijing China 		val = ath9k_hw_get_def_eeprom_antenna_cfg(ah, chan,
2693dd1de374Slin wang - Sun Microsystems - Beijing China 		    index, config);
2694dd1de374Slin wang - Sun Microsystems - Beijing China 	else if (ahp->ah_eep_map == EEP_MAP_4KBITS)
2695dd1de374Slin wang - Sun Microsystems - Beijing China 		val = ath9k_hw_get_4k_eeprom_antenna_cfg(ah, chan,
2696dd1de374Slin wang - Sun Microsystems - Beijing China 		    index, config);
2697dd1de374Slin wang - Sun Microsystems - Beijing China 
2698dd1de374Slin wang - Sun Microsystems - Beijing China 	return (val);
2699dd1de374Slin wang - Sun Microsystems - Beijing China }
2700dd1de374Slin wang - Sun Microsystems - Beijing China 
2701dd1de374Slin wang - Sun Microsystems - Beijing China /* ARGSUSED */
2702dd1de374Slin wang - Sun Microsystems - Beijing China static uint8_t
2703dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_get_4k_num_ant_config(struct ath_hal *ah,
2704dd1de374Slin wang - Sun Microsystems - Beijing China     enum ath9k_band freq_band)
2705dd1de374Slin wang - Sun Microsystems - Beijing China {
2706dd1de374Slin wang - Sun Microsystems - Beijing China 	return (1);
2707dd1de374Slin wang - Sun Microsystems - Beijing China }
2708dd1de374Slin wang - Sun Microsystems - Beijing China 
2709dd1de374Slin wang - Sun Microsystems - Beijing China static uint8_t
2710dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_get_def_num_ant_config(struct ath_hal *ah,
2711dd1de374Slin wang - Sun Microsystems - Beijing China     enum ath9k_band freq_band)
2712dd1de374Slin wang - Sun Microsystems - Beijing China {
2713dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
2714dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ar5416_eeprom_def *eep = &ahp->ah_eeprom.def;
2715dd1de374Slin wang - Sun Microsystems - Beijing China 
2716dd1de374Slin wang - Sun Microsystems - Beijing China 	struct modal_eep_header *pModal =
2717dd1de374Slin wang - Sun Microsystems - Beijing China 	    &(eep->modalHeader[ATH9K_BAND_5GHZ == freq_band]);
2718dd1de374Slin wang - Sun Microsystems - Beijing China 	struct base_eep_header *pBase = &eep->baseEepHeader;
2719dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t num_ant_config;
2720dd1de374Slin wang - Sun Microsystems - Beijing China 
2721dd1de374Slin wang - Sun Microsystems - Beijing China 	num_ant_config = 1;
2722dd1de374Slin wang - Sun Microsystems - Beijing China 
2723dd1de374Slin wang - Sun Microsystems - Beijing China 	if (pBase->version >= 0x0E0D)
2724dd1de374Slin wang - Sun Microsystems - Beijing China 		if (pModal->useAnt1)
2725dd1de374Slin wang - Sun Microsystems - Beijing China 			num_ant_config += 1;
2726dd1de374Slin wang - Sun Microsystems - Beijing China 
2727dd1de374Slin wang - Sun Microsystems - Beijing China 	return (num_ant_config);
2728dd1de374Slin wang - Sun Microsystems - Beijing China }
2729dd1de374Slin wang - Sun Microsystems - Beijing China 
2730dd1de374Slin wang - Sun Microsystems - Beijing China uint8_t
2731dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_get_num_ant_config(struct ath_hal *ah,
2732dd1de374Slin wang - Sun Microsystems - Beijing China     enum ath9k_band freq_band)
2733dd1de374Slin wang - Sun Microsystems - Beijing China {
2734dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
2735dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t val;
2736dd1de374Slin wang - Sun Microsystems - Beijing China 
2737dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ahp->ah_eep_map == EEP_MAP_DEFAULT)
2738dd1de374Slin wang - Sun Microsystems - Beijing China 		val = ath9k_hw_get_def_num_ant_config(ah, freq_band);
2739dd1de374Slin wang - Sun Microsystems - Beijing China 	else if (ahp->ah_eep_map == EEP_MAP_4KBITS)
2740dd1de374Slin wang - Sun Microsystems - Beijing China 		val = ath9k_hw_get_4k_num_ant_config(ah, freq_band);
2741dd1de374Slin wang - Sun Microsystems - Beijing China 
2742dd1de374Slin wang - Sun Microsystems - Beijing China 	return (val);
2743dd1de374Slin wang - Sun Microsystems - Beijing China }
2744dd1de374Slin wang - Sun Microsystems - Beijing China 
2745dd1de374Slin wang - Sun Microsystems - Beijing China uint16_t
2746dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_eeprom_get_spur_chan(struct ath_hal *ah, uint16_t i, boolean_t is2GHz)
2747dd1de374Slin wang - Sun Microsystems - Beijing China {
2748dd1de374Slin wang - Sun Microsystems - Beijing China #define	EEP_MAP4K_SPURCHAN \
2749dd1de374Slin wang - Sun Microsystems - Beijing China 	(ahp->ah_eeprom.map4k.modalHeader.spurChans[i].spurChan)
2750dd1de374Slin wang - Sun Microsystems - Beijing China #define	EEP_DEF_SPURCHAN \
2751dd1de374Slin wang - Sun Microsystems - Beijing China 	(ahp->ah_eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan)
2752dd1de374Slin wang - Sun Microsystems - Beijing China 
2753dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
2754dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t spur_val = AR_NO_SPUR;
2755dd1de374Slin wang - Sun Microsystems - Beijing China 
2756dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG((ARN_DBG_ANI, "arn: "
2757dd1de374Slin wang - Sun Microsystems - Beijing China 	    "Getting spur idx %d is2Ghz. %d val %x\n",
2758dd1de374Slin wang - Sun Microsystems - Beijing China 	    i, is2GHz, ah->ah_config.spurchans[i][is2GHz]));
2759dd1de374Slin wang - Sun Microsystems - Beijing China 
2760dd1de374Slin wang - Sun Microsystems - Beijing China 	switch (ah->ah_config.spurmode) {
2761dd1de374Slin wang - Sun Microsystems - Beijing China 	case SPUR_DISABLE:
2762dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
2763dd1de374Slin wang - Sun Microsystems - Beijing China 	case SPUR_ENABLE_IOCTL:
2764dd1de374Slin wang - Sun Microsystems - Beijing China 		spur_val = ah->ah_config.spurchans[i][is2GHz];
2765dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_ANI, "arn: "
2766dd1de374Slin wang - Sun Microsystems - Beijing China 		    "Getting spur val from new loc. %d\n", spur_val));
2767dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
2768dd1de374Slin wang - Sun Microsystems - Beijing China 	case SPUR_ENABLE_EEPROM:
2769dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ahp->ah_eep_map == EEP_MAP_4KBITS)
2770dd1de374Slin wang - Sun Microsystems - Beijing China 			spur_val = EEP_MAP4K_SPURCHAN;
2771dd1de374Slin wang - Sun Microsystems - Beijing China 		else
2772dd1de374Slin wang - Sun Microsystems - Beijing China 			spur_val = EEP_DEF_SPURCHAN;
2773dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
2774dd1de374Slin wang - Sun Microsystems - Beijing China 
2775dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2776dd1de374Slin wang - Sun Microsystems - Beijing China 
2777dd1de374Slin wang - Sun Microsystems - Beijing China 	return (spur_val);
2778dd1de374Slin wang - Sun Microsystems - Beijing China #undef EEP_DEF_SPURCHAN
2779dd1de374Slin wang - Sun Microsystems - Beijing China #undef EEP_MAP4K_SPURCHAN
2780dd1de374Slin wang - Sun Microsystems - Beijing China }
2781dd1de374Slin wang - Sun Microsystems - Beijing China 
2782dd1de374Slin wang - Sun Microsystems - Beijing China static uint32_t
2783dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_get_eeprom_4k(struct ath_hal *ah,
2784dd1de374Slin wang - Sun Microsystems - Beijing China     enum eeprom_param param)
2785dd1de374Slin wang - Sun Microsystems - Beijing China {
2786dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
2787dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ar5416_eeprom_4k *eep = &ahp->ah_eeprom.map4k;
2788dd1de374Slin wang - Sun Microsystems - Beijing China 	struct modal_eep_4k_header *pModal = &eep->modalHeader;
2789dd1de374Slin wang - Sun Microsystems - Beijing China 	struct base_eep_header_4k *pBase = &eep->baseEepHeader;
2790dd1de374Slin wang - Sun Microsystems - Beijing China 
2791dd1de374Slin wang - Sun Microsystems - Beijing China 	switch (param) {
2792dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_NFTHRESH_2:
2793dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pModal[1].noiseFloorThreshCh[0]);
2794dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR_EEPROM_MAC(0):
2795dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->macAddr[0] << 8 | pBase->macAddr[1]);
2796dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR_EEPROM_MAC(1):
2797dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->macAddr[2] << 8 | pBase->macAddr[3]);
2798dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR_EEPROM_MAC(2):
2799dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->macAddr[4] << 8 | pBase->macAddr[5]);
2800dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_REG_0:
2801dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->regDmn[0]);
2802dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_REG_1:
2803dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->regDmn[1]);
2804dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_OP_CAP:
2805dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->deviceCap);
2806dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_OP_MODE:
2807dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->opCapFlags);
2808dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_RF_SILENT:
2809dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->rfSilent);
2810dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_OB_2:
2811dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pModal->ob_01);
2812dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_DB_2:
2813dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pModal->db1_01);
2814dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_MINOR_REV:
2815dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->version & AR5416_EEP_VER_MINOR_MASK);
2816dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_TX_MASK:
2817dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->txMask);
2818dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_RX_MASK:
2819dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->rxMask);
2820*c0c93480Slin wang - Sun Microsystems - Beijing China 	/* 2.6.30 */
2821*c0c93480Slin wang - Sun Microsystems - Beijing China 	case EEP_FRAC_N_5G:
2822*c0c93480Slin wang - Sun Microsystems - Beijing China 		return (0);
2823dd1de374Slin wang - Sun Microsystems - Beijing China 	default:
2824dd1de374Slin wang - Sun Microsystems - Beijing China 		return (0);
2825dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2826dd1de374Slin wang - Sun Microsystems - Beijing China }
2827dd1de374Slin wang - Sun Microsystems - Beijing China 
2828dd1de374Slin wang - Sun Microsystems - Beijing China uint32_t
2829dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_get_eeprom_def(struct ath_hal *ah, enum eeprom_param param)
2830dd1de374Slin wang - Sun Microsystems - Beijing China {
2831dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 	*ahp = AH5416(ah);
2832dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ar5416_eeprom_def *eep = &ahp->ah_eeprom.def;
2833dd1de374Slin wang - Sun Microsystems - Beijing China 	struct modal_eep_header *pModal = eep->modalHeader;
2834dd1de374Slin wang - Sun Microsystems - Beijing China 	struct base_eep_header 	*pBase = &eep->baseEepHeader;
2835dd1de374Slin wang - Sun Microsystems - Beijing China 
2836dd1de374Slin wang - Sun Microsystems - Beijing China 	switch (param) {
2837dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_NFTHRESH_5:
2838dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pModal[0].noiseFloorThreshCh[0]);
2839dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_NFTHRESH_2:
2840dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pModal[1].noiseFloorThreshCh[0]);
2841dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR_EEPROM_MAC(0):
2842dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->macAddr[0] << 8 | pBase->macAddr[1]);
2843dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR_EEPROM_MAC(1):
2844dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->macAddr[2] << 8 | pBase->macAddr[3]);
2845dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR_EEPROM_MAC(2):
2846dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->macAddr[4] << 8 | pBase->macAddr[5]);
2847dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_REG_0:
2848dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->regDmn[0]);
2849dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_REG_1:
2850dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->regDmn[1]);
2851dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_OP_CAP:
2852dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->deviceCap);
2853dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_OP_MODE:
2854dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->opCapFlags);
2855dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_RF_SILENT:
2856dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->rfSilent);
2857dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_OB_5:
2858dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pModal[0].ob);
2859dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_DB_5:
2860dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pModal[0].db);
2861dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_OB_2:
2862dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pModal[1].ob);
2863dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_DB_2:
2864dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pModal[1].db);
2865dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_MINOR_REV:
2866dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->version & AR5416_EEP_VER_MINOR_MASK);
2867dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_TX_MASK:
2868dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->txMask);
2869dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_RX_MASK:
2870dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->rxMask);
2871dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_RXGAIN_TYPE:
2872dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->rxGainType);
2873dd1de374Slin wang - Sun Microsystems - Beijing China 	case EEP_TXGAIN_TYPE:
2874dd1de374Slin wang - Sun Microsystems - Beijing China 		return (pBase->txGainType);
2875*c0c93480Slin wang - Sun Microsystems - Beijing China 	/* 2.6.30 */
2876*c0c93480Slin wang - Sun Microsystems - Beijing China 	case EEP_OL_PWRCTRL:
2877*c0c93480Slin wang - Sun Microsystems - Beijing China 		if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
2878*c0c93480Slin wang - Sun Microsystems - Beijing China 			return (pBase->openLoopPwrCntl ? B_TRUE: B_FALSE);
2879*c0c93480Slin wang - Sun Microsystems - Beijing China 		else
2880*c0c93480Slin wang - Sun Microsystems - Beijing China 			return (B_FALSE);
2881*c0c93480Slin wang - Sun Microsystems - Beijing China 	case EEP_RC_CHAIN_MASK:
2882*c0c93480Slin wang - Sun Microsystems - Beijing China 		if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
2883*c0c93480Slin wang - Sun Microsystems - Beijing China 			return (pBase->rcChainMask);
2884*c0c93480Slin wang - Sun Microsystems - Beijing China 		else
2885*c0c93480Slin wang - Sun Microsystems - Beijing China 			return (0);
2886*c0c93480Slin wang - Sun Microsystems - Beijing China 	case EEP_DAC_HPWR_5G:
2887*c0c93480Slin wang - Sun Microsystems - Beijing China 		if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20)
2888*c0c93480Slin wang - Sun Microsystems - Beijing China 			return (pBase->dacHiPwrMode_5G);
2889*c0c93480Slin wang - Sun Microsystems - Beijing China 		else
2890*c0c93480Slin wang - Sun Microsystems - Beijing China 			return (0);
2891*c0c93480Slin wang - Sun Microsystems - Beijing China 	case EEP_FRAC_N_5G:
2892*c0c93480Slin wang - Sun Microsystems - Beijing China 		if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_22)
2893*c0c93480Slin wang - Sun Microsystems - Beijing China 			return (pBase->frac_n_5g);
2894*c0c93480Slin wang - Sun Microsystems - Beijing China 		else
2895*c0c93480Slin wang - Sun Microsystems - Beijing China 			return (0);
2896dd1de374Slin wang - Sun Microsystems - Beijing China 
2897dd1de374Slin wang - Sun Microsystems - Beijing China 	default:
2898dd1de374Slin wang - Sun Microsystems - Beijing China 		return (0);
2899dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2900dd1de374Slin wang - Sun Microsystems - Beijing China }
2901dd1de374Slin wang - Sun Microsystems - Beijing China 
2902dd1de374Slin wang - Sun Microsystems - Beijing China uint32_t
2903dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_get_eeprom(struct ath_hal *ah, enum eeprom_param param)
2904dd1de374Slin wang - Sun Microsystems - Beijing China {
2905dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
2906dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t val;
2907dd1de374Slin wang - Sun Microsystems - Beijing China 
2908dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ahp->ah_eep_map == EEP_MAP_DEFAULT)
2909dd1de374Slin wang - Sun Microsystems - Beijing China 		val = ath9k_hw_get_eeprom_def(ah, param);
2910dd1de374Slin wang - Sun Microsystems - Beijing China 	else if (ahp->ah_eep_map == EEP_MAP_4KBITS)
2911dd1de374Slin wang - Sun Microsystems - Beijing China 		val = ath9k_hw_get_eeprom_4k(ah, param);
2912dd1de374Slin wang - Sun Microsystems - Beijing China 
2913dd1de374Slin wang - Sun Microsystems - Beijing China 	return (val);
2914dd1de374Slin wang - Sun Microsystems - Beijing China }
2915dd1de374Slin wang - Sun Microsystems - Beijing China 
2916dd1de374Slin wang - Sun Microsystems - Beijing China int
2917dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_eeprom_attach(struct ath_hal *ah)
2918dd1de374Slin wang - Sun Microsystems - Beijing China {
2919dd1de374Slin wang - Sun Microsystems - Beijing China 	int status;
2920dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
2921dd1de374Slin wang - Sun Microsystems - Beijing China 
2922dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ath9k_hw_use_flash(ah))
2923dd1de374Slin wang - Sun Microsystems - Beijing China 		(void) ath9k_hw_flash_map(ah);
2924dd1de374Slin wang - Sun Microsystems - Beijing China 
2925dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9285(ah))
2926dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_eep_map = EEP_MAP_4KBITS;
2927dd1de374Slin wang - Sun Microsystems - Beijing China 	else
2928dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_eep_map = EEP_MAP_DEFAULT;
2929dd1de374Slin wang - Sun Microsystems - Beijing China 
2930dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_fill_eeprom(ah))
2931dd1de374Slin wang - Sun Microsystems - Beijing China 		return (EIO);
2932dd1de374Slin wang - Sun Microsystems - Beijing China 
2933dd1de374Slin wang - Sun Microsystems - Beijing China 	status = ath9k_hw_check_eeprom(ah);
2934dd1de374Slin wang - Sun Microsystems - Beijing China 
2935dd1de374Slin wang - Sun Microsystems - Beijing China 	return (status);
2936dd1de374Slin wang - Sun Microsystems - Beijing China }
2937