FreeBSD kernel ATH device code
ar9285_diversity.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2008-2010 Atheros Communications Inc.
5 * Copyright (c) 2011 Adrian Chadd, Xenion Pty Ltd.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 * $FreeBSD$
29 */
30#include "opt_ah.h"
31
32#include "ah.h"
33#include "ah_desc.h"
34#include "ah_internal.h"
35#include "ah_eeprom_v4k.h"
36
37#include "ar9002/ar9280.h"
38#include "ar9002/ar9285.h"
39#include "ar5416/ar5416reg.h"
40#include "ar5416/ar5416phy.h"
41#include "ar9002/ar9285phy.h"
42#include "ar9002/ar9285_phy.h"
43
45
46/*
47 * Set the antenna switch to control RX antenna diversity.
48 *
49 * If a fixed configuration is used, the LNA and div bias
50 * settings are fixed and the antenna diversity scanning routine
51 * is disabled.
52 *
53 * If a variable configuration is used, a default is programmed
54 * in and sampling commences per RXed packet.
55 *
56 * Since this is called from ar9285SetBoardValues() to setup
57 * diversity, it means that after a reset or scan, any current
58 * software diversity combining settings will be lost and won't
59 * re-appear until after the first successful sample run.
60 * Please keep this in mind if you're seeing weird performance
61 * that happens to relate to scan/diversity timing.
62 */
65{
66 int regVal;
67 const HAL_EEPROM_v4k *ee = AH_PRIVATE(ah)->ah_eeprom;
68 const MODAL_EEP4K_HEADER *pModal = &ee->ee_base.modalHeader;
69 uint8_t ant_div_control1, ant_div_control2;
70
71 if (pModal->version < 3) {
72 HALDEBUG(ah, HAL_DEBUG_DIVERSITY, "%s: not supported\n",
73 __func__);
74 return AH_FALSE; /* Can't do diversity */
75 }
76
77 /* Store settings */
78 AH5212(ah)->ah_antControl = settings;
79 AH5212(ah)->ah_diversity = (settings == HAL_ANT_VARIABLE);
80
81 /* XXX don't fiddle if the PHY is in sleep mode or ! chan */
82
83 /* Begin setting the relevant registers */
84
85 ant_div_control1 = pModal->antdiv_ctl1;
86 ant_div_control2 = pModal->antdiv_ctl2;
87
89 regVal &= (~(AR_PHY_9285_ANT_DIV_CTL_ALL));
90
91 /* enable antenna diversity only if diversityControl == HAL_ANT_VARIABLE */
92 if (settings == HAL_ANT_VARIABLE)
93 regVal |= SM(ant_div_control1, AR_PHY_9285_ANT_DIV_CTL);
94
95 if (settings == HAL_ANT_VARIABLE) {
96 HALDEBUG(ah, HAL_DEBUG_DIVERSITY, "%s: HAL_ANT_VARIABLE\n",
97 __func__);
98 regVal |= SM(ant_div_control2, AR_PHY_9285_ANT_DIV_ALT_LNACONF);
99 regVal |= SM((ant_div_control2 >> 2), AR_PHY_9285_ANT_DIV_MAIN_LNACONF);
100 regVal |= SM((ant_div_control1 >> 1), AR_PHY_9285_ANT_DIV_ALT_GAINTB);
101 regVal |= SM((ant_div_control1 >> 2), AR_PHY_9285_ANT_DIV_MAIN_GAINTB);
102 } else {
103 if (settings == HAL_ANT_FIXED_A) {
104 /* Diversity disabled, RX = LNA1 */
105 HALDEBUG(ah, HAL_DEBUG_DIVERSITY, "%s: HAL_ANT_FIXED_A\n",
106 __func__);
111 }
112 else if (settings == HAL_ANT_FIXED_B) {
113 /* Diversity disabled, RX = LNA2 */
114 HALDEBUG(ah, HAL_DEBUG_DIVERSITY, "%s: HAL_ANT_FIXED_B\n",
115 __func__);
120 }
121 }
122
125 regVal = OS_REG_READ(ah, AR_PHY_CCK_DETECT);
126 regVal &= (~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
127 if (settings == HAL_ANT_VARIABLE)
128 regVal |= SM((ant_div_control1 >> 3), AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
129
130 OS_REG_WRITE(ah, AR_PHY_CCK_DETECT, regVal);
131 regVal = OS_REG_READ(ah, AR_PHY_CCK_DETECT);
132
133 /*
134 * If Diversity combining is available and the diversity setting
135 * is to allow variable diversity, enable it by default.
136 *
137 * This will be eventually overridden by the software antenna
138 * diversity logic.
139 *
140 * Note that yes, this following section overrides the above
141 * settings for the LNA configuration and fast-bias.
142 */
143 if (ar9285_check_div_comb(ah) && AH5212(ah)->ah_diversity == AH_TRUE) {
144 // If support DivComb, set MAIN to LNA1 and ALT to LNA2 at the first beginning
146 "%s: Enable initial settings for combined diversity\n",
147 __func__);
152 regVal &= (~(AR_PHY_9285_FAST_DIV_BIAS));
153 regVal |= (0 << AR_PHY_9285_FAST_DIV_BIAS_S);
155 }
156
157 return AH_TRUE;
158}
HAL_ANT_SETTING
Definition: ah.h:758
@ HAL_ANT_FIXED_B
Definition: ah.h:761
@ HAL_ANT_VARIABLE
Definition: ah.h:759
@ HAL_ANT_FIXED_A
Definition: ah.h:760
HAL_BOOL
Definition: ah.h:93
@ AH_FALSE
Definition: ah.h:94
@ AH_TRUE
Definition: ah.h:95
@ HAL_ANT_DIV_COMB_LNA2
Definition: ah.h:1067
@ HAL_ANT_DIV_COMB_LNA1
Definition: ah.h:1068
@ HAL_DEBUG_DIVERSITY
Definition: ah_debug.h:49
#define SM(_v, _f)
Definition: ah_internal.h:587
#define AH_PRIVATE(_ah)
Definition: ah_internal.h:442
#define HALDEBUG(_ah, __m,...)
Definition: ah_internal.h:658
#define OS_REG_WRITE(_ah, _reg, _val)
Definition: ah_osdep.h:139
#define OS_REG_READ(_ah, _reg)
Definition: ah_osdep.h:140
#define AH5212(_ah)
Definition: ar5212.h:354
#define AR_PHY_CCK_DETECT
Definition: ar5212phy.h:315
#define AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV
Definition: ar5212phy.h:318
#define AR_PHY_MULTICHAIN_GAIN_CTL
Definition: ar5416phy.h:268
HAL_BOOL ar9285SetAntennaSwitch(struct ath_hal *ah, HAL_ANT_SETTING settings)
HAL_BOOL ar9285_check_div_comb(struct ath_hal *ah)
Definition: ar9285_phy.c:85
#define AR_PHY_9285_ANT_DIV_ALT_GAINTB
Definition: ar9285phy.h:115
#define AR_PHY_9285_ANT_DIV_MAIN_LNACONF_S
Definition: ar9285phy.h:114
#define AR_PHY_9285_ANT_DIV_ALT_LNACONF_S
Definition: ar9285phy.h:112
#define AR_PHY_9285_ANT_DIV_GAINTB_1
Definition: ar9285phy.h:124
#define AR_PHY_9285_ANT_DIV_CTL_ALL
Definition: ar9285phy.h:108
#define AR_PHY_9285_FAST_DIV_BIAS_S
Definition: ar9285phy.h:107
#define AR_PHY_9285_ANT_DIV_GAINTB_0
Definition: ar9285phy.h:123
#define AR_PHY_9285_ANT_DIV_MAIN_GAINTB
Definition: ar9285phy.h:117
#define AR_PHY_9285_ANT_DIV_MAIN_LNACONF
Definition: ar9285phy.h:113
#define AR_PHY_9285_FAST_DIV_BIAS
Definition: ar9285phy.h:106
#define AR_PHY_9285_ANT_DIV_CTL
Definition: ar9285phy.h:109
#define AR_PHY_9285_ANT_DIV_ALT_LNACONF
Definition: ar9285phy.h:111
struct ar5416eeprom_4k ee_base
MODAL_EEP4K_HEADER modalHeader
Definition: ah.h:1219