1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
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.
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
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
22 #include <drv_types.h>
25 u8 center_ch_2g[CENTER_CH_2G_NUM] = {
34 u8 center_ch_2g_40m[CENTER_CH_2G_40M_NUM] = {
46 u8 op_chs_of_cch_2g_40m[CENTER_CH_2G_40M_NUM][2] = {
58 u8 center_ch_5g_all[CENTER_CH_5G_ALL_NUM] = {
66 /* G04 */100, 102, 104,
68 /* G05 */108, 110, 112,
70 /* G06 */116, 118, 120,
72 /* G07 */124, 126, 128,
73 /* G08 */132, 134, 136,
75 /* G09 */140, 142, 144,
76 /* G10 */149, 151, 153,
78 /* G11 */157, 159, 161,
80 /* G12 */165, 167, 169,
82 /* G13 */173, 175, 177
85 u8 center_ch_5g_20m[CENTER_CH_5G_20M_NUM] = {
102 u8 center_ch_5g_40m[CENTER_CH_5G_40M_NUM] = {
119 u8 center_ch_5g_20m_40m[CENTER_CH_5G_20M_NUM + CENTER_CH_5G_40M_NUM] = {
124 /* G04 */100, 102, 104,
125 /* G05 */108, 110, 112,
126 /* G06 */116, 118, 120,
127 /* G07 */124, 126, 128,
128 /* G08 */132, 134, 136,
129 /* G09 */140, 142, 144,
130 /* G10 */149, 151, 153,
131 /* G11 */157, 159, 161,
132 /* G12 */165, 167, 169,
133 /* G13 */173, 175, 177
136 u8 op_chs_of_cch_5g_40m[CENTER_CH_5G_40M_NUM][2] = {
141 {100, 104}, /* 102 */
142 {108, 112}, /* 110 */
143 {116, 120}, /* 118 */
144 {124, 128}, /* 126 */
145 {132, 136}, /* 134 */
146 {140, 144}, /* 142 */
147 {149, 153}, /* 151 */
148 {157, 161}, /* 159 */
149 {165, 169}, /* 167 */
150 {173, 177}, /* 175 */
153 u8 center_ch_5g_80m[CENTER_CH_5G_80M_NUM] = {
163 u8 op_chs_of_cch_5g_80m[CENTER_CH_5G_80M_NUM][4] = {
164 {36, 40, 44, 48}, /* 42 */
165 {52, 56, 60, 64}, /* 58 */
166 {100, 104, 108, 112}, /* 106 */
167 {116, 120, 124, 128}, /* 122 */
168 {132, 136, 140, 144}, /* 138 */
169 {149, 153, 157, 161}, /* 155 */
170 {165, 169, 173, 177}, /* 171 */
173 u8 center_ch_5g_160m[CENTER_CH_5G_160M_NUM] = {
179 u8 op_chs_of_cch_5g_160m[CENTER_CH_5G_160M_NUM][8] = {
180 {36, 40, 44, 48, 52, 56, 60, 64}, /* 50 */
181 {100, 104, 108, 112, 116, 120, 124, 128}, /* 114 */
182 {149, 153, 157, 161, 165, 169, 173, 177}, /* 163 */
185 struct center_chs_ent_t {
190 struct center_chs_ent_t center_chs_2g_by_bw[] = {
191 {CENTER_CH_2G_NUM, center_ch_2g},
192 {CENTER_CH_2G_40M_NUM, center_ch_2g_40m},
195 struct center_chs_ent_t center_chs_5g_by_bw[] = {
196 {CENTER_CH_5G_20M_NUM, center_ch_5g_20m},
197 {CENTER_CH_5G_40M_NUM, center_ch_5g_40m},
198 {CENTER_CH_5G_80M_NUM, center_ch_5g_80m},
199 {CENTER_CH_5G_160M_NUM, center_ch_5g_160m},
203 * Get center channel of smaller bandwidth by @param cch, @param bw, @param offset
204 * @cch: the given center channel
205 * @bw: the given bandwidth
206 * @offset: the given primary SC offset of the given bandwidth
208 * return center channel of smaller bandiwdth if valid, or 0
210 u8 rtw_get_scch_by_cch_offset(u8 cch, u8 bw, u8 offset)
215 if (bw == CHANNEL_WIDTH_20) {
220 if (offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE) {
226 if (cch >= 3 && cch <= 11 && bw == CHANNEL_WIDTH_40) {
227 t_cch = (offset == HAL_PRIME_CHNL_OFFSET_UPPER) ? cch + 2 : cch - 2;
232 if (cch >= 50 && cch <= 163 && bw == CHANNEL_WIDTH_160) {
233 t_cch = (offset == HAL_PRIME_CHNL_OFFSET_UPPER) ? cch + 8 : cch - 8;
237 } else if (cch >= 42 && cch <= 171 && bw == CHANNEL_WIDTH_80) {
238 t_cch = (offset == HAL_PRIME_CHNL_OFFSET_UPPER) ? cch + 4 : cch - 4;
242 } else if (cch >= 38 && cch <= 175 && bw == CHANNEL_WIDTH_40) {
243 t_cch = (offset == HAL_PRIME_CHNL_OFFSET_UPPER) ? cch + 2 : cch - 2;
255 struct op_chs_ent_t {
260 struct op_chs_ent_t op_chs_of_cch_2g_by_bw[] = {
262 {2, (u8 *)op_chs_of_cch_2g_40m},
265 struct op_chs_ent_t op_chs_of_cch_5g_by_bw[] = {
266 {1, center_ch_5g_20m},
267 {2, (u8 *)op_chs_of_cch_5g_40m},
268 {4, (u8 *)op_chs_of_cch_5g_80m},
269 {8, (u8 *)op_chs_of_cch_5g_160m},
272 inline u8 center_chs_2g_num(u8 bw)
274 if (bw > CHANNEL_WIDTH_40)
277 return center_chs_2g_by_bw[bw].ch_num;
280 inline u8 center_chs_2g(u8 bw, u8 id)
282 if (bw > CHANNEL_WIDTH_40)
285 if (id >= center_chs_2g_num(bw))
288 return center_chs_2g_by_bw[bw].chs[id];
291 inline u8 center_chs_5g_num(u8 bw)
293 if (bw > CHANNEL_WIDTH_80)
296 return center_chs_5g_by_bw[bw].ch_num;
299 inline u8 center_chs_5g(u8 bw, u8 id)
301 if (bw > CHANNEL_WIDTH_80)
304 if (id >= center_chs_5g_num(bw))
307 return center_chs_5g_by_bw[bw].chs[id];
311 * Get available op channels by @param cch, @param bw
312 * @cch: the given center channel
313 * @bw: the given bandwidth
314 * @op_chs: the pointer to return pointer of op channel array
315 * @op_ch_num: the pointer to return pointer of op channel number
317 * return valid (1) or not (0)
319 u8 rtw_get_op_chs_by_cch_bw(u8 cch, u8 bw, u8 **op_chs, u8 *op_ch_num)
322 struct center_chs_ent_t *c_chs_ent = NULL;
323 struct op_chs_ent_t *op_chs_ent = NULL;
327 && bw >= CHANNEL_WIDTH_20 && bw <= CHANNEL_WIDTH_40
329 c_chs_ent = ¢er_chs_2g_by_bw[bw];
330 op_chs_ent = &op_chs_of_cch_2g_by_bw[bw];
331 } else if (cch >= 36 && cch <= 177
332 && bw >= CHANNEL_WIDTH_20 && bw <= CHANNEL_WIDTH_160
334 c_chs_ent = ¢er_chs_5g_by_bw[bw];
335 op_chs_ent = &op_chs_of_cch_5g_by_bw[bw];
341 for (i = 0; i < c_chs_ent->ch_num; i++)
342 if (cch == *(c_chs_ent->chs + i))
345 if (i == c_chs_ent->ch_num) {
350 *op_chs = op_chs_ent->chs + op_chs_ent->ch_num * i;
351 *op_ch_num = op_chs_ent->ch_num;
357 u8 rtw_get_ch_group(u8 ch, u8 *group, u8 *cck_group)
359 BAND_TYPE band = BAND_MAX;
360 s8 gp = -1, cck_gp = -1;
365 if (1 <= ch && ch <= 2)
367 else if (3 <= ch && ch <= 5)
369 else if (6 <= ch && ch <= 8)
371 else if (9 <= ch && ch <= 11)
373 else if (12 <= ch && ch <= 14)
385 if (36 <= ch && ch <= 42)
387 else if (44 <= ch && ch <= 48)
389 else if (50 <= ch && ch <= 58)
391 else if (60 <= ch && ch <= 64)
393 else if (100 <= ch && ch <= 106)
395 else if (108 <= ch && ch <= 114)
397 else if (116 <= ch && ch <= 122)
399 else if (124 <= ch && ch <= 130)
401 else if (132 <= ch && ch <= 138)
403 else if (140 <= ch && ch <= 144)
405 else if (149 <= ch && ch <= 155)
407 else if (157 <= ch && ch <= 161)
409 else if (165 <= ch && ch <= 171)
411 else if (173 <= ch && ch <= 177)
418 || (band == BAND_ON_2_4G && cck_gp == -1)
421 RTW_WARN("%s invalid channel:%u", __func__, ch);
428 if (cck_group && band == BAND_ON_2_4G)
435 int rtw_ch2freq(int chan)
437 /* see 802.11 17.3.8.3.2 and Annex J
438 * there are overlapping channel numbers in 5GHz and 2GHz bands */
441 * RTK: don't consider the overlapping channel numbers: 5G channel <= 14,
442 * because we don't support it. simply judge from channel number
445 if (chan >= 1 && chan <= 14) {
449 return 2407 + chan * 5;
450 } else if (chan >= 36 && chan <= 177)
451 return 5000 + chan * 5;
453 return 0; /* not supported */
456 int rtw_freq2ch(int freq)
458 /* see 802.11 17.3.8.3.2 and Annex J */
461 else if (freq < 2484)
462 return (freq - 2407) / 5;
463 else if (freq >= 4910 && freq <= 4980)
464 return (freq - 4000) / 5;
465 else if (freq <= 45000) /* DMG band lower limit */
466 return (freq - 5000) / 5;
467 else if (freq >= 58320 && freq <= 64800)
468 return (freq - 56160) / 2160;
473 bool rtw_chbw_to_freq_range(u8 ch, u8 bw, u8 offset, u32 *hi, u32 *lo)
477 u32 hi_ret = 0, lo_ret = 0;
486 c_ch = rtw_get_center_ch(ch, bw, offset);
487 freq = rtw_ch2freq(c_ch);
494 if (bw == CHANNEL_WIDTH_80) {
497 } else if (bw == CHANNEL_WIDTH_40) {
500 } else if (bw == CHANNEL_WIDTH_20) {
517 const char *const _ch_width_str[] = {
526 const u8 _ch_width_to_bw_cap[] = {
535 const char *const _band_str[] = {
542 const u8 _band_to_band_cap[] = {
549 const u8 _rf_type_to_rf_tx_cnt[] = {
561 const u8 _rf_type_to_rf_rx_cnt[] = {
573 #ifdef CONFIG_80211AC_VHT
574 #define COUNTRY_CHPLAN_ASSIGN_EN_11AC(_val) , .en_11ac = (_val)
576 #define COUNTRY_CHPLAN_ASSIGN_EN_11AC(_val)
579 #if RTW_DEF_MODULE_REGULATORY_CERT
580 #define COUNTRY_CHPLAN_ASSIGN_DEF_MODULE_FLAGS(_val) , .def_module_flags = (_val)
582 #define COUNTRY_CHPLAN_ASSIGN_DEF_MODULE_FLAGS(_val)
585 /* has def_module_flags specified, used by common map and HAL dfference map */
586 #define COUNTRY_CHPLAN_ENT(_alpha2, _chplan, _en_11ac, _def_module_flags) \
587 {.alpha2 = (_alpha2), .chplan = (_chplan) \
588 COUNTRY_CHPLAN_ASSIGN_EN_11AC(_en_11ac) \
589 COUNTRY_CHPLAN_ASSIGN_DEF_MODULE_FLAGS(_def_module_flags) \
592 #ifdef CONFIG_CUSTOMIZED_COUNTRY_CHPLAN_MAP
594 #include "../platform/custom_country_chplan.h"
596 #elif RTW_DEF_MODULE_REGULATORY_CERT
598 #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8821AE_HMC_M2)
599 static const struct country_chplan RTL8821AE_HMC_M2_country_chplan_map[] = {
600 COUNTRY_CHPLAN_ENT("CN", 0x51, 1, 0xFB), /* China */
601 COUNTRY_CHPLAN_ENT("RU", 0x59, 0, 0xFB), /* Russia(fac/gost), Kaliningrad */
602 COUNTRY_CHPLAN_ENT("UA", 0x26, 0, 0xFB), /* Ukraine */
604 static const u16 RTL8821AE_HMC_M2_country_chplan_map_sz = sizeof(RTL8821AE_HMC_M2_country_chplan_map) / sizeof(struct country_chplan);
607 #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8821AU)
608 static const struct country_chplan RTL8821AU_country_chplan_map[] = {
609 COUNTRY_CHPLAN_ENT("RU", 0x59, 0, 0xFB), /* Russia(fac/gost), Kaliningrad */
610 COUNTRY_CHPLAN_ENT("UA", 0x26, 0, 0xFB), /* Ukraine */
612 static const u16 RTL8821AU_country_chplan_map_sz = sizeof(RTL8821AU_country_chplan_map) / sizeof(struct country_chplan);
615 #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8812AENF_NGFF)
616 static const struct country_chplan RTL8812AENF_NGFF_country_chplan_map[] = {
618 static const u16 RTL8812AENF_NGFF_country_chplan_map_sz = sizeof(RTL8812AENF_NGFF_country_chplan_map) / sizeof(struct country_chplan);
621 #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8812AEBT_HMC)
622 static const struct country_chplan RTL8812AEBT_HMC_country_chplan_map[] = {
624 static const u16 RTL8812AEBT_HMC_country_chplan_map_sz = sizeof(RTL8812AEBT_HMC_country_chplan_map) / sizeof(struct country_chplan);
627 #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8188EE_HMC_M2)
628 static const struct country_chplan RTL8188EE_HMC_M2_country_chplan_map[] = {
630 static const u16 RTL8188EE_HMC_M2_country_chplan_map_sz = sizeof(RTL8188EE_HMC_M2_country_chplan_map) / sizeof(struct country_chplan);
633 #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8723BE_HMC_M2)
634 static const struct country_chplan RTL8723BE_HMC_M2_country_chplan_map[] = {
636 static const u16 RTL8723BE_HMC_M2_country_chplan_map_sz = sizeof(RTL8723BE_HMC_M2_country_chplan_map) / sizeof(struct country_chplan);
639 #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8723BS_NGFF1216)
640 static const struct country_chplan RTL8723BS_NGFF1216_country_chplan_map[] = {
642 static const u16 RTL8723BS_NGFF1216_country_chplan_map_sz = sizeof(RTL8723BS_NGFF1216_country_chplan_map) / sizeof(struct country_chplan);
645 #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8192EEBT_HMC_M2)
646 static const struct country_chplan RTL8192EEBT_HMC_M2_country_chplan_map[] = {
648 static const u16 RTL8192EEBT_HMC_M2_country_chplan_map_sz = sizeof(RTL8192EEBT_HMC_M2_country_chplan_map) / sizeof(struct country_chplan);
652 * rtw_def_module_get_chplan_from_country -
653 * @country_code: string of country code
655 * Return NULL for case referring to common map
657 static const struct country_chplan *rtw_def_module_get_chplan_from_country(const char *country_code)
659 const struct country_chplan *ent = NULL;
660 const struct country_chplan *hal_map = NULL;
664 /* TODO: runtime selection for multi driver */
665 #if (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8821AE_HMC_M2)
666 hal_map = RTL8821AE_HMC_M2_country_chplan_map;
667 hal_map_sz = RTL8821AE_HMC_M2_country_chplan_map_sz;
668 #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8821AU)
669 hal_map = RTL8821AU_country_chplan_map;
670 hal_map_sz = RTL8821AU_country_chplan_map_sz;
671 #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8812AENF_NGFF)
672 hal_map = RTL8812AENF_NGFF_country_chplan_map;
673 hal_map_sz = RTL8812AENF_NGFF_country_chplan_map_sz;
674 #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8812AEBT_HMC)
675 hal_map = RTL8812AEBT_HMC_country_chplan_map;
676 hal_map_sz = RTL8812AEBT_HMC_country_chplan_map_sz;
677 #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8188EE_HMC_M2)
678 hal_map = RTL8188EE_HMC_M2_country_chplan_map;
679 hal_map_sz = RTL8188EE_HMC_M2_country_chplan_map_sz;
680 #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8723BE_HMC_M2)
681 hal_map = RTL8723BE_HMC_M2_country_chplan_map;
682 hal_map_sz = RTL8723BE_HMC_M2_country_chplan_map_sz;
683 #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8723BS_NGFF1216)
684 hal_map = RTL8723BS_NGFF1216_country_chplan_map;
685 hal_map_sz = RTL8723BS_NGFF1216_country_chplan_map_sz;
686 #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8192EEBT_HMC_M2)
687 hal_map = RTL8192EEBT_HMC_M2_country_chplan_map;
688 hal_map_sz = RTL8192EEBT_HMC_M2_country_chplan_map_sz;
691 if (hal_map == NULL || hal_map_sz == 0)
694 for (i = 0; i < hal_map_sz; i++) {
695 if (strncmp(country_code, hal_map[i].alpha2, 2) == 0) {
704 #endif /* CONFIG_CUSTOMIZED_COUNTRY_CHPLAN_MAP or RTW_DEF_MODULE_REGULATORY_CERT */
706 static const struct country_chplan country_chplan_map[] = {
707 COUNTRY_CHPLAN_ENT("AD", 0x26, 1, 0x00), /* Andorra */
708 COUNTRY_CHPLAN_ENT("AE", 0x26, 1, 0xFB), /* United Arab Emirates */
709 COUNTRY_CHPLAN_ENT("AF", 0x42, 1, 0x00), /* Afghanistan */
710 COUNTRY_CHPLAN_ENT("AG", 0x30, 1, 0x00), /* Antigua & Barbuda */
711 COUNTRY_CHPLAN_ENT("AI", 0x26, 1, 0x00), /* Anguilla(UK) */
712 COUNTRY_CHPLAN_ENT("AL", 0x26, 1, 0xF1), /* Albania */
713 COUNTRY_CHPLAN_ENT("AM", 0x26, 1, 0xB0), /* Armenia */
714 COUNTRY_CHPLAN_ENT("AO", 0x26, 1, 0xE0), /* Angola */
715 COUNTRY_CHPLAN_ENT("AQ", 0x26, 1, 0x00), /* Antarctica */
716 COUNTRY_CHPLAN_ENT("AR", 0x57, 1, 0xF3), /* Argentina */
717 COUNTRY_CHPLAN_ENT("AS", 0x34, 1, 0x00), /* American Samoa */
718 COUNTRY_CHPLAN_ENT("AT", 0x26, 1, 0xFB), /* Austria */
719 COUNTRY_CHPLAN_ENT("AU", 0x45, 1, 0xFB), /* Australia */
720 COUNTRY_CHPLAN_ENT("AW", 0x34, 1, 0xB0), /* Aruba */
721 COUNTRY_CHPLAN_ENT("AZ", 0x26, 1, 0xF1), /* Azerbaijan */
722 COUNTRY_CHPLAN_ENT("BA", 0x26, 1, 0xF1), /* Bosnia & Herzegovina */
723 COUNTRY_CHPLAN_ENT("BB", 0x34, 1, 0x50), /* Barbados */
724 COUNTRY_CHPLAN_ENT("BD", 0x26, 1, 0xF1), /* Bangladesh */
725 COUNTRY_CHPLAN_ENT("BE", 0x26, 1, 0xFB), /* Belgium */
726 COUNTRY_CHPLAN_ENT("BF", 0x26, 1, 0xB0), /* Burkina Faso */
727 COUNTRY_CHPLAN_ENT("BG", 0x26, 1, 0xF1), /* Bulgaria */
728 COUNTRY_CHPLAN_ENT("BH", 0x47, 1, 0xF1), /* Bahrain */
729 COUNTRY_CHPLAN_ENT("BI", 0x26, 1, 0xB0), /* Burundi */
730 COUNTRY_CHPLAN_ENT("BJ", 0x26, 1, 0xB0), /* Benin */
731 COUNTRY_CHPLAN_ENT("BN", 0x47, 1, 0x10), /* Brunei */
732 COUNTRY_CHPLAN_ENT("BO", 0x30, 1, 0xF1), /* Bolivia */
733 COUNTRY_CHPLAN_ENT("BR", 0x34, 1, 0xF1), /* Brazil */
734 COUNTRY_CHPLAN_ENT("BS", 0x34, 1, 0x20), /* Bahamas */
735 COUNTRY_CHPLAN_ENT("BW", 0x26, 1, 0xF1), /* Botswana */
736 COUNTRY_CHPLAN_ENT("BY", 0x26, 1, 0xF1), /* Belarus */
737 COUNTRY_CHPLAN_ENT("BZ", 0x34, 1, 0x00), /* Belize */
738 COUNTRY_CHPLAN_ENT("CA", 0x34, 1, 0xFB), /* Canada */
739 COUNTRY_CHPLAN_ENT("CC", 0x26, 1, 0x00), /* Cocos (Keeling) Islands (Australia) */
740 COUNTRY_CHPLAN_ENT("CD", 0x26, 1, 0xB0), /* Congo, Republic of the */
741 COUNTRY_CHPLAN_ENT("CF", 0x26, 1, 0xB0), /* Central African Republic */
742 COUNTRY_CHPLAN_ENT("CG", 0x26, 1, 0xB0), /* Congo, Democratic Republic of the. Zaire */
743 COUNTRY_CHPLAN_ENT("CH", 0x26, 1, 0xFB), /* Switzerland */
744 COUNTRY_CHPLAN_ENT("CI", 0x26, 1, 0xF1), /* Cote d'Ivoire */
745 COUNTRY_CHPLAN_ENT("CK", 0x26, 1, 0x00), /* Cook Islands */
746 COUNTRY_CHPLAN_ENT("CL", 0x30, 1, 0xF1), /* Chile */
747 COUNTRY_CHPLAN_ENT("CM", 0x26, 1, 0xB0), /* Cameroon */
748 COUNTRY_CHPLAN_ENT("CN", 0x48, 1, 0xFB), /* China */
749 COUNTRY_CHPLAN_ENT("CO", 0x34, 1, 0xF1), /* Colombia */
750 COUNTRY_CHPLAN_ENT("CR", 0x34, 1, 0xF1), /* Costa Rica */
751 COUNTRY_CHPLAN_ENT("CV", 0x26, 1, 0xB0), /* Cape Verde */
752 COUNTRY_CHPLAN_ENT("CX", 0x45, 1, 0x00), /* Christmas Island (Australia) */
753 COUNTRY_CHPLAN_ENT("CY", 0x26, 1, 0xFB), /* Cyprus */
754 COUNTRY_CHPLAN_ENT("CZ", 0x26, 1, 0xFB), /* Czech Republic */
755 COUNTRY_CHPLAN_ENT("DE", 0x26, 1, 0xFB), /* Germany */
756 COUNTRY_CHPLAN_ENT("DJ", 0x26, 1, 0x80), /* Djibouti */
757 COUNTRY_CHPLAN_ENT("DK", 0x26, 1, 0xFB), /* Denmark */
758 COUNTRY_CHPLAN_ENT("DM", 0x34, 1, 0x00), /* Dominica */
759 COUNTRY_CHPLAN_ENT("DO", 0x34, 1, 0xF1), /* Dominican Republic */
760 COUNTRY_CHPLAN_ENT("DZ", 0x26, 1, 0xF1), /* Algeria */
761 COUNTRY_CHPLAN_ENT("EC", 0x34, 1, 0xF1), /* Ecuador */
762 COUNTRY_CHPLAN_ENT("EE", 0x26, 1, 0xFB), /* Estonia */
763 COUNTRY_CHPLAN_ENT("EG", 0x47, 0, 0xF1), /* Egypt */
764 COUNTRY_CHPLAN_ENT("EH", 0x47, 1, 0x80), /* Western Sahara */
765 COUNTRY_CHPLAN_ENT("ER", 0x26, 1, 0x00), /* Eritrea */
766 COUNTRY_CHPLAN_ENT("ES", 0x26, 1, 0xFB), /* Spain, Canary Islands, Ceuta, Melilla */
767 COUNTRY_CHPLAN_ENT("ET", 0x26, 1, 0xB0), /* Ethiopia */
768 COUNTRY_CHPLAN_ENT("FI", 0x26, 1, 0xFB), /* Finland */
769 COUNTRY_CHPLAN_ENT("FJ", 0x34, 1, 0x00), /* Fiji */
770 COUNTRY_CHPLAN_ENT("FK", 0x26, 1, 0x00), /* Falkland Islands (Islas Malvinas) (UK) */
771 COUNTRY_CHPLAN_ENT("FM", 0x34, 1, 0x00), /* Micronesia, Federated States of (USA) */
772 COUNTRY_CHPLAN_ENT("FO", 0x26, 1, 0x00), /* Faroe Islands (Denmark) */
773 COUNTRY_CHPLAN_ENT("FR", 0x26, 1, 0xFB), /* France */
774 COUNTRY_CHPLAN_ENT("GA", 0x26, 1, 0xB0), /* Gabon */
775 COUNTRY_CHPLAN_ENT("GB", 0x26, 1, 0xFB), /* Great Britain (United Kingdom; England) */
776 COUNTRY_CHPLAN_ENT("GD", 0x34, 1, 0xB0), /* Grenada */
777 COUNTRY_CHPLAN_ENT("GE", 0x26, 1, 0x00), /* Georgia */
778 COUNTRY_CHPLAN_ENT("GF", 0x26, 1, 0x80), /* French Guiana */
779 COUNTRY_CHPLAN_ENT("GG", 0x26, 1, 0x00), /* Guernsey (UK) */
780 COUNTRY_CHPLAN_ENT("GH", 0x26, 1, 0xF1), /* Ghana */
781 COUNTRY_CHPLAN_ENT("GI", 0x26, 1, 0x00), /* Gibraltar (UK) */
782 COUNTRY_CHPLAN_ENT("GL", 0x26, 1, 0x00), /* Greenland (Denmark) */
783 COUNTRY_CHPLAN_ENT("GM", 0x26, 1, 0xB0), /* Gambia */
784 COUNTRY_CHPLAN_ENT("GN", 0x26, 1, 0x10), /* Guinea */
785 COUNTRY_CHPLAN_ENT("GP", 0x26, 1, 0x00), /* Guadeloupe (France) */
786 COUNTRY_CHPLAN_ENT("GQ", 0x26, 1, 0xB0), /* Equatorial Guinea */
787 COUNTRY_CHPLAN_ENT("GR", 0x26, 1, 0xFB), /* Greece */
788 COUNTRY_CHPLAN_ENT("GS", 0x26, 1, 0x00), /* South Georgia and the Sandwich Islands (UK) */
789 COUNTRY_CHPLAN_ENT("GT", 0x34, 1, 0xF1), /* Guatemala */
790 COUNTRY_CHPLAN_ENT("GU", 0x34, 1, 0x00), /* Guam (USA) */
791 COUNTRY_CHPLAN_ENT("GW", 0x26, 1, 0xB0), /* Guinea-Bissau */
792 COUNTRY_CHPLAN_ENT("GY", 0x44, 1, 0x00), /* Guyana */
793 COUNTRY_CHPLAN_ENT("HK", 0x26, 1, 0xFB), /* Hong Kong */
794 COUNTRY_CHPLAN_ENT("HM", 0x45, 1, 0x00), /* Heard and McDonald Islands (Australia) */
795 COUNTRY_CHPLAN_ENT("HN", 0x32, 1, 0xF1), /* Honduras */
796 COUNTRY_CHPLAN_ENT("HR", 0x26, 1, 0xF9), /* Croatia */
797 COUNTRY_CHPLAN_ENT("HT", 0x34, 1, 0x50), /* Haiti */
798 COUNTRY_CHPLAN_ENT("HU", 0x26, 1, 0xFB), /* Hungary */
799 COUNTRY_CHPLAN_ENT("ID", 0x54, 0, 0xF3), /* Indonesia */
800 COUNTRY_CHPLAN_ENT("IE", 0x26, 1, 0xFB), /* Ireland */
801 COUNTRY_CHPLAN_ENT("IL", 0x47, 1, 0xF1), /* Israel */
802 COUNTRY_CHPLAN_ENT("IM", 0x26, 1, 0x00), /* Isle of Man (UK) */
803 COUNTRY_CHPLAN_ENT("IN", 0x47, 1, 0xF1), /* India */
804 COUNTRY_CHPLAN_ENT("IQ", 0x26, 1, 0x00), /* Iraq */
805 COUNTRY_CHPLAN_ENT("IR", 0x26, 0, 0x00), /* Iran */
806 COUNTRY_CHPLAN_ENT("IS", 0x26, 1, 0xFB), /* Iceland */
807 COUNTRY_CHPLAN_ENT("IT", 0x26, 1, 0xFB), /* Italy */
808 COUNTRY_CHPLAN_ENT("JE", 0x26, 1, 0x00), /* Jersey (UK) */
809 COUNTRY_CHPLAN_ENT("JM", 0x51, 1, 0xF1), /* Jamaica */
810 COUNTRY_CHPLAN_ENT("JO", 0x49, 1, 0xFB), /* Jordan */
811 COUNTRY_CHPLAN_ENT("JP", 0x27, 1, 0xFF), /* Japan- Telec */
812 COUNTRY_CHPLAN_ENT("KE", 0x47, 1, 0xF9), /* Kenya */
813 COUNTRY_CHPLAN_ENT("KG", 0x26, 1, 0xF1), /* Kyrgyzstan */
814 COUNTRY_CHPLAN_ENT("KH", 0x26, 1, 0xF1), /* Cambodia */
815 COUNTRY_CHPLAN_ENT("KI", 0x26, 1, 0x00), /* Kiribati */
816 COUNTRY_CHPLAN_ENT("KN", 0x34, 1, 0x00), /* Saint Kitts and Nevis */
817 COUNTRY_CHPLAN_ENT("KR", 0x28, 1, 0xFB), /* South Korea */
818 COUNTRY_CHPLAN_ENT("KW", 0x47, 1, 0xFB), /* Kuwait */
819 COUNTRY_CHPLAN_ENT("KY", 0x34, 1, 0x00), /* Cayman Islands (UK) */
820 COUNTRY_CHPLAN_ENT("KZ", 0x26, 1, 0x00), /* Kazakhstan */
821 COUNTRY_CHPLAN_ENT("LA", 0x26, 1, 0x00), /* Laos */
822 COUNTRY_CHPLAN_ENT("LB", 0x26, 1, 0xF1), /* Lebanon */
823 COUNTRY_CHPLAN_ENT("LC", 0x34, 1, 0x00), /* Saint Lucia */
824 COUNTRY_CHPLAN_ENT("LI", 0x26, 1, 0xFB), /* Liechtenstein */
825 COUNTRY_CHPLAN_ENT("LK", 0x26, 1, 0xF1), /* Sri Lanka */
826 COUNTRY_CHPLAN_ENT("LR", 0x26, 1, 0xB0), /* Liberia */
827 COUNTRY_CHPLAN_ENT("LS", 0x26, 1, 0xF1), /* Lesotho */
828 COUNTRY_CHPLAN_ENT("LT", 0x26, 1, 0xFB), /* Lithuania */
829 COUNTRY_CHPLAN_ENT("LU", 0x26, 1, 0xFB), /* Luxembourg */
830 COUNTRY_CHPLAN_ENT("LV", 0x26, 1, 0xFB), /* Latvia */
831 COUNTRY_CHPLAN_ENT("LY", 0x26, 1, 0x00), /* Libya */
832 COUNTRY_CHPLAN_ENT("MA", 0x47, 1, 0xF1), /* Morocco */
833 COUNTRY_CHPLAN_ENT("MC", 0x26, 1, 0xFB), /* Monaco */
834 COUNTRY_CHPLAN_ENT("MD", 0x26, 1, 0xF1), /* Moldova */
835 COUNTRY_CHPLAN_ENT("ME", 0x26, 1, 0xF1), /* Montenegro */
836 COUNTRY_CHPLAN_ENT("MF", 0x34, 1, 0x00), /* Saint Martin */
837 COUNTRY_CHPLAN_ENT("MG", 0x26, 1, 0x20), /* Madagascar */
838 COUNTRY_CHPLAN_ENT("MH", 0x34, 1, 0x00), /* Marshall Islands (USA) */
839 COUNTRY_CHPLAN_ENT("MK", 0x26, 1, 0xF1), /* Republic of Macedonia (FYROM) */
840 COUNTRY_CHPLAN_ENT("ML", 0x26, 1, 0xB0), /* Mali */
841 COUNTRY_CHPLAN_ENT("MM", 0x26, 1, 0x00), /* Burma (Myanmar) */
842 COUNTRY_CHPLAN_ENT("MN", 0x26, 1, 0x00), /* Mongolia */
843 COUNTRY_CHPLAN_ENT("MO", 0x26, 1, 0x00), /* Macau */
844 COUNTRY_CHPLAN_ENT("MP", 0x34, 1, 0x00), /* Northern Mariana Islands (USA) */
845 COUNTRY_CHPLAN_ENT("MQ", 0x26, 1, 0x40), /* Martinique (France) */
846 COUNTRY_CHPLAN_ENT("MR", 0x26, 1, 0xA0), /* Mauritania */
847 COUNTRY_CHPLAN_ENT("MS", 0x26, 1, 0x00), /* Montserrat (UK) */
848 COUNTRY_CHPLAN_ENT("MT", 0x26, 1, 0xFB), /* Malta */
849 COUNTRY_CHPLAN_ENT("MU", 0x26, 1, 0xB0), /* Mauritius */
850 COUNTRY_CHPLAN_ENT("MV", 0x26, 1, 0x00), /* Maldives */
851 COUNTRY_CHPLAN_ENT("MW", 0x26, 1, 0xB0), /* Malawi */
852 COUNTRY_CHPLAN_ENT("MX", 0x34, 1, 0xF1), /* Mexico */
853 COUNTRY_CHPLAN_ENT("MY", 0x47, 1, 0xF1), /* Malaysia */
854 COUNTRY_CHPLAN_ENT("MZ", 0x26, 1, 0xF1), /* Mozambique */
855 COUNTRY_CHPLAN_ENT("NA", 0x26, 0, 0x00), /* Namibia */
856 COUNTRY_CHPLAN_ENT("NC", 0x26, 1, 0x00), /* New Caledonia */
857 COUNTRY_CHPLAN_ENT("NE", 0x26, 1, 0xB0), /* Niger */
858 COUNTRY_CHPLAN_ENT("NF", 0x45, 1, 0x00), /* Norfolk Island (Australia) */
859 COUNTRY_CHPLAN_ENT("NG", 0x50, 1, 0xF9), /* Nigeria */
860 COUNTRY_CHPLAN_ENT("NI", 0x34, 1, 0xF1), /* Nicaragua */
861 COUNTRY_CHPLAN_ENT("NL", 0x26, 1, 0xFB), /* Netherlands */
862 COUNTRY_CHPLAN_ENT("NO", 0x26, 1, 0xFB), /* Norway */
863 COUNTRY_CHPLAN_ENT("NP", 0x47, 1, 0xF0), /* Nepal */
864 COUNTRY_CHPLAN_ENT("NR", 0x26, 1, 0x00), /* Nauru */
865 COUNTRY_CHPLAN_ENT("NU", 0x45, 1, 0x00), /* Niue */
866 COUNTRY_CHPLAN_ENT("NZ", 0x45, 1, 0xFB), /* New Zealand */
867 COUNTRY_CHPLAN_ENT("OM", 0x26, 1, 0xF9), /* Oman */
868 COUNTRY_CHPLAN_ENT("PA", 0x34, 1, 0xF1), /* Panama */
869 COUNTRY_CHPLAN_ENT("PE", 0x34, 1, 0xF1), /* Peru */
870 COUNTRY_CHPLAN_ENT("PF", 0x26, 1, 0x00), /* French Polynesia (France) */
871 COUNTRY_CHPLAN_ENT("PG", 0x26, 1, 0xF1), /* Papua New Guinea */
872 COUNTRY_CHPLAN_ENT("PH", 0x26, 1, 0xF1), /* Philippines */
873 COUNTRY_CHPLAN_ENT("PK", 0x51, 1, 0xF1), /* Pakistan */
874 COUNTRY_CHPLAN_ENT("PL", 0x26, 1, 0xFB), /* Poland */
875 COUNTRY_CHPLAN_ENT("PM", 0x26, 1, 0x00), /* Saint Pierre and Miquelon (France) */
876 COUNTRY_CHPLAN_ENT("PR", 0x34, 1, 0xF1), /* Puerto Rico */
877 COUNTRY_CHPLAN_ENT("PT", 0x26, 1, 0xFB), /* Portugal */
878 COUNTRY_CHPLAN_ENT("PW", 0x34, 1, 0x00), /* Palau */
879 COUNTRY_CHPLAN_ENT("PY", 0x34, 1, 0xF1), /* Paraguay */
880 COUNTRY_CHPLAN_ENT("QA", 0x51, 1, 0xF9), /* Qatar */
881 COUNTRY_CHPLAN_ENT("RE", 0x26, 1, 0x00), /* Reunion (France) */
882 COUNTRY_CHPLAN_ENT("RO", 0x26, 1, 0xF1), /* Romania */
883 COUNTRY_CHPLAN_ENT("RS", 0x26, 1, 0xF1), /* Serbia, Kosovo */
884 COUNTRY_CHPLAN_ENT("RU", 0x59, 1, 0xFB), /* Russia(fac/gost), Kaliningrad */
885 COUNTRY_CHPLAN_ENT("RW", 0x26, 1, 0xB0), /* Rwanda */
886 COUNTRY_CHPLAN_ENT("SA", 0x26, 1, 0xFB), /* Saudi Arabia */
887 COUNTRY_CHPLAN_ENT("SB", 0x26, 1, 0x00), /* Solomon Islands */
888 COUNTRY_CHPLAN_ENT("SC", 0x34, 1, 0x90), /* Seychelles */
889 COUNTRY_CHPLAN_ENT("SE", 0x26, 1, 0xFB), /* Sweden */
890 COUNTRY_CHPLAN_ENT("SG", 0x47, 1, 0xFB), /* Singapore */
891 COUNTRY_CHPLAN_ENT("SH", 0x26, 1, 0x00), /* Saint Helena (UK) */
892 COUNTRY_CHPLAN_ENT("SI", 0x26, 1, 0xFB), /* Slovenia */
893 COUNTRY_CHPLAN_ENT("SJ", 0x26, 1, 0x00), /* Svalbard (Norway) */
894 COUNTRY_CHPLAN_ENT("SK", 0x26, 1, 0xFB), /* Slovakia */
895 COUNTRY_CHPLAN_ENT("SL", 0x26, 1, 0xB0), /* Sierra Leone */
896 COUNTRY_CHPLAN_ENT("SM", 0x26, 1, 0x00), /* San Marino */
897 COUNTRY_CHPLAN_ENT("SN", 0x26, 1, 0xF1), /* Senegal */
898 COUNTRY_CHPLAN_ENT("SO", 0x26, 1, 0x00), /* Somalia */
899 COUNTRY_CHPLAN_ENT("SR", 0x34, 1, 0x00), /* Suriname */
900 COUNTRY_CHPLAN_ENT("ST", 0x34, 1, 0x80), /* Sao Tome and Principe */
901 COUNTRY_CHPLAN_ENT("SV", 0x30, 1, 0xF1), /* El Salvador */
902 COUNTRY_CHPLAN_ENT("SX", 0x34, 1, 0x00), /* Sint Marteen */
903 COUNTRY_CHPLAN_ENT("SZ", 0x26, 1, 0x20), /* Swaziland */
904 COUNTRY_CHPLAN_ENT("TC", 0x26, 1, 0x00), /* Turks and Caicos Islands (UK) */
905 COUNTRY_CHPLAN_ENT("TD", 0x26, 1, 0xB0), /* Chad */
906 COUNTRY_CHPLAN_ENT("TF", 0x26, 1, 0x80), /* French Southern and Antarctic Lands (FR Southern Territories) */
907 COUNTRY_CHPLAN_ENT("TG", 0x26, 1, 0xB0), /* Togo */
908 COUNTRY_CHPLAN_ENT("TH", 0x26, 1, 0xF1), /* Thailand */
909 COUNTRY_CHPLAN_ENT("TJ", 0x26, 1, 0x40), /* Tajikistan */
910 COUNTRY_CHPLAN_ENT("TK", 0x45, 1, 0x00), /* Tokelau */
911 COUNTRY_CHPLAN_ENT("TM", 0x26, 1, 0x00), /* Turkmenistan */
912 COUNTRY_CHPLAN_ENT("TN", 0x47, 1, 0xF1), /* Tunisia */
913 COUNTRY_CHPLAN_ENT("TO", 0x26, 1, 0x00), /* Tonga */
914 COUNTRY_CHPLAN_ENT("TR", 0x26, 1, 0xF1), /* Turkey, Northern Cyprus */
915 COUNTRY_CHPLAN_ENT("TT", 0x42, 1, 0xF1), /* Trinidad & Tobago */
916 COUNTRY_CHPLAN_ENT("TW", 0x39, 1, 0xFF), /* Taiwan */
917 COUNTRY_CHPLAN_ENT("TZ", 0x26, 1, 0xF0), /* Tanzania */
918 COUNTRY_CHPLAN_ENT("UA", 0x26, 1, 0xFB), /* Ukraine */
919 COUNTRY_CHPLAN_ENT("UG", 0x26, 1, 0xF1), /* Uganda */
920 COUNTRY_CHPLAN_ENT("US", 0x34, 1, 0xFF), /* United States of America (USA) */
921 COUNTRY_CHPLAN_ENT("UY", 0x34, 1, 0xF1), /* Uruguay */
922 COUNTRY_CHPLAN_ENT("UZ", 0x47, 1, 0xF0), /* Uzbekistan */
923 COUNTRY_CHPLAN_ENT("VA", 0x26, 1, 0x00), /* Holy See (Vatican City) */
924 COUNTRY_CHPLAN_ENT("VC", 0x34, 1, 0x10), /* Saint Vincent and the Grenadines */
925 COUNTRY_CHPLAN_ENT("VE", 0x30, 1, 0xF1), /* Venezuela */
926 COUNTRY_CHPLAN_ENT("VI", 0x34, 1, 0x00), /* United States Virgin Islands (USA) */
927 COUNTRY_CHPLAN_ENT("VN", 0x26, 1, 0xF1), /* Vietnam */
928 COUNTRY_CHPLAN_ENT("VU", 0x26, 1, 0x00), /* Vanuatu */
929 COUNTRY_CHPLAN_ENT("WF", 0x26, 1, 0x00), /* Wallis and Futuna (France) */
930 COUNTRY_CHPLAN_ENT("WS", 0x34, 1, 0x00), /* Samoa */
931 COUNTRY_CHPLAN_ENT("YE", 0x26, 1, 0x40), /* Yemen */
932 COUNTRY_CHPLAN_ENT("YT", 0x26, 1, 0x80), /* Mayotte (France) */
933 COUNTRY_CHPLAN_ENT("ZA", 0x26, 1, 0xF1), /* South Africa */
934 COUNTRY_CHPLAN_ENT("ZM", 0x26, 1, 0xB0), /* Zambia */
935 COUNTRY_CHPLAN_ENT("ZW", 0x26, 1, 0xF1), /* Zimbabwe */
938 u16 const country_chplan_map_sz = sizeof(country_chplan_map) / sizeof(struct country_chplan);
941 * rtw_get_chplan_from_country -
942 * @country_code: string of country code
944 * Return pointer of struct country_chplan entry or NULL when unsupported country_code is given
946 const struct country_chplan *rtw_get_chplan_from_country(const char *country_code)
948 const struct country_chplan *ent = NULL;
949 const struct country_chplan *map = NULL;
954 code[0] = alpha_to_upper(country_code[0]);
955 code[1] = alpha_to_upper(country_code[1]);
957 #if !defined(CONFIG_CUSTOMIZED_COUNTRY_CHPLAN_MAP) && RTW_DEF_MODULE_REGULATORY_CERT
958 ent = rtw_def_module_get_chplan_from_country(code);
963 #ifdef CONFIG_CUSTOMIZED_COUNTRY_CHPLAN_MAP
964 map = CUSTOMIZED_country_chplan_map;
965 map_sz = CUSTOMIZED_country_chplan_map_sz;
967 map = country_chplan_map;
968 map_sz = country_chplan_map_sz;
971 for (i = 0; i < map_sz; i++) {
972 if (strncmp(code, map[i].alpha2, 2) == 0) {
979 #if RTW_DEF_MODULE_REGULATORY_CERT
980 if (ent && !(COUNTRY_CHPLAN_DEF_MODULE_FALGS(ent) & RTW_DEF_MODULE_REGULATORY_CERT))
987 int rtw_ch_to_bb_gain_sel(int ch)
991 if (ch >= 1 && ch <= 14)
993 #ifdef CONFIG_IEEE80211_BAND_5GHZ
994 else if (ch >= 36 && ch < 48)
996 else if (ch >= 52 && ch <= 64)
998 else if (ch >= 100 && ch <= 120)
1000 else if (ch >= 124 && ch <= 144)
1001 sel = BB_GAIN_5GMB2;
1002 else if (ch >= 149 && ch <= 177)
1009 s8 rtw_rf_get_kfree_tx_gain_offset(_adapter *padapter, u8 path, u8 ch)
1011 s8 kfree_offset = 0;
1013 #ifdef CONFIG_RF_POWER_TRIM
1014 HAL_DATA_TYPE *hal_data = GET_HAL_DATA(padapter);
1015 struct kfree_data_t *kfree_data = GET_KFREE_DATA(padapter);
1016 s8 bb_gain_sel = rtw_ch_to_bb_gain_sel(ch);
1018 if (bb_gain_sel < BB_GAIN_2G || bb_gain_sel >= BB_GAIN_NUM) {
1023 if (kfree_data->flag & KFREE_FLAG_ON) {
1024 kfree_offset = kfree_data->bb_gain[bb_gain_sel][path];
1025 if (IS_HARDWARE_TYPE_8723D(padapter))
1026 RTW_INFO("%s path:%s, ch:%u, bb_gain_sel:%d, kfree_offset:%d\n"
1027 , __func__, (path == 0)?"S1":"S0",
1028 ch, bb_gain_sel, kfree_offset);
1030 RTW_INFO("%s path:%u, ch:%u, bb_gain_sel:%d, kfree_offset:%d\n"
1031 , __func__, path, ch, bb_gain_sel, kfree_offset);
1034 #endif /* CONFIG_RF_POWER_TRIM */
1035 return kfree_offset;
1038 void rtw_rf_set_tx_gain_offset(_adapter *adapter, u8 path, s8 offset)
1044 if (IS_HARDWARE_TYPE_8723D(adapter)) {
1045 target_path = RF_PATH_A; /*in 8723D case path means S0/S1*/
1046 if (path == PPG_8723D_S1)
1047 RTW_INFO("kfree gain_offset 0x55:0x%x ",
1048 rtw_hal_read_rfreg(adapter, target_path, 0x55, 0xffffffff));
1049 else if (path == PPG_8723D_S0)
1050 RTW_INFO("kfree gain_offset 0x65:0x%x ",
1051 rtw_hal_read_rfreg(adapter, target_path, 0x65, 0xffffffff));
1054 RTW_INFO("kfree gain_offset 0x55:0x%x ", rtw_hal_read_rfreg(adapter, target_path, 0x55, 0xffffffff));
1057 switch (rtw_get_chip_type(adapter)) {
1058 #ifdef CONFIG_RTL8723D
1060 write_value = RF_TX_GAIN_OFFSET_8723D(offset);
1061 if (path == PPG_8723D_S1)
1062 rtw_hal_write_rfreg(adapter, target_path, 0x55, 0x0f8000, write_value);
1063 else if (path == PPG_8723D_S0)
1064 rtw_hal_write_rfreg(adapter, target_path, 0x65, 0x0f8000, write_value);
1066 #endif /* CONFIG_RTL8723D */
1067 #ifdef CONFIG_RTL8703B
1069 write_value = RF_TX_GAIN_OFFSET_8703B(offset);
1070 rtw_hal_write_rfreg(adapter, target_path, 0x55, 0x0fc000, write_value);
1072 #endif /* CONFIG_RTL8703B */
1073 #ifdef CONFIG_RTL8188F
1075 write_value = RF_TX_GAIN_OFFSET_8188F(offset);
1076 rtw_hal_write_rfreg(adapter, target_path, 0x55, 0x0fc000, write_value);
1078 #endif /* CONFIG_RTL8188F */
1079 #ifdef CONFIG_RTL8192E
1081 write_value = RF_TX_GAIN_OFFSET_8192E(offset);
1082 rtw_hal_write_rfreg(adapter, target_path, 0x55, 0x0f8000, write_value);
1084 #endif /* CONFIG_RTL8188F */
1086 #ifdef CONFIG_RTL8821A
1088 write_value = RF_TX_GAIN_OFFSET_8821A(offset);
1089 rtw_hal_write_rfreg(adapter, target_path, 0x55, 0x0f8000, write_value);
1091 #endif /* CONFIG_RTL8821A */
1092 #if defined(CONFIG_RTL8814A) || defined(CONFIG_RTL8822B) || defined(CONFIG_RTL8821C)
1096 RTW_INFO("\nkfree by PhyDM on the sw CH. path %d\n", path);
1098 #endif /* CONFIG_RTL8814A || CONFIG_RTL8822B || CONFIG_RTL8821C */
1105 if (IS_HARDWARE_TYPE_8723D(adapter)) {
1106 if (path == PPG_8723D_S1)
1107 val32 = rtw_hal_read_rfreg(adapter, target_path, 0x55, 0xffffffff);
1108 else if (path == PPG_8723D_S0)
1109 val32 = rtw_hal_read_rfreg(adapter, target_path, 0x65, 0xffffffff);
1111 val32 = rtw_hal_read_rfreg(adapter, target_path, 0x55, 0xffffffff);
1113 RTW_INFO(" after :0x%x\n", val32);
1116 void rtw_rf_apply_tx_gain_offset(_adapter *adapter, u8 ch)
1118 HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
1119 s8 kfree_offset = 0;
1120 s8 tx_pwr_track_offset = 0; /* TODO: 8814A should consider tx pwr track when setting tx gain offset */
1124 if (IS_HARDWARE_TYPE_8723D(adapter))
1125 total = 2; /* S1 and S0 */
1127 total = hal_data->NumTotalRFPath;
1129 for (i = 0; i < total; i++) {
1130 kfree_offset = rtw_rf_get_kfree_tx_gain_offset(adapter, i, ch);
1131 total_offset = kfree_offset + tx_pwr_track_offset;
1132 rtw_rf_set_tx_gain_offset(adapter, i, total_offset);
1136 bool rtw_is_dfs_range(u32 hi, u32 lo)
1138 return rtw_is_range_overlap(hi, lo, 5720 + 10, 5260 - 10) ? _TRUE : _FALSE;
1141 bool rtw_is_dfs_ch(u8 ch, u8 bw, u8 offset)
1145 if (rtw_chbw_to_freq_range(ch, bw, offset, &hi, &lo) == _FALSE)
1148 return rtw_is_dfs_range(hi, lo) ? _TRUE : _FALSE;
1151 bool rtw_is_long_cac_range(u32 hi, u32 lo, u8 dfs_region)
1153 return (dfs_region == PHYDM_DFS_DOMAIN_ETSI && rtw_is_range_overlap(hi, lo, 5660 + 10, 5600 - 10)) ? _TRUE : _FALSE;
1156 bool rtw_is_long_cac_ch(u8 ch, u8 bw, u8 offset, u8 dfs_region)
1160 if (rtw_chbw_to_freq_range(ch, bw, offset, &hi, &lo) == _FALSE)
1163 return rtw_is_long_cac_range(hi, lo, dfs_region) ? _TRUE : _FALSE;