blob: 3d70b8c2bcdd0a3ddad872f0ceff9c241f59f0a4 [file] [log] [blame]
Sujith394cf0a2009-02-09 13:26:54 +05301/*
Sujith Manoharan5b681382011-05-17 13:36:18 +05302 * Copyright (c) 2008-2011 Atheros Communications Inc.
Sujith394cf0a2009-02-09 13:26:54 +05303 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef CALIB_H
18#define CALIB_H
19
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070020#include "hw.h"
21
Sujith394cf0a2009-02-09 13:26:54 +053022#define AR_PHY_CCA_FILTERWINDOW_LENGTH 5
23
Felix Fietkaub7c0c232012-12-10 14:03:17 +010024/* Internal noise floor can vary by about 6db depending on the frequency */
25#define ATH9K_NF_CAL_NOISE_THRESH 6
26
Sujith394cf0a2009-02-09 13:26:54 +053027#define NUM_NF_READINGS 6
28#define ATH9K_NF_CAL_HIST_MAX 5
29
30struct ar5416IniArray {
31 u32 *ia_array;
32 u32 ia_rows;
33 u32 ia_columns;
34};
35
Felix Fietkaua043dfb2013-04-08 00:04:08 +020036#define STATIC_INI_ARRAY(array) { \
37 .ia_array = (u32 *)(array), \
38 .ia_rows = ARRAY_SIZE(array), \
39 .ia_columns = ARRAY_SIZE(array[0]), \
40 }
41
Felix Fietkaua3645172012-07-15 19:53:33 +020042#define INIT_INI_ARRAY(iniarray, array) do { \
Sujith394cf0a2009-02-09 13:26:54 +053043 (iniarray)->ia_array = (u32 *)(array); \
Felix Fietkaua3645172012-07-15 19:53:33 +020044 (iniarray)->ia_rows = ARRAY_SIZE(array); \
45 (iniarray)->ia_columns = ARRAY_SIZE(array[0]); \
Sujith394cf0a2009-02-09 13:26:54 +053046 } while (0)
47
48#define INI_RA(iniarray, row, column) \
49 (((iniarray)->ia_array)[(row) * ((iniarray)->ia_columns) + (column)])
50
51#define INIT_CAL(_perCal) do { \
52 (_perCal)->calState = CAL_WAITING; \
53 (_perCal)->calNext = NULL; \
54 } while (0)
55
56#define INSERT_CAL(_ahp, _perCal) \
57 do { \
Sujith2660b812009-02-09 13:27:26 +053058 if ((_ahp)->cal_list_last == NULL) { \
59 (_ahp)->cal_list = \
60 (_ahp)->cal_list_last = (_perCal); \
61 ((_ahp)->cal_list_last)->calNext = (_perCal); \
Sujith394cf0a2009-02-09 13:26:54 +053062 } else { \
Sujith2660b812009-02-09 13:27:26 +053063 ((_ahp)->cal_list_last)->calNext = (_perCal); \
64 (_ahp)->cal_list_last = (_perCal); \
65 (_perCal)->calNext = (_ahp)->cal_list; \
Sujith394cf0a2009-02-09 13:26:54 +053066 } \
67 } while (0)
68
Sujithcbfe9462009-04-13 21:56:56 +053069enum ath9k_cal_state {
Sujith394cf0a2009-02-09 13:26:54 +053070 CAL_INACTIVE,
71 CAL_WAITING,
72 CAL_RUNNING,
73 CAL_DONE
74};
75
76#define MIN_CAL_SAMPLES 1
77#define MAX_CAL_SAMPLES 64
78#define INIT_LOG_COUNT 5
79#define PER_MIN_LOG_COUNT 2
80#define PER_MAX_LOG_COUNT 10
81
Sujithcbfe9462009-04-13 21:56:56 +053082struct ath9k_percal_data {
Felix Fietkau64978272010-10-03 19:07:16 +020083 u32 calType;
Sujith394cf0a2009-02-09 13:26:54 +053084 u32 calNumSamples;
85 u32 calCountMax;
Sujithcbe61d82009-02-09 13:27:12 +053086 void (*calCollect) (struct ath_hw *);
87 void (*calPostProc) (struct ath_hw *, u8);
Sujith394cf0a2009-02-09 13:26:54 +053088};
89
Sujithcbfe9462009-04-13 21:56:56 +053090struct ath9k_cal_list {
91 const struct ath9k_percal_data *calData;
92 enum ath9k_cal_state calState;
93 struct ath9k_cal_list *calNext;
Sujith394cf0a2009-02-09 13:26:54 +053094};
95
96struct ath9k_nfcal_hist {
97 int16_t nfCalBuffer[ATH9K_NF_CAL_HIST_MAX];
98 u8 currIndex;
99 int16_t privNF;
100 u8 invalidNFcount;
101};
102
Sujitha13883b2009-08-26 08:39:40 +0530103#define MAX_PACAL_SKIPCOUNT 8
104struct ath9k_pacal_info{
105 int32_t prev_offset; /* Previous value of PA offset value */
106 int8_t max_skipcount; /* Max No. of times PACAL can be skipped */
107 int8_t skipcount; /* No. of times the PACAL to be skipped */
108};
109
Sujithcbe61d82009-02-09 13:27:12 +0530110bool ath9k_hw_reset_calvalid(struct ath_hw *ah);
Felix Fietkau00c86592010-07-30 21:02:09 +0200111void ath9k_hw_start_nfcal(struct ath_hw *ah, bool update);
Felix Fietkaubbacee12010-07-11 15:44:42 +0200112void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan);
Felix Fietkau4254bc12010-07-31 00:12:01 +0200113bool ath9k_hw_getnf(struct ath_hw *ah, struct ath9k_channel *chan);
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200114void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah,
115 struct ath9k_channel *chan);
Felix Fietkau70cf1532010-08-02 15:53:14 +0200116void ath9k_hw_bstuck_nfcal(struct ath_hw *ah);
Luis R. Rodriguez795f5e22010-04-15 17:39:00 -0400117void ath9k_hw_reset_calibration(struct ath_hw *ah,
118 struct ath9k_cal_list *currCal);
Felix Fietkauf23fba492011-07-28 14:08:56 +0200119s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan);
Luis R. Rodriguez795f5e22010-04-15 17:39:00 -0400120
Sujith394cf0a2009-02-09 13:26:54 +0530121
122#endif /* CALIB_H */