• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description: Header file for hal_rf.c.
15  */
16 
17 #ifndef __HAL_RF_H__
18 #define __HAL_RF_H__
19 
20 /*****************************************************************************
21   1 其他头文件包含
22 *****************************************************************************/
23 #include "hal_ext_if.h"
24 #include "hal_device.h"
25 #include "fe_rf_customize.h"
26 #include "fe_hal_rf_reg_if.h"
27 #include "fe_rf_customize_rx_insert_loss.h"
28 #include "fe_rf_dev.h"
29 #ifdef __cplusplus
30 #if __cplusplus
31 extern "C" {
32 #endif
33 #endif
34 
35 #undef  THIS_FILE_ID
36 #define THIS_FILE_ID OAM_FILE_ID_HAL_RF_H
37 /*****************************************************************************
38   2 共用宏定义
39 *****************************************************************************/
40 #define HH503_SOC_BUCK_RO         0x400032B4
41 
42 /* wifi校准buf长度 */
43 #define RF_CALI_DATA_BUF_LEN              (0x6cd8)
44 #define RF_SINGLE_CHAN_CALI_DATA_BUF_LEN  (RF_CALI_DATA_BUF_LEN >> 1)
45 #define HH503_TEMPERATURE_THRESH         50
46 
47 #ifdef _PRE_WLAN_03_MPW_RF
48 #define HH503_TOP_TST_SW2                      30
49 #endif /* end of _PRE_WLAN_03_MPW_RF */
50 
51 #ifdef _PRE_WLAN_03_MPW_RF
52 #define HH503_PLL_LD_REG34           34
53 #endif
54 
55 #define HH503_RF_TCXO_25MHZ          1
56 #define HH503_RF_TCXO_40MHZ          2
57 #define HH503_RF_TCXO_384MHZ         3
58 
59 #define HH503_RF_LPF_GAIN_DEFAULT_VAL    0x4688
60 #define HH503_RF_DAC_GAIN_DEFAULT_VAL    0x24
61 
62 /* PLL使能默认值配置 */
63 #ifdef _PRE_WLAN_03_MPW_RF
64 #define HH503_WL_PLL1_RFLDO789_ENABLE      0xFF00
65 #endif
66 
67 #define HH503_RF_2G_CHANNEL_NUM        13
68 #define HH503_RF_5G_CHANNEL_NUM        7
69 
70 #define HH503_RF_FREQ_2_CHANNEL_NUM  14  /* 2g支持信道数目 */
71 #define HH503_RF_FREQ_5_CHANNEL_NUM  29  /* 5g支持信道数目 */
72 
73 #define HH503_CALI_CHN_INDEX_2422        0
74 #define HH503_CALI_CHN_INDEX_2447        1
75 #define HH503_CALI_CHN_INDEX_2472        2
76 
77 #define CHANNEL_NUM5_IDX          4
78 #define CHANNEL_NUM10_IDX          9
79 
80 #define HH503_CALI_CHN_INDEX_4950        0
81 #define HH503_CALI_CHN_INDEX_5210        1
82 #define HH503_CALI_CHN_INDEX_5290        2
83 #define HH503_CALI_CHN_INDEX_5530        3
84 #define HH503_CALI_CHN_INDEX_5610        4
85 #define HH503_CALI_CHN_INDEX_5690        5
86 #define HH503_CALI_CHN_INDEX_5775        6
87 
88 #define HH503_RF_TEMP_STS_RSV                  0x7
89 
90 #define HH503_RF_TEMP_INVALID                   (-100)   /* 温度非法值 */
91 
92 #ifdef _PRE_PLAT_FEATURE_CUSTOMIZE
93 /* RF定制化PA偏置寄存器个数 */
94 #define HH503_TX2G_PA_GATE_VCTL_REG_NUM        (9)
95 #define HH503_TX2G_PA_VRECT_GATE_THIN_REG_NUM  (32)
96 #define HH503_TX2G_REG_280_BAND2_3_NUM         (2)
97 #define HH503_TX2G_PA_GATE_REG_NUM    (HH503_TX2G_PA_GATE_VCTL_REG_NUM + HH503_TX2G_PA_VRECT_GATE_THIN_REG_NUM + \
98     HH503_TX2G_REG_280_BAND2_3_NUM)
99 #endif
100 
101 /* RF发送和接收带宽枚举 */
102 typedef enum {
103     HH503_RF_BAND_CTRL_10M,
104     HH503_RF_BAND_CTRL_20M,
105     HH503_RF_BAND_CTRL_40M,
106     HH503_RF_BAND_CTRL_80M,
107 
108     HH503_RF_BAND_CTRL_BUTT
109 } hh503_rf_bandwidth_enum;
110 typedef osal_u8 hh503_rf_bandwidth_enum_uint8;
111 
112 typedef enum {
113     RFLDO_EN_OFF,
114     RF_EN_OFF,  /* 全关,包括RF_LDO */
115     RF_OFF_BUTT
116 } rf_off_flag_enum;
117 typedef osal_u8 rf_off_flag_enum_uint8;
118 
119 /* 校准信道序号结构体 */
120 typedef struct {
121     osal_u8   norm2_dpa_idx_5g20m[HH503_RF_FREQ_5_CHANNEL_NUM];
122     osal_u8   norm2_dpa_idx_2g[HH503_RF_FREQ_2_CHANNEL_NUM];
123     osal_u8   other_dpa_idx_2g;
124     osal_u8   other_dpa_idx_5g;
125 } hh503_cali_chn_idx_stru;
126 
127 typedef struct {
128     hal_rf_trx_type_enum           trx_type;            /* 发送链路类型 */
129     hal_rf_trx_type_enum           trx_type_hist;       /* 历史发送链路类型 */
130     osal_bool                        trx_type_change;     /* 发送链路类型标志 */
131     osal_u8                          rf_enabled     : 1,  /* rf使能标志 */
132                                    ldo_2g_wf0_on  : 1,  /* 2.4g WF0 ldo打开标志 */
133                                    ldo_2g_wf1_on  : 1,  /* 2.4g WF0 ldo打开标志 */
134                                    ldo_5g_wf0_on  : 1,  /* 5g ldo打开标志 */
135                                    ldo_5g_wf1_on  : 1,  /* 5g ldo打开标志 */
136                                    resv           : 3;  /* 5:保留位 */
137     hal_rf_chn_param               chn_para;            /* 工作信道参数 */
138 } hal_rf;
139 
140 /*****************************************************************************
141   RF函数声明
142 *****************************************************************************/
143 /*****************************************************************************
144   ABB相关接口
145 *****************************************************************************/
146 #ifdef _PRE_PLAT_FEATURE_CUSTOMIZE
147 typedef struct {
148     /* 2g */
149     hal_cfg_custom_gain_db_per_band_stru   gain_db_2g[HAL_DEVICE_2G_BAND_NUM_FOR_LOSS];
150 #ifdef _PRE_WLAN_SUPPORT_5G
151     /* 5g */
152     hal_cfg_custom_gain_db_per_band_stru   gain_db_5g[HAL_DEVICE_5G_BAND_NUM_FOR_LOSS];
153 #endif
154 } hh503_cfg_custom_gain_db_rf_stru;
155 
156 typedef struct {
157     osal_s8   cfg_delta_pwr_ref_rssi_2g[HAL_DEVICE_2G_DELTA_RSSI_NUM];
158 #ifdef _PRE_WLAN_SUPPORT_5G
159     osal_s8   cfg_delta_pwr_ref_rssi_5g[HAL_DEVICE_5G_DELTA_RSSI_NUM];
160 #endif
161 } hh503_cfg_custom_delta_pwr_ref_stru;
162 
163 /* 03 rf相关的定制化参数结构体 */
164 typedef struct {
165     /* INI */
166     hh503_cfg_custom_gain_db_rf_stru       rf_gain_db_rf[WLAN_RF_CHANNEL_NUMS];           /* 2.4g 5g插损 */
167     hh503_cfg_custom_delta_pwr_ref_stru    delta_pwr_ref_cfg[WLAN_RF_CHANNEL_NUMS];      /* 2.4g 5g delta_rssi值 */
168     osal_u16                              aus_dyn_cali_dscr_interval[WLAN_BAND_BUTT];   /* 动态校准开关2.4g 5g */
169     osal_u8                               far_dist_pow_gain_switch;                  /* 超远距离功率增益开关 */
170     osal_u8                               band_5g_enable;                            /* 软件配置mac dev是否支持5g */
171     osal_u8                               tone_amp_grade;                            /* 单音幅度档位 */
172     osal_u8                               far_dist_dsss_scale_promote_switch;  /* 超远距11b 1m 2m dbb scale提升使能开关 */
173 
174     /* BIT3:CHA1_5G BIT2:CHA0_5G BIT1:CHA1_2G BIT0:CHA0_2G */
175     osal_u8                               chn_radio_cap;
176     osal_u8                               rsv[3];
177 
178     /* cca ed thr */
179     hal_cfg_custom_cca_stru                 cfg_cus_cca;
180 
181     /* 过温/恢复门限 */
182     osal_u16                              over_temp_protect_thread;
183     osal_u16                              recovery_temp_protect_thread;
184 } hh503_rf_custom_stru;
185 
186 typedef struct {
187     osal_s32                  power;
188     osal_u16                  mode_ctrl;
189     osal_u16                  mode_gain;
190     osal_u16                  pa_gain;
191     osal_u16                  abb_gain;
192     osal_u32                  scaling;
193 } hh503_adjust_tx_power_stru;
194 
195 typedef struct {
196     osal_s32 power; /* 命令行中的功率 */
197     osal_u8 tpc_code; /* 功率对应的tpc code, 用于设置wifi aware action帧功率 */
198     osal_u8 resrv[3];
199 } hh503_adjust_tx_power_level_stru;
200 
201 typedef struct {
202     osal_u8 index; /* 插损值的索引值 */
203     osal_u8 channel_num_min; /* 插损值信道最小区间 */
204     osal_u8 channel_num_max; /* 插损值信道最大区间 */
205     osal_u8 reseve;
206 } hh503_band_num_for_loss;
207 
208 /* 插损值索引与信道范围的对应关系 */
209 static const hh503_band_num_for_loss g_band_num_for_loss[] = {
210     {0, 1, 4, 0}, {1, 6, 11, 0}, {2, 13, 14, 0},
211     {0, 184, 196, 0}, {1, 36, 48, 0}, {2, 52, 64, 0},
212     {3, 100, 112, 0}, {4, 116, 128, 0}, {5, 132, 140, 0},
213     {6, 149, 165, 0}
214 };
215 #endif // #ifdef _PRE_PLAT_FEATURE_CUSTOMIZE
216 
217 osal_void hh503_set_rf_bw(wlan_bw_cap_enum_uint8 bw);
218 
219 /* 回调函数实现 */
220 osal_void hh503_rf_set_trx_type_ext(hal_rf_trx_type_enum trx_type);
221 osal_void hh503_dpd_cfr_set_11b_ext(const hal_to_dmac_device_stru *hal_device, osal_u8 is_11b);
222 osal_void hh503_cali_send_func_ext(hal_to_dmac_device_stru *hal_device, osal_u8* cali_data, osal_u16 frame_len,
223     osal_u16 remain);
224 osal_u32 hh503_config_custom_rf_ext(const osal_u8 *param);
225 osal_void hh503_config_rssi_for_loss_ext(osal_u8 channel_num, osal_s8 *rssi);
226 osal_void hh503_set_rf_custom_reg_ext(const hal_to_dmac_device_stru *hal_device);
227 osal_void hh503_initialize_rf_sys_ext(hal_to_dmac_device_stru *hal_device);
228 osal_void hh503_pow_set_rf_regctl_enable_ext(const hal_to_dmac_device_stru *hal_device,
229     oal_bool_enum_uint8 rf_linectl);
230 osal_u8 hh503_get_tpc_code_ext(osal_void);
231 osal_void hh503_adjust_tx_power_level_ext(osal_u8 ch, osal_s8 power);
232 
233 /*****************************************************************************
234   11 ROM回调函数类型定义
235 *****************************************************************************/
236 /* hal */
237 typedef osal_u8 (*hh503_get_rx_chain_cb)(osal_void);
238 typedef osal_void (*hh503_set_rf_bw_cb)(wlan_bw_cap_enum_uint8 bw);
239 
240 #ifdef _PRE_WLAN_FEATURE_TEMP_PROTECT
241 typedef osal_void (*hh503_read_max_temperature_cb)(osal_s16 *ps_temperature);
242 #endif
243 typedef osal_void (*hh503_rf_set_trx_type_cb)(hal_rf_trx_type_enum trx_type);
244 typedef osal_void (*hh503_dpd_cfr_set_11b_cb)(hal_to_dmac_device_stru *hal_device, osal_u8 is_11b);
245 typedef osal_void (*hh503_cali_send_func_cb)(hal_to_dmac_device_stru *hal_device, osal_u8* cali_data,
246     osal_u16 frame_len, osal_u16 remain);
247 typedef osal_u32 (*hh503_config_custom_rf_cb)(const osal_u8 *param);
248 typedef osal_void (*hh503_config_rssi_for_loss_cb)(osal_u8 channel_num, osal_s8 *rssi);
249 typedef osal_void (*hh503_set_rf_custom_reg_cb)(hal_to_dmac_device_stru *hal_device);
250 
251 #ifdef _PRE_PLAT_FEATURE_CUSTOMIZE
252 typedef osal_u32 (*hh503_config_custom_dts_cali_cb)(const osal_u8 *param);
253 #endif
254 typedef osal_void (*hh503_initialize_rf_sys_cb)(hal_to_dmac_device_stru *hal_device);
255 typedef osal_void (*hh503_adjust_tx_power_cb)(osal_u8 ch, osal_s8 power);
256 typedef osal_void (*hh503_restore_tx_power_cb)(osal_u8 ch);
257 typedef osal_u8 (*hh503_rf_get_subband_idx_cb)(wlan_channel_band_enum_uint8 band, osal_u8 channel_idx);
258 typedef osal_void (*hh503_pow_set_rf_regctl_enable_cb)(hal_to_dmac_device_stru *hal_device,
259     oal_bool_enum_uint8 rf_linectl);
260 #ifdef _PRE_WLAN_FEATURE_ALWAYS_TX
261 osal_void hal_rf_get_rx_ppdu_info(osal_u8 flag);
262 #endif
263 osal_void hal_radar_sensing_switch_abb_lo_tx_top_test_reg12(osal_bool is_on);
264 osal_void hal_set_cal_tone(osal_u32 tone_cfg);
265 #ifdef __cplusplus
266 #if __cplusplus
267 }
268 #endif
269 #endif
270 
271 #endif /* end of hal_rf.h */
272