hc
2024-08-16 62c46c9150c4afde7e5b25436263fddf79d66f0b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/******************************************************************************
 *
 * Copyright(c) 2007 - 2020  Realtek Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * The full GNU General Public License is included in this distribution in the
 * file called LICENSE.
 *
 * Contact Information:
 * wlanfae <wlanfae@realtek.com>
 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
 * Hsinchu 300, Taiwan.
 *
 * Larry Finger <Larry.Finger@lwfinger.net>
 *
 *****************************************************************************/
#include "../halbb_precomp.h"
 
#ifdef BB_8852B_SUPPORT
 
bool halbb_chk_pkg_valid_8852b(struct bb_info *bb, u8 bb_ver, u8 rf_ver)
{
   bool valid = true;
 
#if 0
   if (bb_ver >= X && rf_ver >= Y)
       valid = true;
   else if (bb_ver < X && rf_ver < Y)
       valid = true;
   else
       valid = false;
#endif
 
   if (!valid) {
       /*halbb_set_reg(bb, 0x1c3c, (BIT(0) | BIT(1)), 0x0);*/
       BB_WARNING("[%s] Pkg_ver{bb, rf}={%d, %d} disable all BB block\n",
            __func__, bb_ver, rf_ver);
   }
 
   return valid;
}
 
 
void halbb_stop_pmac_tx_8852b(struct bb_info *bb,
                 struct halbb_pmac_info *tx_info,
                 enum phl_phy_idx phy_idx)
{
   if (tx_info->is_cck) { // CCK
       if (tx_info->mode == CONT_TX) {
           halbb_set_reg(bb, 0x2300, BIT(26), 1);
           halbb_set_reg(bb, 0x2338, BIT(17), 0);
           halbb_set_reg(bb, 0x2300, BIT(28), 0);
           halbb_set_reg(bb, 0x2300, BIT(26), 0);
       } else if (tx_info->mode == PKTS_TX) {
           halbb_set_reg_cmn(bb, 0x9c4, BIT(4), 0, phy_idx);
       }
   } else { // OFDM
       if (tx_info->mode == CONT_TX)
           halbb_set_reg_cmn(bb, 0x9c4, BIT(0), 0, phy_idx);
       else if (tx_info->mode == PKTS_TX)
           halbb_set_reg_cmn(bb, 0x9c4, BIT(4), 0, phy_idx);
   }
}
 
 
void halbb_start_pmac_tx_8852b(struct bb_info *bb,
                  struct halbb_pmac_info *tx_info,
                  enum halbb_pmac_mode mode, u32 pkt_cnt,u16 period,
                  enum phl_phy_idx phy_idx)
{
   if (mode == CONT_TX) {
       if (tx_info->is_cck) {
           halbb_set_reg(bb, 0x2338, BIT(17), 1);
           halbb_set_reg(bb, 0x2300, BIT(28), 0);
       } else {
           halbb_set_reg_cmn(bb, 0x9c4, BIT(0), 1, phy_idx);
       }
   } else if (mode == PKTS_TX) {
       /*Tx_N_PACKET_EN */
       halbb_set_reg_cmn(bb, 0x9c4, BIT(4), 1, phy_idx);
       /*Tx_N_PERIOD */
       halbb_set_reg_cmn(bb, 0x9c4, 0xffffff00, period, phy_idx);
       /*Tx_N_PACKET */
       halbb_set_reg_cmn(bb, 0x9c8, 0xffffffff, pkt_cnt, phy_idx);
   } else if (mode == CCK_CARRIER_SIPPRESSION_TX) {
       if (tx_info->is_cck) {
           /*Carrier Suppress Tx*/
           halbb_set_reg(bb, 0x2338, BIT(18), 1);
           /*Disable scrambler at payload part*/
           halbb_set_reg(bb, 0x2304, BIT(26), 1);
       } else {
           return;
       }
       /*Tx_N_PACKET_EN */
       halbb_set_reg_cmn(bb, 0x9c4, BIT(4), 1, phy_idx);
       /*Tx_N_PERIOD */
       halbb_set_reg_cmn(bb, 0x9c4, 0xffffff00, period, phy_idx);
       /*Tx_N_PACKET */
       halbb_set_reg_cmn(bb, 0x9c8, 0xffffffff, pkt_cnt, phy_idx);
   }
   /*Tx_EN */
   halbb_set_reg_cmn(bb, 0x9c0, BIT(0), 1, phy_idx);
   halbb_set_reg_cmn(bb, 0x9c0, BIT(0), 0, phy_idx);
}
 
 
void halbb_set_pmac_tx_8852b(struct bb_info *bb, struct halbb_pmac_info *tx_info,
                enum phl_phy_idx phy_idx)
{
   BB_DBG(bb, DBG_PHY_CONFIG, "<====== %s ======>\n", __func__);
 
   if (!tx_info->en_pmac_tx) {
       halbb_stop_pmac_tx_8852b(bb, tx_info, phy_idx);
       /* PD hit enable */
       halbb_set_reg_cmn(bb, 0xc3c, BIT(9), 0, phy_idx);
       halbb_set_reg(bb, 0x2344, BIT(31), 0);
       return;
   }
   /*Turn on PMAC */
   /* Tx */
   halbb_set_reg_cmn(bb, 0x0980, BIT(0), 1, phy_idx);
   /* Rx */
   halbb_set_reg_cmn(bb, 0x0980, BIT(16), 1, phy_idx);
   halbb_set_reg_cmn(bb, 0x0988, 0x3f, 0x3f, phy_idx);
 
   /* PD hit enable */
   halbb_set_reg(bb, 0x704, BIT(1), 0);
   halbb_set_reg_cmn(bb, 0xc3c, BIT(9), 1, phy_idx);
   halbb_set_reg(bb, 0x2344, BIT(31), 1);
   halbb_set_reg(bb, 0x704, BIT(1), 1);
 
   halbb_start_pmac_tx_8852b(bb, tx_info, tx_info->mode, tx_info->tx_cnt,
              tx_info->period, phy_idx);
}
 
void halbb_set_tmac_tx_8852b(struct bb_info *bb, enum phl_phy_idx phy_idx)
{
   /* To do: 0x0d80[16] [25] / 0x0d88[5:0] Should be set to default value in parameter package*/
   /* Turn on TMAC */
   halbb_set_reg_cmn(bb, 0x0980, BIT(0), 0, phy_idx);
   halbb_set_reg_cmn(bb, 0x0980, BIT(16), 0, phy_idx);
   halbb_set_reg_cmn(bb, 0x0988, 0xfff, 0, phy_idx);
   halbb_set_reg_cmn(bb, 0x0994, 0xf0, 0, phy_idx);
   
   // PDP bypass from TMAC
   halbb_set_reg_cmn(bb, 0x09a4, BIT(10), 0, phy_idx);
   // TMAC Tx path
   halbb_set_reg_cmn(bb, 0x09a4, 0x1c, 0, phy_idx);
   // TMAC Tx power
   halbb_set_reg_cmn(bb, 0x09a4, BIT(16), 0, phy_idx);
}
 
void halbb_ic_hw_setting_init_8852b(struct bb_info *bb)
{
   BB_DBG(bb, DBG_PHY_CONFIG, "<====== %s ======>\n", __func__);
 
   if(phl_is_mp_mode(bb->phl_com)) {
       // r_en_sound_wo_ndp
       halbb_set_reg(bb, 0xd7c, BIT(1), 1);
       halbb_set_reg(bb, 0x2d7c, BIT(1), 1);
   } else {
       // r_en_sound_wo_ndp
       halbb_set_reg(bb, 0xd7c, BIT(1), 0);
       halbb_set_reg(bb, 0x2d7c, BIT(1), 0);
   }
}
 
void halbb_ic_hw_setting_8852b(struct bb_info *bb)
{
   bool btg_en;
   
   BB_DBG(bb, DBG_PHY_CONFIG, "<====== %s ======>\n", __func__);
   
   btg_en = (bb->hal_com->band[0].cur_chandef.band == BAND_ON_24G) &&
       ((bb->rx_path == RF_PATH_B) || (bb->rx_path == RF_PATH_AB)) ? true : false;
   
   if (btg_en && bb->bb_link_i.is_linked && (bb->bb_ch_i.rssi_min < (75 << 1))) {// if rssi < -35 dbm
       halbb_set_reg(bb, 0x4aa4, BIT(18), 0x0);
       BB_DBG(bb, DBG_PHY_CONFIG, "[BT] BTG enable, Is linked\n");
       BB_DBG(bb, DBG_PHY_CONFIG, "[BT][RSSI] rssi_min=0x%x\n", bb->bb_ch_i.rssi_min >> 1);
   } else {
       halbb_set_reg(bb, 0x4aa4, BIT(18), 0x1);
       BB_DBG(bb, DBG_PHY_CONFIG, "[BT] btg_en=%d, is_linked=%d\n", btg_en, bb->bb_link_i.is_linked);
       BB_DBG(bb, DBG_PHY_CONFIG, "[BT][RSSI] rssi_min=0x%x\n", bb->bb_ch_i.rssi_min >> 1);
   }
 
}
 
bool halbb_set_pd_lower_bound_8852b(struct bb_info *bb, u8 bound,
                     enum channel_width bw,
                     enum phl_phy_idx phy_idx)
{
   /* 
   Range of bound value: 
   BW20: 95~33
   BW40: 92~30
   BW80: 89~27
   */
   u8 bw_attenuation = 0;
   u8 subband_filter_atteniation = 7;
   u8 bound_idx = 0;
   bool rpt = true;
 
   BB_DBG(bb, DBG_PHY_CONFIG, "<====== %s ======>\n", __func__);
 
   if (bound == 0) {
       halbb_set_reg_cmn(bb, 0x4860, BIT(30), 0, phy_idx);
       BB_DBG(bb, DBG_PHY_CONFIG,
              "[PD Bound] Set Boundary to default!\n");
       return true;
   }
 
   bb->bb_cmn_backup_i.cur_pd_lower_bound = bound;
 
   if (bw == CHANNEL_WIDTH_20) {
       bw_attenuation = 0;
   } else if (bw == CHANNEL_WIDTH_40) {
       bw_attenuation = 3;
   } else if (bw == CHANNEL_WIDTH_80) {
       bw_attenuation = 6;
   } else {
       BB_DBG(bb, DBG_PHY_CONFIG,
              "[PD Bound] Only support BW20/40/80 !\n");
       return false;
   }
 
   bound += (bw_attenuation + subband_filter_atteniation);
   // If Boundary dbm is odd, set it to even number
   bound = bound % 2 ? bound + 1 : bound;
 
   if (bound < 40) {
       BB_DBG(bb, DBG_PHY_CONFIG,
              "[PD Bound] Threshold too high, set to highest level!\n");
       bound = 40;
       rpt = false;
   }
 
   if (bound > 102) {
       BB_DBG(bb, DBG_PHY_CONFIG,
              "[PD Bound] Threshold too low, disable PD lower bound function!\n");
       halbb_set_reg_cmn(bb, 0x4860, BIT(30), 0, phy_idx);
       return true;
   }
 
   bound_idx =  (102 - bound) >> 1;
 
   halbb_set_reg_cmn(bb, 0x4860, 0x7c0, bound_idx, phy_idx);
   halbb_set_reg_cmn(bb, 0x4860, BIT(30), 1, phy_idx);
 
   BB_DBG(bb, DBG_PHY_CONFIG, "[PD Bound] Set Boundary Success!\n");
 
   return rpt;
}
 
bool halbb_set_pd_lower_bound_cck_8852b(struct bb_info *bb, u8 bound,
                     enum channel_width bw,
                     enum phl_phy_idx phy_idx)
{
   u8 bw_attenuation = 0;
   u8 subband_filter_atteniation = 5;
   s8 bound_tmp = 0;
 
   BB_DBG(bb, DBG_PHY_CONFIG, "<====== %s ======>\n", __func__);
 
   if (bb->hal_com->cv < CBV) {
       BB_DBG(bb, DBG_PHY_CONFIG, "[PD Bound] CCK pd_lower_bound CV not support!\n");
       return false;
   }
   
   if (bound == 0) {
       halbb_set_reg_cmn(bb, 0x23b0, BIT(23), 0, phy_idx);
       BB_DBG(bb, DBG_PHY_CONFIG,
           "[PD Bound] Set Boundary to default!\n");
       return true;
   }
 
   if (bw == CHANNEL_WIDTH_20) {
       bw_attenuation = 0;
   }
   else if (bw == CHANNEL_WIDTH_40) {
       bw_attenuation = 3;
   }
   else if (bw == CHANNEL_WIDTH_80) {
       bw_attenuation = 6;
   }
   else {
       BB_DBG(bb, DBG_PHY_CONFIG,
           "[PD Bound] Only support BW20/40/80 !\n");
       return true;
   }
 
   bound += (bw_attenuation + subband_filter_atteniation);
   bound_tmp = (-1) * MIN_2(bound, 128);
 
   halbb_set_reg_cmn(bb, 0x23b0, 0xff000000, bound_tmp, phy_idx);
   halbb_set_reg_cmn(bb, 0x23b4, 0xff000000, 0x7f, phy_idx);
   halbb_set_reg_cmn(bb, 0x23b0, BIT(23), 1, phy_idx);
 
   BB_DBG(bb, DBG_PHY_CONFIG, "[PD Bound] Set CCK Boundary Success!\n");
 
   return true;
}
 
u8 halbb_querry_pd_lower_bound_8852b(struct bb_info *bb, bool get_en_info, enum phl_phy_idx phy_idx)
{
   u8 tmp;
 
   BB_DBG(bb, DBG_PHY_CONFIG, "<====== %s ======>\n", __func__);
 
   if (get_en_info)
       tmp = (u8)halbb_get_reg_cmn(bb, 0x4860, BIT(30), phy_idx);
   else
       tmp = bb->bb_cmn_backup_i.cur_pd_lower_bound;
 
   return tmp;
}
 
void halbb_pop_en_8852b(struct bb_info *bb, bool en, enum phl_phy_idx phy_idx)
{
   BB_DBG(bb, DBG_PHY_CONFIG, "<====== %s ======>\n", __func__);
 
   if (en) {
       halbb_set_reg_cmn(bb, 0x47D4, BIT(8), 1, phy_idx);
 
   } else {
       halbb_set_reg_cmn(bb, 0x47D4, BIT(8), 0, phy_idx);
   }
}
 
bool halbb_querry_pop_en_8852b(struct bb_info *bb, enum phl_phy_idx phy_idx)
{
   bool en;
 
   BB_DBG(bb, DBG_PHY_CONFIG, "<====== %s ======>\n", __func__);
 
   en = (bool)halbb_get_reg_cmn(bb, 0x47D4, BIT(8), phy_idx);
 
   return en;
}
#endif