Path: blob/main/sys/dev/ath/ath_hal/ar9002/ar9285_phy.c
39566 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2008-2010 Atheros Communications Inc.4* Copyright (c) 2010-2011 Adrian Chadd, Xenion Pty Ltd.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/27#include "opt_ah.h"2829#include "ah.h"30#include "ah_internal.h"31#include "ah_devid.h"32#include "ah_eeprom_v4k.h"3334#include "ar9002/ar9280.h"35#include "ar9002/ar9285.h"36#include "ar5416/ar5416reg.h"37#include "ar5416/ar5416phy.h"38#include "ar9002/ar9285phy.h"39#include "ar9002/ar9285_phy.h"4041void42ar9285_antdiv_comb_conf_get(struct ath_hal *ah, HAL_ANT_COMB_CONFIG *antconf)43{44uint32_t regval;4546regval = OS_REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);47antconf->main_lna_conf = (regval & AR_PHY_9285_ANT_DIV_MAIN_LNACONF) >>48AR_PHY_9285_ANT_DIV_MAIN_LNACONF_S;49antconf->alt_lna_conf = (regval & AR_PHY_9285_ANT_DIV_ALT_LNACONF) >>50AR_PHY_9285_ANT_DIV_ALT_LNACONF_S;51antconf->fast_div_bias = (regval & AR_PHY_9285_FAST_DIV_BIAS) >>52AR_PHY_9285_FAST_DIV_BIAS_S;53antconf->antdiv_configgroup = DEFAULT_ANTDIV_CONFIG_GROUP;54}5556void57ar9285_antdiv_comb_conf_set(struct ath_hal *ah, HAL_ANT_COMB_CONFIG *antconf)58{59uint32_t regval;6061regval = OS_REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);62regval &= ~(AR_PHY_9285_ANT_DIV_MAIN_LNACONF |63AR_PHY_9285_ANT_DIV_ALT_LNACONF |64AR_PHY_9285_FAST_DIV_BIAS);65regval |= ((antconf->main_lna_conf << AR_PHY_9285_ANT_DIV_MAIN_LNACONF_S)66& AR_PHY_9285_ANT_DIV_MAIN_LNACONF);67regval |= ((antconf->alt_lna_conf << AR_PHY_9285_ANT_DIV_ALT_LNACONF_S)68& AR_PHY_9285_ANT_DIV_ALT_LNACONF);69regval |= ((antconf->fast_div_bias << AR_PHY_9285_FAST_DIV_BIAS_S)70& AR_PHY_9285_FAST_DIV_BIAS);7172OS_REG_WRITE(ah, AR_PHY_MULTICHAIN_GAIN_CTL, regval);73}7475/*76* Check whether combined + fast antenna diversity should be enabled.77*78* This enables software-driven RX antenna diversity based on RX79* RSSI + antenna config packet sampling.80*/81HAL_BOOL82ar9285_check_div_comb(struct ath_hal *ah)83{84uint8_t ant_div_ctl1;85HAL_EEPROM_v4k *ee = AH_PRIVATE(ah)->ah_eeprom;86const MODAL_EEP4K_HEADER *pModal = &ee->ee_base.modalHeader;8788#if 089/* For now, simply disable this until it's better debugged. -adrian */90return AH_FALSE;91#endif9293if (! AR_SREV_KITE(ah))94return AH_FALSE;9596if (pModal->version < 3)97return AH_FALSE;9899ant_div_ctl1 = pModal->antdiv_ctl1;100if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1))101return AH_TRUE;102103return AH_FALSE;104}105106107