1*572ff6f6SMatthew Dillon /*
2*572ff6f6SMatthew Dillon * Copyright (c) 2008-2010 Atheros Communications Inc.
3*572ff6f6SMatthew Dillon * Copyright (c) 2010-2011 Adrian Chadd, Xenion Pty Ltd.
4*572ff6f6SMatthew Dillon *
5*572ff6f6SMatthew Dillon * Redistribution and use in source and binary forms, with or without
6*572ff6f6SMatthew Dillon * modification, are permitted provided that the following conditions
7*572ff6f6SMatthew Dillon * are met:
8*572ff6f6SMatthew Dillon * 1. Redistributions of source code must retain the above copyright
9*572ff6f6SMatthew Dillon * notice, this list of conditions and the following disclaimer.
10*572ff6f6SMatthew Dillon * 2. Redistributions in binary form must reproduce the above copyright
11*572ff6f6SMatthew Dillon * notice, this list of conditions and the following disclaimer in the
12*572ff6f6SMatthew Dillon * documentation and/or other materials provided with the distribution.
13*572ff6f6SMatthew Dillon *
14*572ff6f6SMatthew Dillon * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*572ff6f6SMatthew Dillon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*572ff6f6SMatthew Dillon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*572ff6f6SMatthew Dillon * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*572ff6f6SMatthew Dillon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*572ff6f6SMatthew Dillon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*572ff6f6SMatthew Dillon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*572ff6f6SMatthew Dillon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*572ff6f6SMatthew Dillon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*572ff6f6SMatthew Dillon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*572ff6f6SMatthew Dillon * SUCH DAMAGE.
25*572ff6f6SMatthew Dillon *
26*572ff6f6SMatthew Dillon * $FreeBSD$
27*572ff6f6SMatthew Dillon */
28*572ff6f6SMatthew Dillon #include "opt_ah.h"
29*572ff6f6SMatthew Dillon
30*572ff6f6SMatthew Dillon #include "ah.h"
31*572ff6f6SMatthew Dillon #include "ah_internal.h"
32*572ff6f6SMatthew Dillon #include "ah_devid.h"
33*572ff6f6SMatthew Dillon #include "ah_eeprom_v4k.h"
34*572ff6f6SMatthew Dillon
35*572ff6f6SMatthew Dillon #include "ar9002/ar9280.h"
36*572ff6f6SMatthew Dillon #include "ar9002/ar9285.h"
37*572ff6f6SMatthew Dillon #include "ar5416/ar5416reg.h"
38*572ff6f6SMatthew Dillon #include "ar5416/ar5416phy.h"
39*572ff6f6SMatthew Dillon #include "ar9002/ar9285phy.h"
40*572ff6f6SMatthew Dillon #include "ar9002/ar9285_phy.h"
41*572ff6f6SMatthew Dillon
42*572ff6f6SMatthew Dillon void
ar9285_antdiv_comb_conf_get(struct ath_hal * ah,HAL_ANT_COMB_CONFIG * antconf)43*572ff6f6SMatthew Dillon ar9285_antdiv_comb_conf_get(struct ath_hal *ah, HAL_ANT_COMB_CONFIG *antconf)
44*572ff6f6SMatthew Dillon {
45*572ff6f6SMatthew Dillon uint32_t regval;
46*572ff6f6SMatthew Dillon
47*572ff6f6SMatthew Dillon regval = OS_REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);
48*572ff6f6SMatthew Dillon antconf->main_lna_conf = (regval & AR_PHY_9285_ANT_DIV_MAIN_LNACONF) >>
49*572ff6f6SMatthew Dillon AR_PHY_9285_ANT_DIV_MAIN_LNACONF_S;
50*572ff6f6SMatthew Dillon antconf->alt_lna_conf = (regval & AR_PHY_9285_ANT_DIV_ALT_LNACONF) >>
51*572ff6f6SMatthew Dillon AR_PHY_9285_ANT_DIV_ALT_LNACONF_S;
52*572ff6f6SMatthew Dillon antconf->fast_div_bias = (regval & AR_PHY_9285_FAST_DIV_BIAS) >>
53*572ff6f6SMatthew Dillon AR_PHY_9285_FAST_DIV_BIAS_S;
54*572ff6f6SMatthew Dillon antconf->antdiv_configgroup = DEFAULT_ANTDIV_CONFIG_GROUP;
55*572ff6f6SMatthew Dillon }
56*572ff6f6SMatthew Dillon
57*572ff6f6SMatthew Dillon void
ar9285_antdiv_comb_conf_set(struct ath_hal * ah,HAL_ANT_COMB_CONFIG * antconf)58*572ff6f6SMatthew Dillon ar9285_antdiv_comb_conf_set(struct ath_hal *ah, HAL_ANT_COMB_CONFIG *antconf)
59*572ff6f6SMatthew Dillon {
60*572ff6f6SMatthew Dillon uint32_t regval;
61*572ff6f6SMatthew Dillon
62*572ff6f6SMatthew Dillon regval = OS_REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);
63*572ff6f6SMatthew Dillon regval &= ~(AR_PHY_9285_ANT_DIV_MAIN_LNACONF |
64*572ff6f6SMatthew Dillon AR_PHY_9285_ANT_DIV_ALT_LNACONF |
65*572ff6f6SMatthew Dillon AR_PHY_9285_FAST_DIV_BIAS);
66*572ff6f6SMatthew Dillon regval |= ((antconf->main_lna_conf << AR_PHY_9285_ANT_DIV_MAIN_LNACONF_S)
67*572ff6f6SMatthew Dillon & AR_PHY_9285_ANT_DIV_MAIN_LNACONF);
68*572ff6f6SMatthew Dillon regval |= ((antconf->alt_lna_conf << AR_PHY_9285_ANT_DIV_ALT_LNACONF_S)
69*572ff6f6SMatthew Dillon & AR_PHY_9285_ANT_DIV_ALT_LNACONF);
70*572ff6f6SMatthew Dillon regval |= ((antconf->fast_div_bias << AR_PHY_9285_FAST_DIV_BIAS_S)
71*572ff6f6SMatthew Dillon & AR_PHY_9285_FAST_DIV_BIAS);
72*572ff6f6SMatthew Dillon
73*572ff6f6SMatthew Dillon OS_REG_WRITE(ah, AR_PHY_MULTICHAIN_GAIN_CTL, regval);
74*572ff6f6SMatthew Dillon }
75*572ff6f6SMatthew Dillon
76*572ff6f6SMatthew Dillon /*
77*572ff6f6SMatthew Dillon * Check whether combined + fast antenna diversity should be enabled.
78*572ff6f6SMatthew Dillon *
79*572ff6f6SMatthew Dillon * This enables software-driven RX antenna diversity based on RX
80*572ff6f6SMatthew Dillon * RSSI + antenna config packet sampling.
81*572ff6f6SMatthew Dillon */
82*572ff6f6SMatthew Dillon HAL_BOOL
ar9285_check_div_comb(struct ath_hal * ah)83*572ff6f6SMatthew Dillon ar9285_check_div_comb(struct ath_hal *ah)
84*572ff6f6SMatthew Dillon {
85*572ff6f6SMatthew Dillon uint8_t ant_div_ctl1;
86*572ff6f6SMatthew Dillon HAL_EEPROM_v4k *ee = AH_PRIVATE(ah)->ah_eeprom;
87*572ff6f6SMatthew Dillon const MODAL_EEP4K_HEADER *pModal = &ee->ee_base.modalHeader;
88*572ff6f6SMatthew Dillon
89*572ff6f6SMatthew Dillon #if 0
90*572ff6f6SMatthew Dillon /* For now, simply disable this until it's better debugged. -adrian */
91*572ff6f6SMatthew Dillon return AH_FALSE;
92*572ff6f6SMatthew Dillon #endif
93*572ff6f6SMatthew Dillon
94*572ff6f6SMatthew Dillon if (! AR_SREV_KITE(ah))
95*572ff6f6SMatthew Dillon return AH_FALSE;
96*572ff6f6SMatthew Dillon
97*572ff6f6SMatthew Dillon if (pModal->version < 3)
98*572ff6f6SMatthew Dillon return AH_FALSE;
99*572ff6f6SMatthew Dillon
100*572ff6f6SMatthew Dillon ant_div_ctl1 = pModal->antdiv_ctl1;
101*572ff6f6SMatthew Dillon if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1))
102*572ff6f6SMatthew Dillon return AH_TRUE;
103*572ff6f6SMatthew Dillon
104*572ff6f6SMatthew Dillon return AH_FALSE;
105*572ff6f6SMatthew Dillon }
106