xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8189fs/hal/phydm/phydm_lna_sat.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2017  Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * The full GNU General Public License is included in this distribution in the
15  * file called LICENSE.
16  *
17  * Contact Information:
18  * wlanfae <wlanfae@realtek.com>
19  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20  * Hsinchu 300, Taiwan.
21  *
22  * Larry Finger <Larry.Finger@lwfinger.net>
23  *
24  *****************************************************************************/
25 
26 #ifndef __PHYDM_LNA_SAT_H__
27 #define __PHYDM_LNA_SAT_H__
28 #ifdef PHYDM_LNA_SAT_CHK_SUPPORT
29 /* @1 ============================================================
30  * 1  Definition
31  * 1 ============================================================
32  */
33 
34 #define LNA_SAT_VERSION "1.0"
35 
36 /*@LNA saturation check*/
37 #define	OFDM_AGC_TAB_0			0
38 #define	OFDM_AGC_TAB_2			2
39 
40 #define	DIFF_RSSI_TO_IGI		10
41 #define	ONE_SEC_MS			1000
42 
43 #define LNA_CHK_PERIOD			100 /*@ms*/
44 #define LNA_CHK_CNT			10 /*@checks per callback*/
45 #define LNA_CHK_DUTY_CYCLE		5 /*@percentage*/
46 
47 #define	DELTA_STD	2
48 #define	DELTA_MEAN	2
49 #define	SNR_STATISTIC_SHIFT	8
50 #define	SNR_RPT_MAX	256
51 
52 /* @1 ============================================================
53  * 1 enumrate
54  * 1 ============================================================
55  */
56 
57 enum lna_sat_timer_state {
58 	INIT_LNA_SAT_CHK_TIMMER,
59 	CANCEL_LNA_SAT_CHK_TIMMER,
60 	RELEASE_LNA_SAT_CHK_TIMMER
61 };
62 
63 #ifdef PHYDM_LNA_SAT_CHK_TYPE2
64 enum lna_sat_chk_type2_status {
65 	ORI_TABLE_MONITOR,
66 	ORI_TABLE_TRAINING,
67 	SAT_TABLE_MONITOR,
68 	SAT_TABLE_TRAINING,
69 	SAT_TABLE_TRY_FAIL,
70 	ORI_TABLE_TRY_FAIL
71 };
72 
73 #endif
74 
75 enum lna_sat_type {
76 	LNA_SAT_WITH_PEAK_DET	= 1,	/*type1*/
77 	LNA_SAT_WITH_TRAIN	= 2,	/*type2*/
78 };
79 
80 /* @1 ============================================================
81  * 1  structure
82  * 1 ============================================================
83  */
84 
85 struct phydm_lna_sat_t {
86 #ifdef PHYDM_LNA_SAT_CHK_TYPE1
87 	u8			chk_cnt;
88 	u8			chk_duty_cycle;
89 	u32			chk_period;/*@ms*/
90 	boolean			is_disable_lna_sat_chk;
91 	boolean			dis_agc_table_swh;
92 #endif
93 #ifdef PHYDM_LNA_SAT_CHK_TYPE2
94 	u8			force_traget_macid;
95 	u32			snr_var_thd;
96 	u32			delta_snr_mean;
97 	u16			ori_table_try_fail_times;
98 	u16			cnt_lower_snr_statistic;
99 	u16			sat_table_monitor_times;
100 	u16			force_change_period;
101 	u8			is_snr_detail_en;
102 	u8			is_force_lna_sat_table;
103 	u8			lwr_snr_ratio_bit_shift;
104 	u8			cnt_snr_statistic;
105 	u16			snr_statistic_sqr[SNR_RPT_MAX];
106 	u8			snr_statistic[SNR_RPT_MAX];
107 	u8			is_sm_done;
108 	u8			is_snr_done;
109 	u32			cur_snr_var;
110 	u8			total_bit_shift;
111 	u8			total_cnt_snr;
112 	u32			cur_snr_mean;
113 	u8			cur_snr_var0;
114 	u32			cur_lower_snr_mean;
115 	u32			pre_snr_mean;
116 	u32			pre_snr_var;
117 	u32			pre_lower_snr_mean;
118 	u8			nxt_state;
119 	u8			pre_state;
120 #endif
121 	enum lna_sat_type	lna_sat_type;
122 	u32			sat_cnt_acc_patha;
123 	u32			sat_cnt_acc_pathb;
124 #ifdef PHYDM_IC_ABOVE_3SS
125 	u32			sat_cnt_acc_pathc;
126 #endif
127 #ifdef PHYDM_IC_ABOVE_4SS
128 	u32			sat_cnt_acc_pathd;
129 #endif
130 	u32			check_time;
131 	boolean			pre_sat_status;
132 	boolean			cur_sat_status;
133 	struct phydm_timer_list	phydm_lna_sat_chk_timer;
134 	u32			cur_timer_check_cnt;
135 	u32			pre_timer_check_cnt;
136 };
137 
138 /* @1 ============================================================
139  * 1 function prototype
140  * 1 ============================================================
141  */
142 void phydm_lna_sat_chk_init(void *dm_void);
143 
144 u8 phydm_get_ofdm_agc_tab(void *dm_void);
145 
146 void phydm_lna_sat_chk(void *dm_void);
147 
148 void phydm_lna_sat_chk_timers(void *dm_void, u8 state);
149 
150 #ifdef PHYDM_LNA_SAT_CHK_TYPE1
151 #if (RTL8198F_SUPPORT || RTL8814B_SUPPORT)
152 void phydm_lna_sat_chk_bb_init(void *dm_void);
153 
154 void phydm_set_ofdm_agc_tab_path(void *dm_void,
155 				 u8 tab_sel, enum rf_path path);
156 
157 u8 phydm_get_ofdm_agc_tab_path(void *dm_void, enum rf_path path);
158 #endif /*@#if (RTL8198F_SUPPORT || RTL8814B_SUPPORT)*/
159 #endif
160 
161 #ifdef PHYDM_LNA_SAT_CHK_TYPE2
162 void phydm_parsing_snr(void *dm_void, void *pktinfo_void, s8 *rx_snr);
163 #endif
164 
165 void phydm_lna_sat_debug(void *dm_void, char input[][16], u32 *_used,
166 			 char *output, u32 *_out_len);
167 
168 void phydm_lna_sat_chk_watchdog(void *dm_void);
169 
170 void phydm_lna_sat_check_init(void *dm_void);
171 
172 #endif /*@#if (PHYDM_LNA_SAT_CHK_SUPPORT == 1)*/
173 #endif
174