1718cf2ccSPedro F. Giffuni /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni *
41c554472SAdrian Chadd * Copyright (c) 2008-2010 Atheros Communications Inc.
51c554472SAdrian Chadd * Copyright (c) 2010-2011 Adrian Chadd, Xenion Pty Ltd.
61c554472SAdrian Chadd *
71c554472SAdrian Chadd * Redistribution and use in source and binary forms, with or without
81c554472SAdrian Chadd * modification, are permitted provided that the following conditions
91c554472SAdrian Chadd * are met:
101c554472SAdrian Chadd * 1. Redistributions of source code must retain the above copyright
111c554472SAdrian Chadd * notice, this list of conditions and the following disclaimer.
121c554472SAdrian Chadd * 2. Redistributions in binary form must reproduce the above copyright
131c554472SAdrian Chadd * notice, this list of conditions and the following disclaimer in the
141c554472SAdrian Chadd * documentation and/or other materials provided with the distribution.
151c554472SAdrian Chadd *
161c554472SAdrian Chadd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
171c554472SAdrian Chadd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
181c554472SAdrian Chadd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
191c554472SAdrian Chadd * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
201c554472SAdrian Chadd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
211c554472SAdrian Chadd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
221c554472SAdrian Chadd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
231c554472SAdrian Chadd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
241c554472SAdrian Chadd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
251c554472SAdrian Chadd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
261c554472SAdrian Chadd * SUCH DAMAGE.
271c554472SAdrian Chadd */
281c554472SAdrian Chadd #include "opt_ah.h"
291c554472SAdrian Chadd
301c554472SAdrian Chadd #include "ah.h"
311c554472SAdrian Chadd #include "ah_internal.h"
321c554472SAdrian Chadd #include "ah_devid.h"
331c554472SAdrian Chadd #include "ah_eeprom_v4k.h"
341c554472SAdrian Chadd
351c554472SAdrian Chadd #include "ar9002/ar9280.h"
361c554472SAdrian Chadd #include "ar9002/ar9285.h"
371c554472SAdrian Chadd #include "ar5416/ar5416reg.h"
381c554472SAdrian Chadd #include "ar5416/ar5416phy.h"
391c554472SAdrian Chadd #include "ar9002/ar9285phy.h"
401c554472SAdrian Chadd #include "ar9002/ar9285_phy.h"
411c554472SAdrian Chadd
421c554472SAdrian Chadd void
ar9285_antdiv_comb_conf_get(struct ath_hal * ah,HAL_ANT_COMB_CONFIG * antconf)439ae49f26SAdrian Chadd ar9285_antdiv_comb_conf_get(struct ath_hal *ah, HAL_ANT_COMB_CONFIG *antconf)
441c554472SAdrian Chadd {
451c554472SAdrian Chadd uint32_t regval;
461c554472SAdrian Chadd
471c554472SAdrian Chadd regval = OS_REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);
481c554472SAdrian Chadd antconf->main_lna_conf = (regval & AR_PHY_9285_ANT_DIV_MAIN_LNACONF) >>
491c554472SAdrian Chadd AR_PHY_9285_ANT_DIV_MAIN_LNACONF_S;
501c554472SAdrian Chadd antconf->alt_lna_conf = (regval & AR_PHY_9285_ANT_DIV_ALT_LNACONF) >>
511c554472SAdrian Chadd AR_PHY_9285_ANT_DIV_ALT_LNACONF_S;
521c554472SAdrian Chadd antconf->fast_div_bias = (regval & AR_PHY_9285_FAST_DIV_BIAS) >>
531c554472SAdrian Chadd AR_PHY_9285_FAST_DIV_BIAS_S;
54de98311fSAdrian Chadd antconf->antdiv_configgroup = DEFAULT_ANTDIV_CONFIG_GROUP;
551c554472SAdrian Chadd }
561c554472SAdrian Chadd
571c554472SAdrian Chadd void
ar9285_antdiv_comb_conf_set(struct ath_hal * ah,HAL_ANT_COMB_CONFIG * antconf)589ae49f26SAdrian Chadd ar9285_antdiv_comb_conf_set(struct ath_hal *ah, HAL_ANT_COMB_CONFIG *antconf)
591c554472SAdrian Chadd {
601c554472SAdrian Chadd uint32_t regval;
611c554472SAdrian Chadd
621c554472SAdrian Chadd regval = OS_REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);
631c554472SAdrian Chadd regval &= ~(AR_PHY_9285_ANT_DIV_MAIN_LNACONF |
641c554472SAdrian Chadd AR_PHY_9285_ANT_DIV_ALT_LNACONF |
651c554472SAdrian Chadd AR_PHY_9285_FAST_DIV_BIAS);
661c554472SAdrian Chadd regval |= ((antconf->main_lna_conf << AR_PHY_9285_ANT_DIV_MAIN_LNACONF_S)
671c554472SAdrian Chadd & AR_PHY_9285_ANT_DIV_MAIN_LNACONF);
681c554472SAdrian Chadd regval |= ((antconf->alt_lna_conf << AR_PHY_9285_ANT_DIV_ALT_LNACONF_S)
691c554472SAdrian Chadd & AR_PHY_9285_ANT_DIV_ALT_LNACONF);
701c554472SAdrian Chadd regval |= ((antconf->fast_div_bias << AR_PHY_9285_FAST_DIV_BIAS_S)
711c554472SAdrian Chadd & AR_PHY_9285_FAST_DIV_BIAS);
721c554472SAdrian Chadd
731c554472SAdrian Chadd OS_REG_WRITE(ah, AR_PHY_MULTICHAIN_GAIN_CTL, regval);
741c554472SAdrian Chadd }
751c554472SAdrian Chadd
761c554472SAdrian Chadd /*
77352dbd82SAdrian Chadd * Check whether combined + fast antenna diversity should be enabled.
78352dbd82SAdrian Chadd *
79352dbd82SAdrian Chadd * This enables software-driven RX antenna diversity based on RX
80352dbd82SAdrian Chadd * RSSI + antenna config packet sampling.
811c554472SAdrian Chadd */
82352dbd82SAdrian Chadd HAL_BOOL
ar9285_check_div_comb(struct ath_hal * ah)831c554472SAdrian Chadd ar9285_check_div_comb(struct ath_hal *ah)
841c554472SAdrian Chadd {
851c554472SAdrian Chadd uint8_t ant_div_ctl1;
861c554472SAdrian Chadd HAL_EEPROM_v4k *ee = AH_PRIVATE(ah)->ah_eeprom;
871c554472SAdrian Chadd const MODAL_EEP4K_HEADER *pModal = &ee->ee_base.modalHeader;
881c554472SAdrian Chadd
895eb07ec7SAdrian Chadd #if 0
90352dbd82SAdrian Chadd /* For now, simply disable this until it's better debugged. -adrian */
91352dbd82SAdrian Chadd return AH_FALSE;
925eb07ec7SAdrian Chadd #endif
93352dbd82SAdrian Chadd
941c554472SAdrian Chadd if (! AR_SREV_KITE(ah))
95352dbd82SAdrian Chadd return AH_FALSE;
961c554472SAdrian Chadd
971c554472SAdrian Chadd if (pModal->version < 3)
98352dbd82SAdrian Chadd return AH_FALSE;
991c554472SAdrian Chadd
1001c554472SAdrian Chadd ant_div_ctl1 = pModal->antdiv_ctl1;
1011c554472SAdrian Chadd if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1))
102352dbd82SAdrian Chadd return AH_TRUE;
1031c554472SAdrian Chadd
104352dbd82SAdrian Chadd return AH_FALSE;
1051c554472SAdrian Chadd }
106