hc
2024-03-22 a0752693d998599af469473b8dc239ef973a012f
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
/******************************************************************************
 *
 * 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 "../halrf_precomp.h"
#ifdef RF_8852B_SUPPORT
 
u8 halrf_get_thermal_8852b(struct rf_info *rf, enum rf_path rf_path)
{
   halrf_wrf(rf, rf_path, 0x42, BIT(19), 0x1);
   halrf_wrf(rf, rf_path, 0x42, BIT(19), 0x0);
   halrf_wrf(rf, rf_path, 0x42, BIT(19), 0x1);
 
   halrf_delay_10us(rf, 20);
 
   return (u8)halrf_rrf(rf, rf_path, 0x42, 0x0007e);
}
 
u32 halrf_mac_get_pwr_reg_8852b(struct rf_info *rf, enum phl_phy_idx phy,
   u32 addr, u32 mask)
{
   struct rtw_hal_com_t *hal = rf->hal_com;
   u32 result, ori_val, bit_shift, reg_val;
 
   result = rtw_hal_mac_get_pwr_reg(hal, phy, addr, &ori_val);
   if (result)
       RF_WARNING("=======>%s Get MAC(0x%x) fail, error code=%d\n",
           __func__, addr, result);
   else
       RF_DBG(rf, DBG_RF_POWER, "Get MAC(0x%x) ok!!! 0x%08x\n",
           addr, ori_val);
 
   bit_shift = halrf_cal_bit_shift(mask);
   reg_val = (ori_val & mask) >> bit_shift;
 
   return reg_val;
}
 
u32 halrf_mac_set_pwr_reg_8852b(struct rf_info *rf, enum phl_phy_idx phy,
   u32 addr, u32 mask, u32 val)
{
   struct rtw_hal_com_t *hal = rf->hal_com;
   u32 result;
 
   result = rtw_hal_mac_write_msk_pwr_reg(hal, phy, addr, mask, val);
   if (result) {
       RF_WARNING("=======>%s Set MAC(0x%x[0x%08x]) fail, error code=%d\n",
           __func__, addr, mask, result);
       return false;
   } else
       RF_DBG(rf, DBG_RF_POWER, "Set MAC(0x%x[0x%08x])=0x%08x ok!!! \n",
           addr, mask, val);
 
   return result;
}
 
bool halrf_wl_tx_power_control_8852b(struct rf_info *rf, u32 tx_power_val)
{
   struct halrf_pwr_info *pwr = &rf->pwr_info;
   u32 result; 
   s32 tmp_pwr;
   u8 phy = 0;
   u32 all_time_control = 0;
   u32 gnt_bt_control = 0;
 
   RF_DBG(rf, DBG_RF_POWER, "=======>%s\n", __func__);
 
   all_time_control = tx_power_val & 0xffff;
   gnt_bt_control = (tx_power_val & 0xffff0000) >> 16;
 
   RF_DBG(rf, DBG_RF_POWER, "[Pwr Ctrl]tx_power_val=0x%x   all_time_control=0x%x   gnt_bt_control=0x%x\n",
       tx_power_val, all_time_control, gnt_bt_control);
 
   if (all_time_control == 0xffff) {
       /*Coex Disable*/
       pwr->coex_pwr_ctl_enable = false;
       pwr->coex_pwr = 0;
       RF_DBG(rf, DBG_RF_POWER, "[Pwr Ctrl] Coex Disable all_time_control=0xffff!!!\n");
   } else if (all_time_control == 0xeeee) {
       /*DPK Disable*/
       pwr->dpk_pwr_ctl_enable = false;
       pwr->dpk_pwr = 0;
       RF_DBG(rf, DBG_RF_POWER, "[Pwr Ctrl] DPK Disable all_time_control=0xeeee\n");
   } else {
       if (all_time_control & BIT(15)) {
           /*DPK*/
           pwr->dpk_pwr_ctl_enable = true;
           pwr->dpk_pwr = all_time_control & 0x1ff;
 
           RF_DBG(rf, DBG_RF_POWER, "[Pwr Ctrl] DPK Enable Set pwr->dpk_pwr = %d\n",
               pwr->dpk_pwr);
       } else {
           /*Coex*/
           pwr->coex_pwr_ctl_enable = true;
           pwr->coex_pwr = all_time_control & 0x1ff;
 
           RF_DBG(rf, DBG_RF_POWER, "[Pwr Ctrl] Coex Enable Set pwr->coex_pwr = %d\n",
               pwr->coex_pwr);
       }
   }
 
   if (pwr->coex_pwr_ctl_enable == true && pwr->dpk_pwr_ctl_enable == false) {
       tmp_pwr = pwr->coex_pwr;
 
       RF_DBG(rf, DBG_RF_POWER, "[Pwr Ctrl] coex_pwr_ctl_enable=true dpk_pwr_ctl_enable=false tmp_pwr=%d\n",
           tmp_pwr);
   } else if (pwr->coex_pwr_ctl_enable == false && pwr->dpk_pwr_ctl_enable == true) {
       tmp_pwr = pwr->dpk_pwr;
 
       RF_DBG(rf, DBG_RF_POWER, "[Pwr Ctrl] coex_pwr_ctl_enable=false dpk_pwr_ctl_enable=true tmp_pwr=%d\n",
           tmp_pwr);
   } else if (pwr->coex_pwr_ctl_enable == true && pwr->dpk_pwr_ctl_enable == true) {
       if (pwr->coex_pwr > pwr->dpk_pwr)
           tmp_pwr = pwr->dpk_pwr;
       else
           tmp_pwr = pwr->coex_pwr;
 
       RF_DBG(rf, DBG_RF_POWER, "[Pwr Ctrl] coex_pwr_ctl_enable=true dpk_pwr_ctl_enable=true tmp_pwr=%d\n",
           tmp_pwr);
   } else
       tmp_pwr = 0;
 
   if (pwr->coex_pwr_ctl_enable == false && pwr->dpk_pwr_ctl_enable == false) {
       /*all-time control Disable*/
       result = halrf_mac_set_pwr_reg_8852b(rf, phy, 0xd200, 0xfffffc00, 0x0);
 
       if (result) {
           RF_WARNING("=======>%s Set MAC(0xd200) fail, error code=%d\n",
               __func__, result);
           return false;
       } else {
           RF_DBG(rf, DBG_RF_POWER, "Set MAC(0xd200) ok!!!\n");
           rf->is_coex = false;
       }
   } else {
       /*all-time control*/
       result = halrf_mac_set_pwr_reg_8852b(rf, phy, 0xd200, 0xfffffc00, ((tmp_pwr & 0x1ff) | BIT(9)));
       if (result) {
           RF_WARNING("=======>%s Set MAC(0xd200) fail, error code=%d\n",
               __func__, result);
           return false;
       } else {
           RF_DBG(rf, DBG_RF_POWER, "Set MAC(0xd200) ok!!!\n");
           rf->is_coex = true;
       }
   }
 
   if (gnt_bt_control == 0xffff) {
       /*GNT_BT control*/
 
       RF_DBG(rf, DBG_RF_POWER, "=======>%s   gnt_bt_control = 0x%x\n",
           __func__, gnt_bt_control);
 
       result = halrf_mac_set_pwr_reg_8852b(rf, phy, 0xd220, BIT(1), 0x0);
       result = halrf_mac_set_pwr_reg_8852b(rf, phy, 0xd220, 0xfffff007, 0x0);
       if (result) {
           RF_WARNING("=======>%s Set MAC(0xd220) fail, error code=%d\n",
               __func__, result);
           return false;
       } else {
           RF_DBG(rf, DBG_RF_POWER, "Set MAC(0xd220) ok!!!\n");
           rf->is_coex = false;
       }
   } else {
       /*GNT_BT control*/
 
       RF_DBG(rf, DBG_RF_POWER, "=======>%s   gnt_bt_control = 0x%x\n",
           __func__, gnt_bt_control);
 
       result = halrf_mac_set_pwr_reg_8852b(rf, phy, 0xd220, BIT(1), 0x1);
       result = halrf_mac_set_pwr_reg_8852b(rf, phy, 0xd220, 0xfffff007, ((gnt_bt_control & 0x1ff) << 3));
       if (result) {
           RF_WARNING("=======>%s Set MAC(0xd220) fail, error code=%d\n",
               __func__, result);
           return false;
       } else {
           RF_DBG(rf, DBG_RF_POWER, "Set MAC(0xd220) ok!!!\n");
           rf->is_coex = true;
       }
   }
 
   return true;
}
 
s8 halrf_get_ther_protected_threshold_8852b(struct rf_info *rf)
{
   u8 tmp_a, tmp_b, tmp;
 
   tmp_a = halrf_get_thermal(rf, RF_PATH_A);
   tmp_b = halrf_get_thermal(rf, RF_PATH_B);
 
   if (tmp_a > tmp_b)
       tmp = tmp_a;
   else
       tmp = tmp_b;
 
   if (tmp > 0x32)
       return -1;    /*Tx duty reduce*/
   else if (tmp < 0x31)
       return 1;    /*Tx duty up*/
   else 
       return 0;    /*Tx duty the same*/
}
 
s8 halrf_xtal_tracking_offset_8852b(struct rf_info *rf,
                   enum phl_phy_idx phy)
{
   struct halrf_xtal_info *xtal_trk = &rf->xtal_track;
   u8 thermal_a = 0xff, thermal_b = 0xff;
   u8 tmp_a, tmp_b, tmp;
   s8 xtal_ofst = 0;
 
   RF_DBG(rf, DBG_RF_XTAL_TRACK, "======>%s   phy=%d\n",
       __func__, phy);
 
   tmp_a = halrf_get_thermal(rf, RF_PATH_A);
   tmp_b = halrf_get_thermal(rf, RF_PATH_B);
   halrf_efuse_get_info(rf, EFUSE_INFO_RF_THERMAL_A, &thermal_a, 1);
   halrf_efuse_get_info(rf, EFUSE_INFO_RF_THERMAL_B, &thermal_b, 1);
 
   if (thermal_a == 0xff || thermal_b == 0xff ||
       thermal_a == 0x0 || thermal_b == 0x0) {
       RF_DBG(rf, DBG_RF_XTAL_TRACK, "======>%s PG ThermalA=%d ThermalB=%d\n",
           __func__, thermal_a, thermal_b);
       return 0;
   }
 
   if (tmp_a > tmp_b) {
       if (tmp_a > thermal_a) {
           tmp = tmp_a - thermal_a;
           if (tmp > DELTA_SWINGIDX_SIZE)
               tmp = DELTA_SWINGIDX_SIZE - 1;
           xtal_ofst = xtal_trk->delta_swing_xtal_table_idx_p[tmp];
       } else {
           tmp = thermal_a - tmp_a;
           if (tmp > DELTA_SWINGIDX_SIZE)
               tmp = DELTA_SWINGIDX_SIZE - 1;
           xtal_ofst = xtal_trk->delta_swing_xtal_table_idx_n[tmp];
       }
   } else {
       if (tmp_b > thermal_b) {
           tmp = tmp_b - thermal_b;
           if (tmp > DELTA_SWINGIDX_SIZE)
               tmp = DELTA_SWINGIDX_SIZE - 1;
           xtal_ofst = xtal_trk->delta_swing_xtal_table_idx_p[tmp];
       } else {
           tmp = thermal_b - tmp_b;
           if (tmp > DELTA_SWINGIDX_SIZE)
               tmp = DELTA_SWINGIDX_SIZE - 1;
           xtal_ofst = xtal_trk->delta_swing_xtal_table_idx_n[tmp];
       }
   }
 
   RF_DBG(rf, DBG_RF_XTAL_TRACK, "PG ThermalA=%d   ThermalA=%d\n",
       thermal_a, tmp_a);
 
   RF_DBG(rf, DBG_RF_XTAL_TRACK, "PG ThermalB=%d   ThermalB=%d\n",
       thermal_b, tmp_b);
 
   RF_DBG(rf, DBG_RF_XTAL_TRACK, "xtal_ofst[%d]=%d\n",
       tmp, xtal_ofst);
 
   return xtal_ofst;
}
 
#endif