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 ******************************************************************************/
21 #include <osdep_service.h>
22 #include <drv_types.h>
23 #include <rtw_byteorder.h>
28 #ifdef CONFIG_RTL8192C
29 #include <rtl8192c_hal.h>
31 #ifdef CONFIG_RTL8192D
32 #include <rtl8192d_hal.h>
37 //============================================================
39 //============================================================
40 u32 OFDMSwingTable
[OFDM_TABLE_SIZE_92D
] = {
41 0x7f8001fe, // 0, +6.0dB
42 0x788001e2, // 1, +5.5dB
43 0x71c001c7, // 2, +5.0dB
44 0x6b8001ae, // 3, +4.5dB
45 0x65400195, // 4, +4.0dB
46 0x5fc0017f, // 5, +3.5dB
47 0x5a400169, // 6, +3.0dB
48 0x55400155, // 7, +2.5dB
49 0x50800142, // 8, +2.0dB
50 0x4c000130, // 9, +1.5dB
51 0x47c0011f, // 10, +1.0dB
52 0x43c0010f, // 11, +0.5dB
53 0x40000100, // 12, +0dB
54 0x3c8000f2, // 13, -0.5dB
55 0x390000e4, // 14, -1.0dB
56 0x35c000d7, // 15, -1.5dB
57 0x32c000cb, // 16, -2.0dB
58 0x300000c0, // 17, -2.5dB
59 0x2d4000b5, // 18, -3.0dB
60 0x2ac000ab, // 19, -3.5dB
61 0x288000a2, // 20, -4.0dB
62 0x26000098, // 21, -4.5dB
63 0x24000090, // 22, -5.0dB
64 0x22000088, // 23, -5.5dB
65 0x20000080, // 24, -6.0dB
66 0x1e400079, // 25, -6.5dB
67 0x1c800072, // 26, -7.0dB
68 0x1b00006c, // 27. -7.5dB
69 0x19800066, // 28, -8.0dB
70 0x18000060, // 29, -8.5dB
71 0x16c0005b, // 30, -9.0dB
72 0x15800056, // 31, -9.5dB
73 0x14400051, // 32, -10.0dB
74 0x1300004c, // 33, -10.5dB
75 0x12000048, // 34, -11.0dB
76 0x11000044, // 35, -11.5dB
77 0x10000040, // 36, -12.0dB
78 0x0f00003c,// 37, -12.5dB
79 0x0e400039,// 38, -13.0dB
80 0x0d800036,// 39, -13.5dB
81 0x0cc00033,// 40, -14.0dB
82 0x0c000030,// 41, -14.5dB
83 0x0b40002d,// 42, -15.0dB
87 u8 CCKSwingTable_Ch1_Ch13
[CCK_TABLE_SIZE
][8] = {
88 {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04}, // 0, +0dB
89 {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, // 1, -0.5dB
90 {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, // 2, -1.0dB
91 {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, // 3, -1.5dB
92 {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, // 4, -2.0dB
93 {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, // 5, -2.5dB
94 {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, // 6, -3.0dB
95 {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, // 7, -3.5dB
96 {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, // 8, -4.0dB
97 {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, // 9, -4.5dB
98 {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, // 10, -5.0dB
99 {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, // 11, -5.5dB
100 {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, // 12, -6.0dB
101 {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, // 13, -6.5dB
102 {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, // 14, -7.0dB
103 {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, // 15, -7.5dB
104 {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, // 16, -8.0dB
105 {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, // 17, -8.5dB
106 {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, // 18, -9.0dB
107 {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, // 19, -9.5dB
108 {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, // 20, -10.0dB
109 {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, // 21, -10.5dB
110 {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, // 22, -11.0dB
111 {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, // 23, -11.5dB
112 {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, // 24, -12.0dB
113 {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, // 25, -12.5dB
114 {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, // 26, -13.0dB
115 {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, // 27, -13.5dB
116 {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, // 28, -14.0dB
117 {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, // 29, -14.5dB
118 {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, // 30, -15.0dB
119 {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, // 31, -15.5dB
120 {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01} // 32, -16.0dB
124 u8 CCKSwingTable_Ch14
[CCK_TABLE_SIZE
][8]= {
125 {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00}, // 0, +0dB
126 {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, // 1, -0.5dB
127 {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, // 2, -1.0dB
128 {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, // 3, -1.5dB
129 {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, // 4, -2.0dB
130 {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, // 5, -2.5dB
131 {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, // 6, -3.0dB
132 {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, // 7, -3.5dB
133 {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, // 8, -4.0dB
134 {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, // 9, -4.5dB
135 {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, // 10, -5.0dB
136 {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, // 11, -5.5dB
137 {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, // 12, -6.0dB
138 {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, // 13, -6.5dB
139 {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, // 14, -7.0dB
140 {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, // 15, -7.5dB
141 {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, // 16, -8.0dB
142 {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, // 17, -8.5dB
143 {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, // 18, -9.0dB
144 {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, // 19, -9.5dB
145 {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, // 20, -10.0dB
146 {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, // 21, -10.5dB
147 {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, // 22, -11.0dB
148 {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, // 23, -11.5dB
149 {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, // 24, -12.0dB
150 {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, // 25, -12.5dB
151 {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, // 26, -13.0dB
152 {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, // 27, -13.5dB
153 {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, // 28, -14.0dB
154 {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, // 29, -14.5dB
155 {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, // 30, -15.0dB
156 {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, // 31, -15.5dB
157 {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00} // 32, -16.0dB
161 #ifdef CONFIG_CHIP_VER_INTEGRATION
162 void dump_chip_info(HAL_VERSION ChipVersion
)
164 if(IS_81XXC(ChipVersion
)){
165 DBG_871X("Chip Version Info: %s_",IS_92C_SERIAL(ChipVersion
)?"CHIP_8192C":"CHIP_8188C");
167 else if(IS_92D(ChipVersion
)){
168 DBG_871X("Chip Version Info: CHIP_8192D_");
170 else if(IS_8723_SERIES(ChipVersion
)){
171 DBG_871X("Chip Version Info: CHIP_8723A_");
173 else if(IS_8188E(ChipVersion
)){
174 DBG_871X("Chip Version Info: CHIP_8188E_");
177 DBG_871X("%s_",IS_NORMAL_CHIP(ChipVersion
)?"Normal_Chip":"Test_Chip");
178 DBG_871X("%s_",IS_CHIP_VENDOR_TSMC(ChipVersion
)?"TSMC":"UMC");
179 if(IS_A_CUT(ChipVersion
)) DBG_871X("A_CUT_");
180 else if(IS_B_CUT(ChipVersion
)) DBG_871X("B_CUT_");
181 else if(IS_C_CUT(ChipVersion
)) DBG_871X("C_CUT_");
182 else if(IS_D_CUT(ChipVersion
)) DBG_871X("D_CUT_");
183 else if(IS_E_CUT(ChipVersion
)) DBG_871X("E_CUT_");
184 else DBG_871X("UNKNOWN_CUT(%d)_",ChipVersion
.CUTVersion
);
186 if(IS_1T1R(ChipVersion
)) DBG_871X("1T1R_");
187 else if(IS_1T2R(ChipVersion
)) DBG_871X("1T2R_");
188 else if(IS_2T2R(ChipVersion
)) DBG_871X("2T2R_");
189 else DBG_871X("UNKNOWN_RFTYPE(%d)_",ChipVersion
.RFType
);
192 DBG_871X("RomVer(%d)\n",ChipVersion
.ROMVer
);
197 #define EEPROM_CHANNEL_PLAN_BY_HW_MASK 0x80
199 u8
//return the final channel plan decision
200 hal_com_get_channel_plan(
201 IN PADAPTER padapter
,
202 IN u8 hw_channel_plan
, //channel plan from HW (efuse/eeprom)
203 IN u8 sw_channel_plan
, //channel plan from SW (registry/module param)
204 IN u8 def_channel_plan
, //channel plan used when the former two is invalid
205 IN BOOLEAN AutoLoadFail
214 if (!rtw_is_channel_plan_valid(sw_channel_plan
))
216 if (hw_channel_plan
& EEPROM_CHANNEL_PLAN_BY_HW_MASK
)
220 if (swConfig
== _TRUE
)
221 chnlPlan
= sw_channel_plan
;
223 chnlPlan
= hw_channel_plan
& (~EEPROM_CHANNEL_PLAN_BY_HW_MASK
);
225 if (!rtw_is_channel_plan_valid(chnlPlan
))
226 chnlPlan
= def_channel_plan
;
231 u8
MRateToHwRate(u8 rate
)
233 u8 ret
= DESC_RATE1M
;
237 // CCK and OFDM non-HT rates
238 case IEEE80211_CCK_RATE_1MB
: ret
= DESC_RATE1M
; break;
239 case IEEE80211_CCK_RATE_2MB
: ret
= DESC_RATE2M
; break;
240 case IEEE80211_CCK_RATE_5MB
: ret
= DESC_RATE5_5M
; break;
241 case IEEE80211_CCK_RATE_11MB
: ret
= DESC_RATE11M
; break;
242 case IEEE80211_OFDM_RATE_6MB
: ret
= DESC_RATE6M
; break;
243 case IEEE80211_OFDM_RATE_9MB
: ret
= DESC_RATE9M
; break;
244 case IEEE80211_OFDM_RATE_12MB
: ret
= DESC_RATE12M
; break;
245 case IEEE80211_OFDM_RATE_18MB
: ret
= DESC_RATE18M
; break;
246 case IEEE80211_OFDM_RATE_24MB
: ret
= DESC_RATE24M
; break;
247 case IEEE80211_OFDM_RATE_36MB
: ret
= DESC_RATE36M
; break;
248 case IEEE80211_OFDM_RATE_48MB
: ret
= DESC_RATE48M
; break;
249 case IEEE80211_OFDM_RATE_54MB
: ret
= DESC_RATE54M
; break;
251 // HT rates since here
252 //case MGN_MCS0: ret = DESC_RATEMCS0; break;
253 //case MGN_MCS1: ret = DESC_RATEMCS1; break;
254 //case MGN_MCS2: ret = DESC_RATEMCS2; break;
255 //case MGN_MCS3: ret = DESC_RATEMCS3; break;
256 //case MGN_MCS4: ret = DESC_RATEMCS4; break;
257 //case MGN_MCS5: ret = DESC_RATEMCS5; break;
258 //case MGN_MCS6: ret = DESC_RATEMCS6; break;
259 //case MGN_MCS7: ret = DESC_RATEMCS7; break;
272 u8 i
, is_brate
, brate
;
274 for(i
=0;i
<NDIS_802_11_LENGTH_RATES_EX
;i
++)
276 is_brate
= mBratesOS
[i
] & IEEE80211_BASIC_RATE_MASK
;
277 brate
= mBratesOS
[i
] & 0x7f;
283 case IEEE80211_CCK_RATE_1MB
: *pBrateCfg
|= RATE_1M
; break;
284 case IEEE80211_CCK_RATE_2MB
: *pBrateCfg
|= RATE_2M
; break;
285 case IEEE80211_CCK_RATE_5MB
: *pBrateCfg
|= RATE_5_5M
;break;
286 case IEEE80211_CCK_RATE_11MB
: *pBrateCfg
|= RATE_11M
; break;
287 case IEEE80211_OFDM_RATE_6MB
: *pBrateCfg
|= RATE_6M
; break;
288 case IEEE80211_OFDM_RATE_9MB
: *pBrateCfg
|= RATE_9M
; break;
289 case IEEE80211_OFDM_RATE_12MB
: *pBrateCfg
|= RATE_12M
; break;
290 case IEEE80211_OFDM_RATE_18MB
: *pBrateCfg
|= RATE_18M
; break;
291 case IEEE80211_OFDM_RATE_24MB
: *pBrateCfg
|= RATE_24M
; break;
292 case IEEE80211_OFDM_RATE_36MB
: *pBrateCfg
|= RATE_36M
; break;
293 case IEEE80211_OFDM_RATE_48MB
: *pBrateCfg
|= RATE_48M
; break;
294 case IEEE80211_OFDM_RATE_54MB
: *pBrateCfg
|= RATE_54M
; break;
300 void hal_init_macaddr(_adapter
*adapter
)
302 rtw_hal_set_hwreg(adapter
, HW_VAR_MAC_ADDR
, adapter
->eeprompriv
.mac_addr
);
303 #ifdef CONFIG_CONCURRENT_MODE
304 if (adapter
->pbuddy_adapter
)
305 rtw_hal_set_hwreg(adapter
->pbuddy_adapter
, HW_VAR_MAC_ADDR
, adapter
->pbuddy_adapter
->eeprompriv
.mac_addr
);
311 * Field TRIGGER CONTENT CMD_SEQ CMD_LEN CMD_ID
312 * BITS [127:120] [119:16] [15:8] [7:4] [3:0]
315 void c2h_evt_clear(_adapter
*adapter
)
317 rtw_write8(adapter
, REG_C2HEVT_CLEAR
, C2H_EVT_HOST_CLOSE
);
320 s32
c2h_evt_read(_adapter
*adapter
, u8
*buf
)
323 struct c2h_evt_hdr
*c2h_evt
;
330 trigger
= rtw_read8(adapter
, REG_C2HEVT_CLEAR
);
332 if (trigger
== C2H_EVT_HOST_CLOSE
) {
333 goto exit
; /* Not ready */
334 } else if (trigger
!= C2H_EVT_FW_CLOSE
) {
335 goto clear_evt
; /* Not a valid value */
338 c2h_evt
= (struct c2h_evt_hdr
*)buf
;
340 _rtw_memset(c2h_evt
, 0, 16);
342 *buf
= rtw_read8(adapter
, REG_C2HEVT_MSG_NORMAL
);
343 *(buf
+1) = rtw_read8(adapter
, REG_C2HEVT_MSG_NORMAL
+ 1);
345 RT_PRINT_DATA(_module_hal_init_c_
, _drv_info_
, "c2h_evt_read(): ",
346 &c2h_evt
, sizeof(c2h_evt
));
349 DBG_871X("%s id:%u, len:%u, seq:%u, trigger:0x%02x\n", __func__
350 , c2h_evt
->id
, c2h_evt
->plen
, c2h_evt
->seq
, trigger
);
353 /* Read the content */
354 for (i
= 0; i
< c2h_evt
->plen
; i
++)
355 c2h_evt
->payload
[i
] = rtw_read8(adapter
, REG_C2HEVT_MSG_NORMAL
+ sizeof(*c2h_evt
) + i
);
357 RT_PRINT_DATA(_module_hal_init_c_
, _drv_info_
, "c2h_evt_read(): Command Content:\n",
358 c2h_evt
->payload
, c2h_evt
->plen
);
364 * Clear event to notify FW we have read the command.
365 * If this field isn't clear, the FW won't update the next command message.
367 c2h_evt_clear(adapter
);