FreeBSD kernel ATH device code
ar5416_cal_adcgain.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: ISC
3 *
4 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
5 * Copyright (c) 2002-2008 Atheros Communications, Inc.
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 *
19 * $FreeBSD$
20 */
21#include "opt_ah.h"
22
23#include "ah.h"
24#include "ah_internal.h"
25#include "ah_devid.h"
26
27#include "ar5416/ar5416.h"
28#include "ar5416/ar5416reg.h"
29#include "ar5416/ar5416phy.h"
30
31/* Adc Gain Cal aliases */
32#define totalAdcIOddPhase(i) caldata[0][i].u
33#define totalAdcIEvenPhase(i) caldata[1][i].u
34#define totalAdcQOddPhase(i) caldata[2][i].u
35#define totalAdcQEvenPhase(i) caldata[3][i].u
36
37/*
38 * Collect data from HW to later perform ADC Gain Calibration
39 */
40void
42{
43 struct ar5416PerCal *cal = &AH5416(ah)->ah_cal;
44 int i;
45
46 /*
47 * Accumulate ADC Gain cal measures for active chains
48 */
49 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
50 cal->totalAdcIOddPhase(i) +=
52 cal->totalAdcIEvenPhase(i) +=
54 cal->totalAdcQOddPhase(i) +=
56 cal->totalAdcQEvenPhase(i) +=
58
60 "%d: Chn %d oddi=0x%08x; eveni=0x%08x; oddq=0x%08x; evenq=0x%08x;\n",
61 cal->calSamples, i, cal->totalAdcIOddPhase(i),
62 cal->totalAdcIEvenPhase(i), cal->totalAdcQOddPhase(i),
63 cal->totalAdcQEvenPhase(i));
64 }
65}
66
67/*
68 * Use HW data to do ADC Gain Calibration
69 */
70void
71ar5416AdcGainCalibration(struct ath_hal *ah, uint8_t numChains)
72{
73 struct ar5416PerCal *cal = &AH5416(ah)->ah_cal;
74 uint32_t i;
75
76 for (i = 0; i < numChains; i++) {
77 uint32_t iOddMeasOffset = cal->totalAdcIOddPhase(i);
78 uint32_t iEvenMeasOffset = cal->totalAdcIEvenPhase(i);
79 uint32_t qOddMeasOffset = cal->totalAdcQOddPhase(i);
80 uint32_t qEvenMeasOffset = cal->totalAdcQEvenPhase(i);
81
83 "Start ADC Gain Cal for Chain %d\n", i);
85 " pwr_meas_odd_i = 0x%08x\n", iOddMeasOffset);
87 " pwr_meas_even_i = 0x%08x\n", iEvenMeasOffset);
89 " pwr_meas_odd_q = 0x%08x\n", qOddMeasOffset);
91 " pwr_meas_even_q = 0x%08x\n", qEvenMeasOffset);
92
93 if (iOddMeasOffset != 0 && qEvenMeasOffset != 0) {
94 uint32_t iGainMismatch =
95 ((iEvenMeasOffset*32)/iOddMeasOffset) & 0x3f;
96 uint32_t qGainMismatch =
97 ((qOddMeasOffset*32)/qEvenMeasOffset) & 0x3f;
98 uint32_t val;
99
101 " gain_mismatch_i = 0x%08x\n",
102 iGainMismatch);
104 " gain_mismatch_q = 0x%08x\n",
105 qGainMismatch);
106
108 val &= 0xfffff000;
109 val |= (qGainMismatch) | (iGainMismatch << 6);
111
113 "ADC Gain Cal done for Chain %d\n", i);
114 }
115 }
118}
@ HAL_DEBUG_PERCAL
Definition: ah_debug.h:33
#define AR5416_MAX_CHAINS
Definition: ah_eeprom_v14.h:84
#define OS_REG_SET_BIT(_a, _r, _f)
Definition: ah_internal.h:594
#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 AH5416(_ah)
Definition: ar5416.h:162
void ar5416AdcGainCalibration(struct ath_hal *ah, uint8_t numChains)
void ar5416AdcGainCalCollect(struct ath_hal *ah)
#define AR_PHY_CAL_MEAS_2(_i)
Definition: ar5416phy.h:223
#define AR_PHY_CAL_MEAS_1(_i)
Definition: ar5416phy.h:222
#define AR_PHY_NEW_ADC_DC_GAIN_CORR(_i)
Definition: ar5416phy.h:265
#define AR_PHY_NEW_ADC_GAIN_CORR_ENABLE
Definition: ar5416phy.h:266
#define AR_PHY_CAL_MEAS_3(_i)
Definition: ar5416phy.h:225
#define AR_PHY_CAL_MEAS_0(_i)
Definition: ar5416phy.h:221
int calSamples
Definition: ar5416_cal.h:82
Definition: ah.h:1219