xref: /freebsd/sys/dev/ath/ath_hal/ar9002/ar9285.c (revision c697fb7f)
1 /*-
2  * SPDX-License-Identifier: ISC
3  *
4  * Copyright (c) 2008-2009 Sam Leffler, Errno Consulting
5  * Copyright (c) 2008 Atheros Communications, Inc.
6  *
7  * Permission to use, copy, modify, and/or distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  *
19  * $FreeBSD$
20  */
21 #include "opt_ah.h"
22 
23 #include "ah.h"
24 #include "ah_internal.h"
25 
26 #include "ah_eeprom_v14.h"
27 
28 #include "ar9002/ar9280.h"
29 #include "ar9002/ar9285.h"
30 #include "ar5416/ar5416reg.h"
31 #include "ar5416/ar5416phy.h"
32 
33 /*
34  * The ordering of nfarray is thus:
35  *
36  * nfarray[0]: Chain 0 ctl
37  * nfarray[1]: Chain 1 ctl
38  * nfarray[2]: Chain 2 ctl
39  * nfarray[3]: Chain 0 ext
40  * nfarray[4]: Chain 1 ext
41  * nfarray[5]: Chain 2 ext
42  */
43 static void
44 ar9285GetNoiseFloor(struct ath_hal *ah, int16_t nfarray[])
45 {
46 	int16_t nf;
47 
48 	nf = MS(OS_REG_READ(ah, AR_PHY_CCA), AR9280_PHY_MINCCA_PWR);
49 	if (nf & 0x100)
50 		nf = 0 - ((nf ^ 0x1ff) + 1);
51 	HALDEBUG(ah, HAL_DEBUG_NFCAL,
52 	    "NF calibrated [ctl] [chain 0] is %d\n", nf);
53 	nfarray[0] = nf;
54 
55 
56 	nf = MS(OS_REG_READ(ah, AR_PHY_EXT_CCA), AR9280_PHY_EXT_MINCCA_PWR);
57 	if (nf & 0x100)
58 		nf = 0 - ((nf ^ 0x1ff) + 1);
59 	HALDEBUG(ah, HAL_DEBUG_NFCAL,
60 	    "NF calibrated [ext] [chain 0] is %d\n", nf);
61 	nfarray[3] = nf;
62 
63 	/* Chain 1 - invalid */
64 	nfarray[1] = 0;
65 	nfarray[4] = 0;
66 
67 	/* Chain 2 - invalid */
68 	nfarray[2] = 0;
69 	nfarray[5] = 0;
70 }
71 
72 HAL_BOOL
73 ar9285RfAttach(struct ath_hal *ah, HAL_STATUS *status)
74 {
75 	if (ar9280RfAttach(ah, status) == AH_FALSE)
76 		return AH_FALSE;
77 
78 	AH_PRIVATE(ah)->ah_getNoiseFloor = ar9285GetNoiseFloor;
79 
80 	return AH_TRUE;
81 }
82 
83 static HAL_BOOL
84 ar9285RfProbe(struct ath_hal *ah)
85 {
86 	return (AR_SREV_KITE(ah));
87 }
88 
89 AH_RF(RF9285, ar9285RfProbe, ar9285RfAttach);
90