Path: blob/main/sys/dev/ath/ath_hal/ar9002/ar9285_diversity.c
39566 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2008-2010 Atheros Communications Inc.4* Copyright (c) 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_desc.h"31#include "ah_internal.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"4041#include "ar9002/ar9285_diversity.h"4243/*44* Set the antenna switch to control RX antenna diversity.45*46* If a fixed configuration is used, the LNA and div bias47* settings are fixed and the antenna diversity scanning routine48* is disabled.49*50* If a variable configuration is used, a default is programmed51* in and sampling commences per RXed packet.52*53* Since this is called from ar9285SetBoardValues() to setup54* diversity, it means that after a reset or scan, any current55* software diversity combining settings will be lost and won't56* re-appear until after the first successful sample run.57* Please keep this in mind if you're seeing weird performance58* that happens to relate to scan/diversity timing.59*/60HAL_BOOL61ar9285SetAntennaSwitch(struct ath_hal *ah, HAL_ANT_SETTING settings)62{63int regVal;64const HAL_EEPROM_v4k *ee = AH_PRIVATE(ah)->ah_eeprom;65const MODAL_EEP4K_HEADER *pModal = &ee->ee_base.modalHeader;66uint8_t ant_div_control1, ant_div_control2;6768if (pModal->version < 3) {69HALDEBUG(ah, HAL_DEBUG_DIVERSITY, "%s: not supported\n",70__func__);71return AH_FALSE; /* Can't do diversity */72}7374/* Store settings */75AH5212(ah)->ah_antControl = settings;76AH5212(ah)->ah_diversity = (settings == HAL_ANT_VARIABLE);7778/* XXX don't fiddle if the PHY is in sleep mode or ! chan */7980/* Begin setting the relevant registers */8182ant_div_control1 = pModal->antdiv_ctl1;83ant_div_control2 = pModal->antdiv_ctl2;8485regVal = OS_REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);86regVal &= (~(AR_PHY_9285_ANT_DIV_CTL_ALL));8788/* enable antenna diversity only if diversityControl == HAL_ANT_VARIABLE */89if (settings == HAL_ANT_VARIABLE)90regVal |= SM(ant_div_control1, AR_PHY_9285_ANT_DIV_CTL);9192if (settings == HAL_ANT_VARIABLE) {93HALDEBUG(ah, HAL_DEBUG_DIVERSITY, "%s: HAL_ANT_VARIABLE\n",94__func__);95regVal |= SM(ant_div_control2, AR_PHY_9285_ANT_DIV_ALT_LNACONF);96regVal |= SM((ant_div_control2 >> 2), AR_PHY_9285_ANT_DIV_MAIN_LNACONF);97regVal |= SM((ant_div_control1 >> 1), AR_PHY_9285_ANT_DIV_ALT_GAINTB);98regVal |= SM((ant_div_control1 >> 2), AR_PHY_9285_ANT_DIV_MAIN_GAINTB);99} else {100if (settings == HAL_ANT_FIXED_A) {101/* Diversity disabled, RX = LNA1 */102HALDEBUG(ah, HAL_DEBUG_DIVERSITY, "%s: HAL_ANT_FIXED_A\n",103__func__);104regVal |= SM(HAL_ANT_DIV_COMB_LNA2, AR_PHY_9285_ANT_DIV_ALT_LNACONF);105regVal |= SM(HAL_ANT_DIV_COMB_LNA1, AR_PHY_9285_ANT_DIV_MAIN_LNACONF);106regVal |= SM(AR_PHY_9285_ANT_DIV_GAINTB_0, AR_PHY_9285_ANT_DIV_ALT_GAINTB);107regVal |= SM(AR_PHY_9285_ANT_DIV_GAINTB_1, AR_PHY_9285_ANT_DIV_MAIN_GAINTB);108}109else if (settings == HAL_ANT_FIXED_B) {110/* Diversity disabled, RX = LNA2 */111HALDEBUG(ah, HAL_DEBUG_DIVERSITY, "%s: HAL_ANT_FIXED_B\n",112__func__);113regVal |= SM(HAL_ANT_DIV_COMB_LNA1, AR_PHY_9285_ANT_DIV_ALT_LNACONF);114regVal |= SM(HAL_ANT_DIV_COMB_LNA2, AR_PHY_9285_ANT_DIV_MAIN_LNACONF);115regVal |= SM(AR_PHY_9285_ANT_DIV_GAINTB_1, AR_PHY_9285_ANT_DIV_ALT_GAINTB);116regVal |= SM(AR_PHY_9285_ANT_DIV_GAINTB_0, AR_PHY_9285_ANT_DIV_MAIN_GAINTB);117}118}119120OS_REG_WRITE(ah, AR_PHY_MULTICHAIN_GAIN_CTL, regVal);121regVal = OS_REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);122regVal = OS_REG_READ(ah, AR_PHY_CCK_DETECT);123regVal &= (~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);124if (settings == HAL_ANT_VARIABLE)125regVal |= SM((ant_div_control1 >> 3), AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);126127OS_REG_WRITE(ah, AR_PHY_CCK_DETECT, regVal);128regVal = OS_REG_READ(ah, AR_PHY_CCK_DETECT);129130/*131* If Diversity combining is available and the diversity setting132* is to allow variable diversity, enable it by default.133*134* This will be eventually overridden by the software antenna135* diversity logic.136*137* Note that yes, this following section overrides the above138* settings for the LNA configuration and fast-bias.139*/140if (ar9285_check_div_comb(ah) && AH5212(ah)->ah_diversity == AH_TRUE) {141// If support DivComb, set MAIN to LNA1 and ALT to LNA2 at the first beginning142HALDEBUG(ah, HAL_DEBUG_DIVERSITY,143"%s: Enable initial settings for combined diversity\n",144__func__);145regVal = OS_REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);146regVal &= (~(AR_PHY_9285_ANT_DIV_MAIN_LNACONF | AR_PHY_9285_ANT_DIV_ALT_LNACONF));147regVal |= (HAL_ANT_DIV_COMB_LNA1 << AR_PHY_9285_ANT_DIV_MAIN_LNACONF_S);148regVal |= (HAL_ANT_DIV_COMB_LNA2 << AR_PHY_9285_ANT_DIV_ALT_LNACONF_S);149regVal &= (~(AR_PHY_9285_FAST_DIV_BIAS));150regVal |= (0 << AR_PHY_9285_FAST_DIV_BIAS_S);151OS_REG_WRITE(ah, AR_PHY_MULTICHAIN_GAIN_CTL, regVal);152}153154return AH_TRUE;155}156157158