1 /******************************************************************************
3 * Copyright(c) 2009-2012 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 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
35 #include "../rtl8192c/phy_common.h"
38 #include "../rtl8192c/dm_common.h"
39 #include "../rtl8192c/fw_common.h"
41 #include "../rtl8192ce/hw.h"
46 static void _rtl92cu_phy_param_tab_init(struct ieee80211_hw
*hw
)
48 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
49 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
50 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtlpriv
);
52 rtlphy
->hwparam_tables
[MAC_REG
].length
= RTL8192CUMAC_2T_ARRAYLENGTH
;
53 rtlphy
->hwparam_tables
[MAC_REG
].pdata
= RTL8192CUMAC_2T_ARRAY
;
54 if (IS_HIGHT_PA(rtlefuse
->board_type
)) {
55 rtlphy
->hwparam_tables
[PHY_REG_PG
].length
=
56 RTL8192CUPHY_REG_Array_PG_HPLength
;
57 rtlphy
->hwparam_tables
[PHY_REG_PG
].pdata
=
58 RTL8192CUPHY_REG_Array_PG_HP
;
60 rtlphy
->hwparam_tables
[PHY_REG_PG
].length
=
61 RTL8192CUPHY_REG_ARRAY_PGLENGTH
;
62 rtlphy
->hwparam_tables
[PHY_REG_PG
].pdata
=
63 RTL8192CUPHY_REG_ARRAY_PG
;
66 rtlphy
->hwparam_tables
[PHY_REG_2T
].length
=
67 RTL8192CUPHY_REG_2TARRAY_LENGTH
;
68 rtlphy
->hwparam_tables
[PHY_REG_2T
].pdata
=
69 RTL8192CUPHY_REG_2TARRAY
;
70 rtlphy
->hwparam_tables
[RADIOA_2T
].length
=
71 RTL8192CURADIOA_2TARRAYLENGTH
;
72 rtlphy
->hwparam_tables
[RADIOA_2T
].pdata
=
73 RTL8192CURADIOA_2TARRAY
;
74 rtlphy
->hwparam_tables
[RADIOB_2T
].length
=
75 RTL8192CURADIOB_2TARRAYLENGTH
;
76 rtlphy
->hwparam_tables
[RADIOB_2T
].pdata
=
77 RTL8192CU_RADIOB_2TARRAY
;
78 rtlphy
->hwparam_tables
[AGCTAB_2T
].length
=
79 RTL8192CUAGCTAB_2TARRAYLENGTH
;
80 rtlphy
->hwparam_tables
[AGCTAB_2T
].pdata
=
81 RTL8192CUAGCTAB_2TARRAY
;
83 if (IS_HIGHT_PA(rtlefuse
->board_type
)) {
84 rtlphy
->hwparam_tables
[PHY_REG_1T
].length
=
85 RTL8192CUPHY_REG_1T_HPArrayLength
;
86 rtlphy
->hwparam_tables
[PHY_REG_1T
].pdata
=
87 RTL8192CUPHY_REG_1T_HPArray
;
88 rtlphy
->hwparam_tables
[RADIOA_1T
].length
=
89 RTL8192CURadioA_1T_HPArrayLength
;
90 rtlphy
->hwparam_tables
[RADIOA_1T
].pdata
=
91 RTL8192CURadioA_1T_HPArray
;
92 rtlphy
->hwparam_tables
[RADIOB_1T
].length
=
93 RTL8192CURADIOB_1TARRAYLENGTH
;
94 rtlphy
->hwparam_tables
[RADIOB_1T
].pdata
=
95 RTL8192CU_RADIOB_1TARRAY
;
96 rtlphy
->hwparam_tables
[AGCTAB_1T
].length
=
97 RTL8192CUAGCTAB_1T_HPArrayLength
;
98 rtlphy
->hwparam_tables
[AGCTAB_1T
].pdata
=
99 Rtl8192CUAGCTAB_1T_HPArray
;
101 rtlphy
->hwparam_tables
[PHY_REG_1T
].length
=
102 RTL8192CUPHY_REG_1TARRAY_LENGTH
;
103 rtlphy
->hwparam_tables
[PHY_REG_1T
].pdata
=
104 RTL8192CUPHY_REG_1TARRAY
;
105 rtlphy
->hwparam_tables
[RADIOA_1T
].length
=
106 RTL8192CURADIOA_1TARRAYLENGTH
;
107 rtlphy
->hwparam_tables
[RADIOA_1T
].pdata
=
108 RTL8192CU_RADIOA_1TARRAY
;
109 rtlphy
->hwparam_tables
[RADIOB_1T
].length
=
110 RTL8192CURADIOB_1TARRAYLENGTH
;
111 rtlphy
->hwparam_tables
[RADIOB_1T
].pdata
=
112 RTL8192CU_RADIOB_1TARRAY
;
113 rtlphy
->hwparam_tables
[AGCTAB_1T
].length
=
114 RTL8192CUAGCTAB_1TARRAYLENGTH
;
115 rtlphy
->hwparam_tables
[AGCTAB_1T
].pdata
=
116 RTL8192CUAGCTAB_1TARRAY
;
120 static void _rtl92cu_read_txpower_info_from_hwpg(struct ieee80211_hw
*hw
,
124 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
125 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
126 u8 rf_path
, index
, tempval
;
129 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
130 for (i
= 0; i
< 3; i
++) {
131 if (!autoload_fail
) {
133 eeprom_chnlarea_txpwr_cck
[rf_path
][i
] =
134 hwinfo
[EEPROM_TXPOWERCCK
+ rf_path
* 3 + i
];
136 eeprom_chnlarea_txpwr_ht40_1s
[rf_path
][i
] =
137 hwinfo
[EEPROM_TXPOWERHT40_1S
+ rf_path
* 3 +
141 eeprom_chnlarea_txpwr_cck
[rf_path
][i
] =
142 EEPROM_DEFAULT_TXPOWERLEVEL
;
144 eeprom_chnlarea_txpwr_ht40_1s
[rf_path
][i
] =
145 EEPROM_DEFAULT_TXPOWERLEVEL
;
149 for (i
= 0; i
< 3; i
++) {
151 tempval
= hwinfo
[EEPROM_TXPOWERHT40_2SDIFF
+ i
];
153 tempval
= EEPROM_DEFAULT_HT40_2SDIFF
;
154 rtlefuse
->eprom_chnl_txpwr_ht40_2sdf
[RF90_PATH_A
][i
] =
156 rtlefuse
->eprom_chnl_txpwr_ht40_2sdf
[RF90_PATH_B
][i
] =
157 ((tempval
& 0xf0) >> 4);
159 for (rf_path
= 0; rf_path
< 2; rf_path
++)
160 for (i
= 0; i
< 3; i
++)
161 RTPRINT(rtlpriv
, FINIT
, INIT_EEPROM
,
162 "RF(%d) EEPROM CCK Area(%d) = 0x%x\n",
165 eeprom_chnlarea_txpwr_cck
[rf_path
][i
]);
166 for (rf_path
= 0; rf_path
< 2; rf_path
++)
167 for (i
= 0; i
< 3; i
++)
168 RTPRINT(rtlpriv
, FINIT
, INIT_EEPROM
,
169 "RF(%d) EEPROM HT40 1S Area(%d) = 0x%x\n",
172 eeprom_chnlarea_txpwr_ht40_1s
[rf_path
][i
]);
173 for (rf_path
= 0; rf_path
< 2; rf_path
++)
174 for (i
= 0; i
< 3; i
++)
175 RTPRINT(rtlpriv
, FINIT
, INIT_EEPROM
,
176 "RF(%d) EEPROM HT40 2S Diff Area(%d) = 0x%x\n",
179 eprom_chnl_txpwr_ht40_2sdf
[rf_path
][i
]);
180 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
181 for (i
= 0; i
< 14; i
++) {
182 index
= rtl92c_get_chnl_group((u8
)i
);
183 rtlefuse
->txpwrlevel_cck
[rf_path
][i
] =
184 rtlefuse
->eeprom_chnlarea_txpwr_cck
[rf_path
][index
];
185 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
] =
187 eeprom_chnlarea_txpwr_ht40_1s
[rf_path
][index
];
189 eeprom_chnlarea_txpwr_ht40_1s
[rf_path
][index
] -
191 eprom_chnl_txpwr_ht40_2sdf
[rf_path
][index
])
193 rtlefuse
->txpwrlevel_ht40_2s
[rf_path
][i
] =
195 eeprom_chnlarea_txpwr_ht40_1s
[rf_path
]
197 eprom_chnl_txpwr_ht40_2sdf
[rf_path
]
200 rtlefuse
->txpwrlevel_ht40_2s
[rf_path
][i
] = 0;
203 for (i
= 0; i
< 14; i
++) {
204 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
205 "RF(%d)-Ch(%d) [CCK / HT40_1S / HT40_2S] = [0x%x / 0x%x / 0x%x]\n", rf_path
, i
,
206 rtlefuse
->txpwrlevel_cck
[rf_path
][i
],
207 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
],
208 rtlefuse
->txpwrlevel_ht40_2s
[rf_path
][i
]);
211 for (i
= 0; i
< 3; i
++) {
212 if (!autoload_fail
) {
213 rtlefuse
->eeprom_pwrlimit_ht40
[i
] =
214 hwinfo
[EEPROM_TXPWR_GROUP
+ i
];
215 rtlefuse
->eeprom_pwrlimit_ht20
[i
] =
216 hwinfo
[EEPROM_TXPWR_GROUP
+ 3 + i
];
218 rtlefuse
->eeprom_pwrlimit_ht40
[i
] = 0;
219 rtlefuse
->eeprom_pwrlimit_ht20
[i
] = 0;
222 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
223 for (i
= 0; i
< 14; i
++) {
224 index
= rtl92c_get_chnl_group((u8
)i
);
225 if (rf_path
== RF90_PATH_A
) {
226 rtlefuse
->pwrgroup_ht20
[rf_path
][i
] =
227 (rtlefuse
->eeprom_pwrlimit_ht20
[index
]
229 rtlefuse
->pwrgroup_ht40
[rf_path
][i
] =
230 (rtlefuse
->eeprom_pwrlimit_ht40
[index
]
232 } else if (rf_path
== RF90_PATH_B
) {
233 rtlefuse
->pwrgroup_ht20
[rf_path
][i
] =
234 ((rtlefuse
->eeprom_pwrlimit_ht20
[index
]
236 rtlefuse
->pwrgroup_ht40
[rf_path
][i
] =
237 ((rtlefuse
->eeprom_pwrlimit_ht40
[index
]
240 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
241 "RF-%d pwrgroup_ht20[%d] = 0x%x\n",
243 rtlefuse
->pwrgroup_ht20
[rf_path
][i
]);
244 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
245 "RF-%d pwrgroup_ht40[%d] = 0x%x\n",
247 rtlefuse
->pwrgroup_ht40
[rf_path
][i
]);
250 for (i
= 0; i
< 14; i
++) {
251 index
= rtl92c_get_chnl_group((u8
)i
);
253 tempval
= hwinfo
[EEPROM_TXPOWERHT20DIFF
+ index
];
255 tempval
= EEPROM_DEFAULT_HT20_DIFF
;
256 rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
] = (tempval
& 0xF);
257 rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
] =
258 ((tempval
>> 4) & 0xF);
259 if (rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
] & BIT(3))
260 rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
] |= 0xF0;
261 if (rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
] & BIT(3))
262 rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
] |= 0xF0;
263 index
= rtl92c_get_chnl_group((u8
)i
);
265 tempval
= hwinfo
[EEPROM_TXPOWER_OFDMDIFF
+ index
];
267 tempval
= EEPROM_DEFAULT_LEGACYHTTXPOWERDIFF
;
268 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][i
] = (tempval
& 0xF);
269 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_B
][i
] =
270 ((tempval
>> 4) & 0xF);
272 rtlefuse
->legacy_ht_txpowerdiff
=
273 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][7];
274 for (i
= 0; i
< 14; i
++)
275 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
276 "RF-A Ht20 to HT40 Diff[%d] = 0x%x\n",
277 i
, rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
]);
278 for (i
= 0; i
< 14; i
++)
279 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
280 "RF-A Legacy to Ht40 Diff[%d] = 0x%x\n",
281 i
, rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][i
]);
282 for (i
= 0; i
< 14; i
++)
283 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
284 "RF-B Ht20 to HT40 Diff[%d] = 0x%x\n",
285 i
, rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
]);
286 for (i
= 0; i
< 14; i
++)
287 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
288 "RF-B Legacy to HT40 Diff[%d] = 0x%x\n",
289 i
, rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_B
][i
]);
291 rtlefuse
->eeprom_regulatory
= (hwinfo
[RF_OPTION1
] & 0x7);
293 rtlefuse
->eeprom_regulatory
= 0;
294 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
295 "eeprom_regulatory = 0x%x\n", rtlefuse
->eeprom_regulatory
);
296 if (!autoload_fail
) {
297 rtlefuse
->eeprom_tssi
[RF90_PATH_A
] = hwinfo
[EEPROM_TSSI_A
];
298 rtlefuse
->eeprom_tssi
[RF90_PATH_B
] = hwinfo
[EEPROM_TSSI_B
];
300 rtlefuse
->eeprom_tssi
[RF90_PATH_A
] = EEPROM_DEFAULT_TSSI
;
301 rtlefuse
->eeprom_tssi
[RF90_PATH_B
] = EEPROM_DEFAULT_TSSI
;
303 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
304 "TSSI_A = 0x%x, TSSI_B = 0x%x\n",
305 rtlefuse
->eeprom_tssi
[RF90_PATH_A
],
306 rtlefuse
->eeprom_tssi
[RF90_PATH_B
]);
308 tempval
= hwinfo
[EEPROM_THERMAL_METER
];
310 tempval
= EEPROM_DEFAULT_THERMALMETER
;
311 rtlefuse
->eeprom_thermalmeter
= (tempval
& 0x1f);
312 if (rtlefuse
->eeprom_thermalmeter
< 0x06 ||
313 rtlefuse
->eeprom_thermalmeter
> 0x1c)
314 rtlefuse
->eeprom_thermalmeter
= 0x12;
315 if (rtlefuse
->eeprom_thermalmeter
== 0x1f || autoload_fail
)
316 rtlefuse
->apk_thermalmeterignore
= true;
317 rtlefuse
->thermalmeter
[0] = rtlefuse
->eeprom_thermalmeter
;
318 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
319 "thermalmeter = 0x%x\n", rtlefuse
->eeprom_thermalmeter
);
322 static void _rtl92cu_read_board_type(struct ieee80211_hw
*hw
, u8
*contents
)
324 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
325 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
328 if (IS_NORMAL_CHIP(rtlhal
->version
)) {
329 boardType
= ((contents
[EEPROM_RF_OPT1
]) &
330 BOARD_TYPE_NORMAL_MASK
) >> 5; /*bit[7:5]*/
332 boardType
= contents
[EEPROM_RF_OPT4
];
333 boardType
&= BOARD_TYPE_TEST_MASK
;
335 rtlefuse
->board_type
= boardType
;
336 if (IS_HIGHT_PA(rtlefuse
->board_type
))
337 rtlefuse
->external_pa
= 1;
338 pr_info("Board Type %x\n", rtlefuse
->board_type
);
341 static void _rtl92cu_read_adapter_info(struct ieee80211_hw
*hw
)
343 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
344 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
345 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
346 int params
[] = {RTL8190_EEPROM_ID
, EEPROM_VID
, EEPROM_DID
,
347 EEPROM_SVID
, EEPROM_SMID
, EEPROM_MAC_ADDR
,
348 EEPROM_CHANNELPLAN
, EEPROM_VERSION
, EEPROM_CUSTOMER_ID
,
352 hwinfo
= kzalloc(HWSET_MAX_SIZE
, GFP_KERNEL
);
356 if (rtl_get_hwinfo(hw
, rtlpriv
, HWSET_MAX_SIZE
, hwinfo
, params
))
359 _rtl92cu_read_txpower_info_from_hwpg(hw
,
360 rtlefuse
->autoload_failflag
, hwinfo
);
361 _rtl92cu_read_board_type(hw
, hwinfo
);
363 rtlefuse
->txpwr_fromeprom
= true;
364 if (rtlhal
->oem_id
== RT_CID_DEFAULT
) {
365 switch (rtlefuse
->eeprom_oemid
) {
366 case EEPROM_CID_DEFAULT
:
367 if (rtlefuse
->eeprom_did
== 0x8176) {
368 if ((rtlefuse
->eeprom_svid
== 0x103C &&
369 rtlefuse
->eeprom_smid
== 0x1629))
370 rtlhal
->oem_id
= RT_CID_819X_HP
;
372 rtlhal
->oem_id
= RT_CID_DEFAULT
;
374 rtlhal
->oem_id
= RT_CID_DEFAULT
;
377 case EEPROM_CID_TOSHIBA
:
378 rtlhal
->oem_id
= RT_CID_TOSHIBA
;
381 rtlhal
->oem_id
= RT_CID_819X_QMI
;
383 case EEPROM_CID_WHQL
:
385 rtlhal
->oem_id
= RT_CID_DEFAULT
;
393 static void _rtl92cu_hal_customized_behavior(struct ieee80211_hw
*hw
)
395 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
396 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
398 switch (rtlhal
->oem_id
) {
400 rtlpriv
->ledctl
.led_opendrain
= true;
402 case RT_CID_819X_LENOVO
:
406 case RT_CID_819X_ACER
:
411 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "RT Customized ID: 0x%02X\n",
415 void rtl92cu_read_eeprom_info(struct ieee80211_hw
*hw
)
418 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
419 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
420 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
423 if (!IS_NORMAL_CHIP(rtlhal
->version
))
425 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_9346CR
);
426 rtlefuse
->epromtype
= (tmp_u1b
& BOOT_FROM_EEPROM
) ?
427 EEPROM_93C46
: EEPROM_BOOT_EFUSE
;
428 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from %s\n",
429 tmp_u1b
& BOOT_FROM_EEPROM
? "EERROM" : "EFUSE");
430 rtlefuse
->autoload_failflag
= (tmp_u1b
& EEPROM_EN
) ? false : true;
431 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload %s\n",
432 tmp_u1b
& EEPROM_EN
? "OK!!" : "ERR!!");
433 _rtl92cu_read_adapter_info(hw
);
434 _rtl92cu_hal_customized_behavior(hw
);
438 static int _rtl92cu_init_power_on(struct ieee80211_hw
*hw
)
440 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
444 /* polling autoload done. */
445 u32 pollingCount
= 0;
448 if (rtl_read_byte(rtlpriv
, REG_APS_FSMCO
) & PFM_ALDN
) {
449 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
453 if (pollingCount
++ > 100) {
454 pr_err("Failed to polling REG_APS_FSMCO[PFM_ALDN] done!\n");
458 /* 0. RSV_CTRL 0x1C[7:0] = 0 unlock ISO/CLK/Power control register */
459 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x0);
460 /* Power on when re-enter from IPS/Radio off/card disable */
461 /* enable SPS into PWM mode */
462 rtl_write_byte(rtlpriv
, REG_SPS0_CTRL
, 0x2b);
464 value8
= rtl_read_byte(rtlpriv
, REG_LDOV12D_CTRL
);
465 if (0 == (value8
& LDV12_EN
)) {
467 rtl_write_byte(rtlpriv
, REG_LDOV12D_CTRL
, value8
);
468 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
469 " power-on :REG_LDOV12D_CTRL Reg0x21:0x%02x\n",
472 value8
= rtl_read_byte(rtlpriv
, REG_SYS_ISO_CTRL
);
473 value8
&= ~ISO_MD2PP
;
474 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
, value8
);
476 /* auto enable WLAN */
478 value16
= rtl_read_word(rtlpriv
, REG_APS_FSMCO
);
479 value16
|= APFM_ONMAC
;
480 rtl_write_word(rtlpriv
, REG_APS_FSMCO
, value16
);
482 if (!(rtl_read_word(rtlpriv
, REG_APS_FSMCO
) & APFM_ONMAC
)) {
483 pr_info("MAC auto ON okay!\n");
486 if (pollingCount
++ > 1000) {
487 pr_err("Failed to polling REG_APS_FSMCO[APFM_ONMAC] done!\n");
491 /* Enable Radio ,GPIO ,and LED function */
492 rtl_write_word(rtlpriv
, REG_APS_FSMCO
, 0x0812);
493 /* release RF digital isolation */
494 value16
= rtl_read_word(rtlpriv
, REG_SYS_ISO_CTRL
);
495 value16
&= ~ISO_DIOR
;
496 rtl_write_word(rtlpriv
, REG_SYS_ISO_CTRL
, value16
);
497 /* Reconsider when to do this operation after asking HWSD. */
499 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, (rtl_read_byte(rtlpriv
,
500 REG_APSD_CTRL
) & ~BIT(6)));
503 } while ((pollingCount
< 200) &&
504 (rtl_read_byte(rtlpriv
, REG_APSD_CTRL
) & BIT(7)));
505 /* Enable MAC DMA/WMAC/SCHEDULE/SEC block */
506 value16
= rtl_read_word(rtlpriv
, REG_CR
);
507 value16
|= (HCI_TXDMA_EN
| HCI_RXDMA_EN
| TXDMA_EN
| RXDMA_EN
|
508 PROTOCOL_EN
| SCHEDULE_EN
| MACTXEN
| MACRXEN
| ENSEC
);
509 rtl_write_word(rtlpriv
, REG_CR
, value16
);
513 static void _rtl92cu_init_queue_reserved_page(struct ieee80211_hw
*hw
,
518 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
519 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
520 bool isChipN
= IS_NORMAL_CHIP(rtlhal
->version
);
521 u32 outEPNum
= (u32
)out_ep_num
;
528 u32 txQPageNum
, txQPageUnit
, txQRemainPage
;
531 numPubQ
= (isChipN
) ? CHIP_B_PAGE_NUM_PUBQ
:
532 CHIP_A_PAGE_NUM_PUBQ
;
533 txQPageNum
= TX_TOTAL_PAGE_NUMBER
- numPubQ
;
535 txQPageUnit
= txQPageNum
/outEPNum
;
536 txQRemainPage
= txQPageNum
% outEPNum
;
537 if (queue_sel
& TX_SELE_HQ
)
539 if (queue_sel
& TX_SELE_LQ
)
541 /* HIGH priority queue always present in the configuration of
542 * 2 out-ep. Remainder pages have assigned to High queue */
543 if ((outEPNum
> 1) && (txQRemainPage
))
544 numHQ
+= txQRemainPage
;
545 /* NOTE: This step done before writting REG_RQPN. */
547 if (queue_sel
& TX_SELE_NQ
)
549 value8
= (u8
)_NPQ(numNQ
);
550 rtl_write_byte(rtlpriv
, REG_RQPN_NPQ
, value8
);
553 /* for WMM ,number of out-ep must more than or equal to 2! */
554 numPubQ
= isChipN
? WMM_CHIP_B_PAGE_NUM_PUBQ
:
555 WMM_CHIP_A_PAGE_NUM_PUBQ
;
556 if (queue_sel
& TX_SELE_HQ
) {
557 numHQ
= isChipN
? WMM_CHIP_B_PAGE_NUM_HPQ
:
558 WMM_CHIP_A_PAGE_NUM_HPQ
;
560 if (queue_sel
& TX_SELE_LQ
) {
561 numLQ
= isChipN
? WMM_CHIP_B_PAGE_NUM_LPQ
:
562 WMM_CHIP_A_PAGE_NUM_LPQ
;
564 /* NOTE: This step done before writting REG_RQPN. */
566 if (queue_sel
& TX_SELE_NQ
)
567 numNQ
= WMM_CHIP_B_PAGE_NUM_NPQ
;
568 value8
= (u8
)_NPQ(numNQ
);
569 rtl_write_byte(rtlpriv
, REG_RQPN_NPQ
, value8
);
573 value32
= _HPQ(numHQ
) | _LPQ(numLQ
) | _PUBQ(numPubQ
) | LD_RQPN
;
574 rtl_write_dword(rtlpriv
, REG_RQPN
, value32
);
577 static void _rtl92c_init_trx_buffer(struct ieee80211_hw
*hw
, bool wmm_enable
)
579 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
580 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
585 txpktbuf_bndy
= TX_PAGE_BOUNDARY
;
587 txpktbuf_bndy
= (IS_NORMAL_CHIP(rtlhal
->version
))
588 ? WMM_CHIP_B_TX_PAGE_BOUNDARY
589 : WMM_CHIP_A_TX_PAGE_BOUNDARY
;
590 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_BCNQ_BDNY
, txpktbuf_bndy
);
591 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_MGQ_BDNY
, txpktbuf_bndy
);
592 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_WMAC_LBK_BF_HD
, txpktbuf_bndy
);
593 rtl_write_byte(rtlpriv
, REG_TRXFF_BNDY
, txpktbuf_bndy
);
594 rtl_write_byte(rtlpriv
, REG_TDECTRL
+1, txpktbuf_bndy
);
595 rtl_write_word(rtlpriv
, (REG_TRXFF_BNDY
+ 2), 0x27FF);
596 value8
= _PSRX(RX_PAGE_SIZE_REG_VALUE
) | _PSTX(PBP_128
);
597 rtl_write_byte(rtlpriv
, REG_PBP
, value8
);
600 static void _rtl92c_init_chipN_reg_priority(struct ieee80211_hw
*hw
, u16 beQ
,
601 u16 bkQ
, u16 viQ
, u16 voQ
,
604 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
605 u16 value16
= (rtl_read_word(rtlpriv
, REG_TRXDMA_CTRL
) & 0x7);
607 value16
|= _TXDMA_BEQ_MAP(beQ
) | _TXDMA_BKQ_MAP(bkQ
) |
608 _TXDMA_VIQ_MAP(viQ
) | _TXDMA_VOQ_MAP(voQ
) |
609 _TXDMA_MGQ_MAP(mgtQ
) | _TXDMA_HIQ_MAP(hiQ
);
610 rtl_write_word(rtlpriv
, REG_TRXDMA_CTRL
, value16
);
613 static void _rtl92cu_init_chipN_one_out_ep_priority(struct ieee80211_hw
*hw
,
617 u16
uninitialized_var(value
);
627 value
= QUEUE_NORMAL
;
630 WARN_ON(1); /* Shall not reach here! */
633 _rtl92c_init_chipN_reg_priority(hw
, value
, value
, value
, value
,
635 pr_info("Tx queue select: 0x%02x\n", queue_sel
);
638 static void _rtl92cu_init_chipN_two_out_ep_priority(struct ieee80211_hw
*hw
,
642 u16 beQ
, bkQ
, viQ
, voQ
, mgtQ
, hiQ
;
643 u16
uninitialized_var(valueHi
);
644 u16
uninitialized_var(valueLow
);
647 case (TX_SELE_HQ
| TX_SELE_LQ
):
648 valueHi
= QUEUE_HIGH
;
649 valueLow
= QUEUE_LOW
;
651 case (TX_SELE_NQ
| TX_SELE_LQ
):
652 valueHi
= QUEUE_NORMAL
;
653 valueLow
= QUEUE_LOW
;
655 case (TX_SELE_HQ
| TX_SELE_NQ
):
656 valueHi
= QUEUE_HIGH
;
657 valueLow
= QUEUE_NORMAL
;
670 } else {/* for WMM ,CONFIG_OUT_EP_WIFI_MODE */
678 _rtl92c_init_chipN_reg_priority(hw
, beQ
, bkQ
, viQ
, voQ
, mgtQ
, hiQ
);
679 pr_info("Tx queue select: 0x%02x\n", queue_sel
);
682 static void _rtl92cu_init_chipN_three_out_ep_priority(struct ieee80211_hw
*hw
,
686 u16 beQ
, bkQ
, viQ
, voQ
, mgtQ
, hiQ
;
688 if (!wmm_enable
) { /* typical setting */
695 } else { /* for WMM */
703 _rtl92c_init_chipN_reg_priority(hw
, beQ
, bkQ
, viQ
, voQ
, mgtQ
, hiQ
);
704 pr_info("Tx queue select :0x%02x..\n", queue_sel
);
707 static void _rtl92cu_init_chipN_queue_priority(struct ieee80211_hw
*hw
,
712 switch (out_ep_num
) {
714 _rtl92cu_init_chipN_one_out_ep_priority(hw
, wmm_enable
,
718 _rtl92cu_init_chipN_two_out_ep_priority(hw
, wmm_enable
,
722 _rtl92cu_init_chipN_three_out_ep_priority(hw
, wmm_enable
,
726 WARN_ON(1); /* Shall not reach here! */
731 static void _rtl92cu_init_chipT_queue_priority(struct ieee80211_hw
*hw
,
737 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
739 switch (out_ep_num
) {
740 case 2: /* (TX_SELE_HQ|TX_SELE_LQ) */
741 if (!wmm_enable
) /* typical setting */
742 hq_sele
= HQSEL_VOQ
| HQSEL_VIQ
| HQSEL_MGTQ
|
745 hq_sele
= HQSEL_VOQ
| HQSEL_BEQ
| HQSEL_MGTQ
|
749 if (TX_SELE_LQ
== queue_sel
) {
750 /* map all endpoint to Low queue */
752 } else if (TX_SELE_HQ
== queue_sel
) {
753 /* map all endpoint to High queue */
754 hq_sele
= HQSEL_VOQ
| HQSEL_VIQ
| HQSEL_BEQ
|
755 HQSEL_BKQ
| HQSEL_MGTQ
| HQSEL_HIQ
;
759 WARN_ON(1); /* Shall not reach here! */
762 rtl_write_byte(rtlpriv
, (REG_TRXDMA_CTRL
+1), hq_sele
);
763 pr_info("Tx queue select :0x%02x..\n", hq_sele
);
766 static void _rtl92cu_init_queue_priority(struct ieee80211_hw
*hw
,
771 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
772 if (IS_NORMAL_CHIP(rtlhal
->version
))
773 _rtl92cu_init_chipN_queue_priority(hw
, wmm_enable
, out_ep_num
,
776 _rtl92cu_init_chipT_queue_priority(hw
, wmm_enable
, out_ep_num
,
780 static void _rtl92cu_init_wmac_setting(struct ieee80211_hw
*hw
)
784 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
786 value32
= (RCR_APM
| RCR_AM
| RCR_ADF
| RCR_AB
| RCR_APPFCS
|
787 RCR_APP_ICV
| RCR_AMF
| RCR_HTC_LOC_CTRL
|
788 RCR_APP_MIC
| RCR_APP_PHYSTS
| RCR_ACRC32
);
789 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
, (u8
*)(&value32
));
790 /* Accept all multicast address */
791 rtl_write_dword(rtlpriv
, REG_MAR
, 0xFFFFFFFF);
792 rtl_write_dword(rtlpriv
, REG_MAR
+ 4, 0xFFFFFFFF);
793 /* Accept all management frames */
795 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_MGT_FILTER
,
797 /* Reject all control frame - default value is 0 */
799 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_CTRL_FILTER
,
801 /* Accept all data frames */
803 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_DATA_FILTER
,
807 static void _rtl92cu_init_beacon_parameters(struct ieee80211_hw
*hw
)
809 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
810 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
812 rtl_write_word(rtlpriv
, REG_BCN_CTRL
, 0x1010);
814 /* TODO: Remove these magic number */
815 rtl_write_word(rtlpriv
, REG_TBTT_PROHIBIT
, 0x6404);
816 rtl_write_byte(rtlpriv
, REG_DRVERLYINT
, DRIVER_EARLY_INT_TIME
);
817 rtl_write_byte(rtlpriv
, REG_BCNDMATIM
, BCN_DMA_ATIME_INT_TIME
);
818 /* Change beacon AIFS to the largest number
819 * beacause test chip does not contension before sending beacon.
821 if (IS_NORMAL_CHIP(rtlhal
->version
))
822 rtl_write_word(rtlpriv
, REG_BCNTCFG
, 0x660F);
824 rtl_write_word(rtlpriv
, REG_BCNTCFG
, 0x66FF);
827 static int _rtl92cu_init_mac(struct ieee80211_hw
*hw
)
829 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
830 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
831 struct rtl_usb_priv
*usb_priv
= rtl_usbpriv(hw
);
832 struct rtl_usb
*rtlusb
= rtl_usbdev(usb_priv
);
835 u8 wmm_enable
= false; /* TODO */
836 u8 out_ep_nums
= rtlusb
->out_ep_nums
;
837 u8 queue_sel
= rtlusb
->out_queue_sel
;
838 err
= _rtl92cu_init_power_on(hw
);
841 pr_err("Failed to init power on!\n");
845 boundary
= TX_PAGE_BOUNDARY
;
846 } else { /* for WMM */
847 boundary
= (IS_NORMAL_CHIP(rtlhal
->version
))
848 ? WMM_CHIP_B_TX_PAGE_BOUNDARY
849 : WMM_CHIP_A_TX_PAGE_BOUNDARY
;
851 if (false == rtl92c_init_llt_table(hw
, boundary
)) {
852 pr_err("Failed to init LLT Table!\n");
855 _rtl92cu_init_queue_reserved_page(hw
, wmm_enable
, out_ep_nums
,
857 _rtl92c_init_trx_buffer(hw
, wmm_enable
);
858 _rtl92cu_init_queue_priority(hw
, wmm_enable
, out_ep_nums
,
860 /* Get Rx PHY status in order to report RSSI and others. */
861 rtl92c_init_driver_info_size(hw
, RTL92C_DRIVER_INFO_SIZE
);
862 rtl92c_init_interrupt(hw
);
863 rtl92c_init_network_type(hw
);
864 _rtl92cu_init_wmac_setting(hw
);
865 rtl92c_init_adaptive_ctrl(hw
);
866 rtl92c_init_edca(hw
);
867 rtl92c_init_rate_fallback(hw
);
868 rtl92c_init_retry_function(hw
);
869 rtlpriv
->cfg
->ops
->set_bw_mode(hw
, NL80211_CHAN_HT20
);
870 rtl92c_set_min_space(hw
, IS_92C_SERIAL(rtlhal
->version
));
871 _rtl92cu_init_beacon_parameters(hw
);
872 rtl92c_init_ampdu_aggregation(hw
);
873 rtl92c_init_beacon_max_error(hw
);
877 void rtl92cu_enable_hw_security_config(struct ieee80211_hw
*hw
)
879 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
880 u8 sec_reg_value
= 0x0;
881 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
883 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
884 "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
885 rtlpriv
->sec
.pairwise_enc_algorithm
,
886 rtlpriv
->sec
.group_enc_algorithm
);
887 if (rtlpriv
->cfg
->mod_params
->sw_crypto
|| rtlpriv
->sec
.use_sw_sec
) {
888 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
889 "not open sw encryption\n");
892 sec_reg_value
= SCR_TxEncEnable
| SCR_RxDecEnable
;
893 if (rtlpriv
->sec
.use_defaultkey
) {
894 sec_reg_value
|= SCR_TxUseDK
;
895 sec_reg_value
|= SCR_RxUseDK
;
897 if (IS_NORMAL_CHIP(rtlhal
->version
))
898 sec_reg_value
|= (SCR_RXBCUSEDK
| SCR_TXBCUSEDK
);
899 rtl_write_byte(rtlpriv
, REG_CR
+ 1, 0x02);
900 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_LOUD
, "The SECR-value %x\n",
902 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_WPA_CONFIG
, &sec_reg_value
);
905 static void _rtl92cu_hw_configure(struct ieee80211_hw
*hw
)
907 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
908 struct rtl_usb
*rtlusb
= rtl_usbdev(rtl_usbpriv(hw
));
910 /* To Fix MAC loopback mode fail. */
911 rtl_write_byte(rtlpriv
, REG_LDOHCI12_CTRL
, 0x0f);
912 rtl_write_byte(rtlpriv
, 0x15, 0xe9);
914 /* set 0x0 to 0xFF by tynli. Default enable HW SEQ NUM. */
915 rtl_write_byte(rtlpriv
, REG_HWSEQ_CTRL
, 0xFF);
916 /* fixed USB interface interference issue */
917 rtl_write_byte(rtlpriv
, 0xfe40, 0xe0);
918 rtl_write_byte(rtlpriv
, 0xfe41, 0x8d);
919 rtl_write_byte(rtlpriv
, 0xfe42, 0x80);
920 rtlusb
->reg_bcn_ctrl_val
= 0x18;
921 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, (u8
)rtlusb
->reg_bcn_ctrl_val
);
924 static void _InitPABias(struct ieee80211_hw
*hw
)
926 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
927 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
930 /* FIXED PA current issue */
931 pa_setting
= efuse_read_1byte(hw
, 0x1FA);
932 if (!(pa_setting
& BIT(0))) {
933 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x15, 0x0FFFFF, 0x0F406);
934 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x15, 0x0FFFFF, 0x4F406);
935 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x15, 0x0FFFFF, 0x8F406);
936 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x15, 0x0FFFFF, 0xCF406);
938 if (!(pa_setting
& BIT(1)) && IS_NORMAL_CHIP(rtlhal
->version
) &&
939 IS_92C_SERIAL(rtlhal
->version
)) {
940 rtl_set_rfreg(hw
, RF90_PATH_B
, 0x15, 0x0FFFFF, 0x0F406);
941 rtl_set_rfreg(hw
, RF90_PATH_B
, 0x15, 0x0FFFFF, 0x4F406);
942 rtl_set_rfreg(hw
, RF90_PATH_B
, 0x15, 0x0FFFFF, 0x8F406);
943 rtl_set_rfreg(hw
, RF90_PATH_B
, 0x15, 0x0FFFFF, 0xCF406);
945 if (!(pa_setting
& BIT(4))) {
946 pa_setting
= rtl_read_byte(rtlpriv
, 0x16);
948 rtl_write_byte(rtlpriv
, 0x16, pa_setting
| 0x90);
952 int rtl92cu_hw_init(struct ieee80211_hw
*hw
)
954 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
955 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
956 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
957 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
958 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
962 /* As this function can take a very long time (up to 350 ms)
963 * and can be called with irqs disabled, reenable the irqs
964 * to let the other devices continue being serviced.
966 * It is safe doing so since our own interrupts will only be enabled
967 * in a subsequent step.
969 local_save_flags(flags
);
972 rtlhal
->fw_ready
= false;
973 rtlhal
->hw_type
= HARDWARE_TYPE_RTL8192CU
;
974 err
= _rtl92cu_init_mac(hw
);
976 pr_err("init mac failed!\n");
979 err
= rtl92c_download_fw(hw
);
981 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
982 "Failed to download FW. Init HW without FW now..\n");
987 rtlhal
->fw_ready
= true;
988 rtlhal
->last_hmeboxnum
= 0; /* h2c */
989 _rtl92cu_phy_param_tab_init(hw
);
990 rtl92cu_phy_mac_config(hw
);
991 rtl92cu_phy_bb_config(hw
);
992 rtlphy
->rf_mode
= RF_OP_BY_SW_3WIRE
;
993 rtl92c_phy_rf_config(hw
);
994 if (IS_VENDOR_UMC_A_CUT(rtlhal
->version
) &&
995 !IS_92C_SERIAL(rtlhal
->version
)) {
996 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_RX_G1
, MASKDWORD
, 0x30255);
997 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_RX_G2
, MASKDWORD
, 0x50a00);
999 rtlphy
->rfreg_chnlval
[0] = rtl_get_rfreg(hw
, (enum radio_path
)0,
1000 RF_CHNLBW
, RFREG_OFFSET_MASK
);
1001 rtlphy
->rfreg_chnlval
[1] = rtl_get_rfreg(hw
, (enum radio_path
)1,
1002 RF_CHNLBW
, RFREG_OFFSET_MASK
);
1003 rtl92cu_bb_block_on(hw
);
1004 rtl_cam_reset_all_entry(hw
);
1005 rtl92cu_enable_hw_security_config(hw
);
1006 ppsc
->rfpwr_state
= ERFON
;
1007 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ETHER_ADDR
, mac
->mac_addr
);
1008 if (ppsc
->rfpwr_state
== ERFON
) {
1009 rtl92c_phy_set_rfpath_switch(hw
, 1);
1010 if (rtlphy
->iqk_initialized
) {
1011 rtl92c_phy_iq_calibrate(hw
, true);
1013 rtl92c_phy_iq_calibrate(hw
, false);
1014 rtlphy
->iqk_initialized
= true;
1016 rtl92c_dm_check_txpower_tracking(hw
);
1017 rtl92c_phy_lc_calibrate(hw
);
1019 _rtl92cu_hw_configure(hw
);
1023 local_irq_restore(flags
);
1027 static void _DisableRFAFEAndResetBB(struct ieee80211_hw
*hw
)
1029 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1030 /**************************************
1031 a. TXPAUSE 0x522[7:0] = 0xFF Pause MAC TX queue
1032 b. RF path 0 offset 0x00 = 0x00 disable RF
1033 c. APSD_CTRL 0x600[7:0] = 0x40
1034 d. SYS_FUNC_EN 0x02[7:0] = 0x16 reset BB state machine
1035 e. SYS_FUNC_EN 0x02[7:0] = 0x14 reset BB state machine
1036 ***************************************/
1037 u8 eRFPath
= 0, value8
= 0;
1038 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0xFF);
1039 rtl_set_rfreg(hw
, (enum radio_path
)eRFPath
, 0x0, MASKBYTE0
, 0x0);
1042 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, value8
); /*0x40*/
1044 value8
|= (FEN_USBD
| FEN_USBA
| FEN_BB_GLB_RSTn
);
1045 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, value8
);/*0x16*/
1046 value8
&= (~FEN_BB_GLB_RSTn
);
1047 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, value8
); /*0x14*/
1050 static void _ResetDigitalProcedure1(struct ieee80211_hw
*hw
, bool bWithoutHWSM
)
1052 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1053 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1055 if (rtlhal
->fw_version
<= 0x20) {
1056 /*****************************
1057 f. MCUFWDL 0x80[7:0]=0 reset MCU ready status
1058 g. SYS_FUNC_EN 0x02[10]= 0 reset MCU reg, (8051 reset)
1059 h. SYS_FUNC_EN 0x02[15-12]= 5 reset MAC reg, DCORE
1060 i. SYS_FUNC_EN 0x02[10]= 1 enable MCU reg, (8051 enable)
1061 ******************************/
1064 rtl_write_byte(rtlpriv
, REG_MCUFWDL
, 0);
1065 valu16
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
1066 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (valu16
&
1067 (~FEN_CPUEN
))); /* reset MCU ,8051 */
1068 valu16
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
)&0x0FFF;
1069 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (valu16
|
1070 (FEN_HWPDN
|FEN_ELDR
))); /* reset MAC */
1071 valu16
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
1072 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (valu16
|
1073 FEN_CPUEN
)); /* enable MCU ,8051 */
1077 /* IF fw in RAM code, do reset */
1078 if (rtl_read_byte(rtlpriv
, REG_MCUFWDL
) & BIT(1)) {
1079 /* reset MCU ready status */
1080 rtl_write_byte(rtlpriv
, REG_MCUFWDL
, 0);
1081 /* 8051 reset by self */
1082 rtl_write_byte(rtlpriv
, REG_HMETFR
+3, 0x20);
1083 while ((retry_cnts
++ < 100) &&
1084 (FEN_CPUEN
& rtl_read_word(rtlpriv
,
1085 REG_SYS_FUNC_EN
))) {
1088 if (retry_cnts
>= 100) {
1089 pr_err("8051 reset failed!.........................\n");
1090 /* if 8051 reset fail, reset MAC. */
1091 rtl_write_byte(rtlpriv
,
1092 REG_SYS_FUNC_EN
+ 1,
1097 /* Reset MAC and Enable 8051 */
1098 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, 0x54);
1099 rtl_write_byte(rtlpriv
, REG_MCUFWDL
, 0);
1102 /*****************************
1103 Without HW auto state machine
1104 g.SYS_CLKR 0x08[15:0] = 0x30A3 disable MAC clock
1105 h.AFE_PLL_CTRL 0x28[7:0] = 0x80 disable AFE PLL
1106 i.AFE_XTAL_CTRL 0x24[15:0] = 0x880F gated AFE DIG_CLOCK
1107 j.SYS_ISu_CTRL 0x00[7:0] = 0xF9 isolated digital to PON
1108 ******************************/
1109 rtl_write_word(rtlpriv
, REG_SYS_CLKR
, 0x70A3);
1110 rtl_write_byte(rtlpriv
, REG_AFE_PLL_CTRL
, 0x80);
1111 rtl_write_word(rtlpriv
, REG_AFE_XTAL_CTRL
, 0x880F);
1112 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
, 0xF9);
1116 static void _ResetDigitalProcedure2(struct ieee80211_hw
*hw
)
1118 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1119 /*****************************
1120 k. SYS_FUNC_EN 0x03[7:0] = 0x44 disable ELDR runction
1121 l. SYS_CLKR 0x08[15:0] = 0x3083 disable ELDR clock
1122 m. SYS_ISO_CTRL 0x01[7:0] = 0x83 isolated ELDR to PON
1123 ******************************/
1124 rtl_write_word(rtlpriv
, REG_SYS_CLKR
, 0x70A3);
1125 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
+1, 0x82);
1128 static void _DisableGPIO(struct ieee80211_hw
*hw
)
1130 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1131 /***************************************
1132 j. GPIO_PIN_CTRL 0x44[31:0]=0x000
1133 k. Value = GPIO_PIN_CTRL[7:0]
1134 l. GPIO_PIN_CTRL 0x44[31:0] = 0x00FF0000 | (value <<8); write ext PIN level
1135 m. GPIO_MUXCFG 0x42 [15:0] = 0x0780
1136 n. LEDCFG 0x4C[15:0] = 0x8080
1137 ***************************************/
1142 /* 1. Disable GPIO[7:0] */
1143 rtl_write_word(rtlpriv
, REG_GPIO_PIN_CTRL
+2, 0x0000);
1144 value32
= rtl_read_dword(rtlpriv
, REG_GPIO_PIN_CTRL
) & 0xFFFF00FF;
1145 value8
= (u8
)(value32
&0x000000FF);
1146 value32
|= ((value8
<<8) | 0x00FF0000);
1147 rtl_write_dword(rtlpriv
, REG_GPIO_PIN_CTRL
, value32
);
1148 /* 2. Disable GPIO[10:8] */
1149 rtl_write_byte(rtlpriv
, REG_GPIO_MUXCFG
+3, 0x00);
1150 value16
= rtl_read_word(rtlpriv
, REG_GPIO_MUXCFG
+2) & 0xFF0F;
1151 value8
= (u8
)(value16
&0x000F);
1152 value16
|= ((value8
<<4) | 0x0780);
1153 rtl_write_word(rtlpriv
, REG_GPIO_PIN_CTRL
+2, value16
);
1154 /* 3. Disable LED0 & 1 */
1155 rtl_write_word(rtlpriv
, REG_LEDCFG0
, 0x8080);
1158 static void _DisableAnalog(struct ieee80211_hw
*hw
, bool bWithoutHWSM
)
1160 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1165 /*****************************
1166 n. LDOA15_CTRL 0x20[7:0] = 0x04 disable A15 power
1167 o. LDOV12D_CTRL 0x21[7:0] = 0x54 disable digital core power
1168 r. When driver call disable, the ASIC will turn off remaining
1170 ******************************/
1171 rtl_write_byte(rtlpriv
, REG_LDOA15_CTRL
, 0x04);
1172 value8
= rtl_read_byte(rtlpriv
, REG_LDOV12D_CTRL
);
1173 value8
&= (~LDV12_EN
);
1174 rtl_write_byte(rtlpriv
, REG_LDOV12D_CTRL
, value8
);
1177 /*****************************
1178 h. SPS0_CTRL 0x11[7:0] = 0x23 enter PFM mode
1179 i. APS_FSMCO 0x04[15:0] = 0x4802 set USB suspend
1180 ******************************/
1181 rtl_write_byte(rtlpriv
, REG_SPS0_CTRL
, 0x23);
1182 value16
|= (APDM_HOST
| AFSM_HSUS
| PFM_ALDN
);
1183 rtl_write_word(rtlpriv
, REG_APS_FSMCO
, (u16
)value16
);
1184 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x0E);
1187 static void _CardDisableHWSM(struct ieee80211_hw
*hw
)
1189 /* ==== RF Off Sequence ==== */
1190 _DisableRFAFEAndResetBB(hw
);
1191 /* ==== Reset digital sequence ====== */
1192 _ResetDigitalProcedure1(hw
, false);
1193 /* ==== Pull GPIO PIN to balance level and LED control ====== */
1195 /* ==== Disable analog sequence === */
1196 _DisableAnalog(hw
, false);
1199 static void _CardDisableWithoutHWSM(struct ieee80211_hw
*hw
)
1201 /*==== RF Off Sequence ==== */
1202 _DisableRFAFEAndResetBB(hw
);
1203 /* ==== Reset digital sequence ====== */
1204 _ResetDigitalProcedure1(hw
, true);
1205 /* ==== Pull GPIO PIN to balance level and LED control ====== */
1207 /* ==== Reset digital sequence ====== */
1208 _ResetDigitalProcedure2(hw
);
1209 /* ==== Disable analog sequence === */
1210 _DisableAnalog(hw
, true);
1213 static void _rtl92cu_set_bcn_ctrl_reg(struct ieee80211_hw
*hw
,
1214 u8 set_bits
, u8 clear_bits
)
1216 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1217 struct rtl_usb
*rtlusb
= rtl_usbdev(rtl_usbpriv(hw
));
1219 rtlusb
->reg_bcn_ctrl_val
|= set_bits
;
1220 rtlusb
->reg_bcn_ctrl_val
&= ~clear_bits
;
1221 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, (u8
)rtlusb
->reg_bcn_ctrl_val
);
1224 static void _rtl92cu_stop_tx_beacon(struct ieee80211_hw
*hw
)
1226 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1227 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1229 if (IS_NORMAL_CHIP(rtlhal
->version
)) {
1230 tmp1byte
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
1231 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2,
1232 tmp1byte
& (~BIT(6)));
1233 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0x64);
1234 tmp1byte
= rtl_read_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2);
1235 tmp1byte
&= ~(BIT(0));
1236 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2, tmp1byte
);
1238 rtl_write_byte(rtlpriv
, REG_TXPAUSE
,
1239 rtl_read_byte(rtlpriv
, REG_TXPAUSE
) | BIT(6));
1243 static void _rtl92cu_resume_tx_beacon(struct ieee80211_hw
*hw
)
1245 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1246 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1249 if (IS_NORMAL_CHIP(rtlhal
->version
)) {
1250 tmp1byte
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
1251 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2,
1253 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0xff);
1254 tmp1byte
= rtl_read_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2);
1256 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2, tmp1byte
);
1258 rtl_write_byte(rtlpriv
, REG_TXPAUSE
,
1259 rtl_read_byte(rtlpriv
, REG_TXPAUSE
) & (~BIT(6)));
1263 static void _rtl92cu_enable_bcn_sub_func(struct ieee80211_hw
*hw
)
1265 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1266 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1268 if (IS_NORMAL_CHIP(rtlhal
->version
))
1269 _rtl92cu_set_bcn_ctrl_reg(hw
, 0, BIT(1));
1271 _rtl92cu_set_bcn_ctrl_reg(hw
, 0, BIT(4));
1274 static void _rtl92cu_disable_bcn_sub_func(struct ieee80211_hw
*hw
)
1276 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1277 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1279 if (IS_NORMAL_CHIP(rtlhal
->version
))
1280 _rtl92cu_set_bcn_ctrl_reg(hw
, BIT(1), 0);
1282 _rtl92cu_set_bcn_ctrl_reg(hw
, BIT(4), 0);
1285 static int _rtl92cu_set_media_status(struct ieee80211_hw
*hw
,
1286 enum nl80211_iftype type
)
1288 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1289 u8 bt_msr
= rtl_read_byte(rtlpriv
, MSR
);
1290 enum led_ctl_mode ledaction
= LED_CTL_NO_LINK
;
1293 if (type
== NL80211_IFTYPE_UNSPECIFIED
|| type
==
1294 NL80211_IFTYPE_STATION
) {
1295 _rtl92cu_stop_tx_beacon(hw
);
1296 _rtl92cu_enable_bcn_sub_func(hw
);
1297 } else if (type
== NL80211_IFTYPE_ADHOC
|| type
== NL80211_IFTYPE_AP
) {
1298 _rtl92cu_resume_tx_beacon(hw
);
1299 _rtl92cu_disable_bcn_sub_func(hw
);
1301 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1302 "Set HW_VAR_MEDIA_STATUS:No such media status(%x)\n",
1306 case NL80211_IFTYPE_UNSPECIFIED
:
1307 bt_msr
|= MSR_NOLINK
;
1308 ledaction
= LED_CTL_LINK
;
1309 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1310 "Set Network type to NO LINK!\n");
1312 case NL80211_IFTYPE_ADHOC
:
1313 bt_msr
|= MSR_ADHOC
;
1314 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1315 "Set Network type to Ad Hoc!\n");
1317 case NL80211_IFTYPE_STATION
:
1318 bt_msr
|= MSR_INFRA
;
1319 ledaction
= LED_CTL_LINK
;
1320 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1321 "Set Network type to STA!\n");
1323 case NL80211_IFTYPE_AP
:
1325 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1326 "Set Network type to AP!\n");
1329 pr_err("Network type %d not supported!\n", type
);
1332 rtl_write_byte(rtlpriv
, MSR
, bt_msr
);
1333 rtlpriv
->cfg
->ops
->led_control(hw
, ledaction
);
1334 if ((bt_msr
& MSR_MASK
) == MSR_AP
)
1335 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x00);
1337 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x66);
1343 void rtl92cu_card_disable(struct ieee80211_hw
*hw
)
1345 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1346 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1347 struct rtl_usb
*rtlusb
= rtl_usbdev(rtl_usbpriv(hw
));
1348 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1349 enum nl80211_iftype opmode
;
1351 mac
->link_state
= MAC80211_NOLINK
;
1352 opmode
= NL80211_IFTYPE_UNSPECIFIED
;
1353 _rtl92cu_set_media_status(hw
, opmode
);
1354 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_POWER_OFF
);
1355 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
1356 if (rtlusb
->disableHWSM
)
1357 _CardDisableHWSM(hw
);
1359 _CardDisableWithoutHWSM(hw
);
1361 /* after power off we should do iqk again */
1362 rtlpriv
->phy
.iqk_initialized
= false;
1365 void rtl92cu_set_check_bssid(struct ieee80211_hw
*hw
, bool check_bssid
)
1367 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1368 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1371 if (rtlpriv
->psc
.rfpwr_state
!= ERFON
)
1374 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RCR
, (u8
*)(®_rcr
));
1378 if (IS_NORMAL_CHIP(rtlhal
->version
)) {
1379 reg_rcr
|= (RCR_CBSSID_DATA
| RCR_CBSSID_BCN
);
1382 reg_rcr
|= RCR_CBSSID
;
1383 tmp
= BIT(4) | BIT(5);
1385 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
,
1387 _rtl92cu_set_bcn_ctrl_reg(hw
, 0, tmp
);
1390 if (IS_NORMAL_CHIP(rtlhal
->version
)) {
1391 reg_rcr
&= ~(RCR_CBSSID_DATA
| RCR_CBSSID_BCN
);
1394 reg_rcr
&= ~RCR_CBSSID
;
1395 tmp
= BIT(4) | BIT(5);
1397 reg_rcr
&= (~(RCR_CBSSID_DATA
| RCR_CBSSID_BCN
));
1398 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1399 HW_VAR_RCR
, (u8
*) (®_rcr
));
1400 _rtl92cu_set_bcn_ctrl_reg(hw
, tmp
, 0);
1404 /*========================================================================== */
1406 int rtl92cu_set_network_type(struct ieee80211_hw
*hw
, enum nl80211_iftype type
)
1408 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1410 if (_rtl92cu_set_media_status(hw
, type
))
1413 if (rtlpriv
->mac80211
.link_state
== MAC80211_LINKED
) {
1414 if (type
!= NL80211_IFTYPE_AP
)
1415 rtl92cu_set_check_bssid(hw
, true);
1417 rtl92cu_set_check_bssid(hw
, false);
1423 static void _beacon_function_enable(struct ieee80211_hw
*hw
)
1425 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1427 _rtl92cu_set_bcn_ctrl_reg(hw
, (BIT(4) | BIT(3) | BIT(1)), 0x00);
1428 rtl_write_byte(rtlpriv
, REG_RD_CTRL
+1, 0x6F);
1431 void rtl92cu_set_beacon_related_registers(struct ieee80211_hw
*hw
)
1434 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1435 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1436 u16 bcn_interval
, atim_window
;
1439 bcn_interval
= mac
->beacon_interval
;
1440 atim_window
= 2; /*FIX MERGE */
1441 rtl_write_word(rtlpriv
, REG_ATIMWND
, atim_window
);
1442 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
1443 _rtl92cu_init_beacon_parameters(hw
);
1444 rtl_write_byte(rtlpriv
, REG_SLOT
, 0x09);
1446 * Force beacon frame transmission even after receiving beacon frame
1447 * from other ad hoc STA
1450 * Reset TSF Timer to zero, added by Roger. 2008.06.24
1452 value32
= rtl_read_dword(rtlpriv
, REG_TCR
);
1454 rtl_write_dword(rtlpriv
, REG_TCR
, value32
);
1456 rtl_write_dword(rtlpriv
, REG_TCR
, value32
);
1457 RT_TRACE(rtlpriv
, COMP_INIT
|COMP_BEACON
, DBG_LOUD
,
1458 "SetBeaconRelatedRegisters8192CUsb(): Set TCR(%x)\n",
1460 /* TODO: Modify later (Find the right parameters)
1461 * NOTE: Fix test chip's bug (about contention windows's randomness) */
1462 if ((mac
->opmode
== NL80211_IFTYPE_ADHOC
) ||
1463 (mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) ||
1464 (mac
->opmode
== NL80211_IFTYPE_AP
)) {
1465 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_CCK
, 0x50);
1466 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_OFDM
, 0x50);
1468 _beacon_function_enable(hw
);
1471 void rtl92cu_set_beacon_interval(struct ieee80211_hw
*hw
)
1473 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1474 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1475 u16 bcn_interval
= mac
->beacon_interval
;
1477 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_DMESG
, "beacon_interval:%d\n",
1479 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
1482 void rtl92cu_update_interrupt_mask(struct ieee80211_hw
*hw
,
1483 u32 add_msr
, u32 rm_msr
)
1487 void rtl92cu_get_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
1489 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1490 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1491 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1495 *((u32
*)(val
)) = mac
->rx_conf
;
1497 case HW_VAR_RF_STATE
:
1498 *((enum rf_pwrstate
*)(val
)) = ppsc
->rfpwr_state
;
1500 case HW_VAR_FWLPS_RF_ON
:{
1501 enum rf_pwrstate rfState
;
1504 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RF_STATE
,
1506 if (rfState
== ERFOFF
) {
1507 *((bool *) (val
)) = true;
1509 val_rcr
= rtl_read_dword(rtlpriv
, REG_RCR
);
1510 val_rcr
&= 0x00070000;
1512 *((bool *) (val
)) = false;
1514 *((bool *) (val
)) = true;
1518 case HW_VAR_FW_PSMODE_STATUS
:
1519 *((bool *) (val
)) = ppsc
->fw_current_inpsmode
;
1521 case HW_VAR_CORRECT_TSF
:{
1523 u32
*ptsf_low
= (u32
*)&tsf
;
1524 u32
*ptsf_high
= ((u32
*)&tsf
) + 1;
1526 *ptsf_high
= rtl_read_dword(rtlpriv
, (REG_TSFTR
+ 4));
1527 *ptsf_low
= rtl_read_dword(rtlpriv
, REG_TSFTR
);
1528 *((u64
*)(val
)) = tsf
;
1531 case HW_VAR_MGT_FILTER
:
1532 *((u16
*) (val
)) = rtl_read_word(rtlpriv
, REG_RXFLTMAP0
);
1534 case HW_VAR_CTRL_FILTER
:
1535 *((u16
*) (val
)) = rtl_read_word(rtlpriv
, REG_RXFLTMAP1
);
1537 case HW_VAR_DATA_FILTER
:
1538 *((u16
*) (val
)) = rtl_read_word(rtlpriv
, REG_RXFLTMAP2
);
1540 case HAL_DEF_WOWLAN
:
1543 pr_err("switch case %#x not processed\n", variable
);
1548 static bool usb_cmd_send_packet(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1550 /* Currently nothing happens here.
1551 * Traffic stops after some seconds in WPA2 802.11n mode.
1552 * Maybe because rtl8192cu chip should be set from here?
1553 * If I understand correctly, the realtek vendor driver sends some urbs
1556 * This is maybe necessary:
1557 * rtlpriv->cfg->ops->fill_tx_cmddesc(hw, buffer, 1, 1, skb);
1562 void rtl92cu_set_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
1564 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1565 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1566 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1567 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1568 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1569 enum wireless_mode wirelessmode
= mac
->mode
;
1573 case HW_VAR_ETHER_ADDR
:{
1574 for (idx
= 0; idx
< ETH_ALEN
; idx
++) {
1575 rtl_write_byte(rtlpriv
, (REG_MACID
+ idx
),
1580 case HW_VAR_BASIC_RATE
:{
1581 u16 rate_cfg
= ((u16
*) val
)[0];
1586 /* if (mac->current_network.vender == HT_IOT_PEER_CISCO
1587 * && ((rate_cfg & 0x150) == 0)) {
1588 * rate_cfg |= 0x010;
1591 rtl_write_byte(rtlpriv
, REG_RRSR
, rate_cfg
& 0xff);
1592 rtl_write_byte(rtlpriv
, REG_RRSR
+ 1,
1593 (rate_cfg
>> 8) & 0xff);
1594 while (rate_cfg
> 0x1) {
1598 rtl_write_byte(rtlpriv
, REG_INIRTS_RATE_SEL
,
1603 for (idx
= 0; idx
< ETH_ALEN
; idx
++) {
1604 rtl_write_byte(rtlpriv
, (REG_BSSID
+ idx
),
1610 rtl_write_byte(rtlpriv
, REG_SIFS_CCK
+ 1, val
[0]);
1611 rtl_write_byte(rtlpriv
, REG_SIFS_OFDM
+ 1, val
[1]);
1612 rtl_write_byte(rtlpriv
, REG_SPEC_SIFS
+ 1, val
[0]);
1613 rtl_write_byte(rtlpriv
, REG_MAC_SPEC_SIFS
+ 1, val
[0]);
1614 rtl_write_byte(rtlpriv
, REG_R2T_SIFS
+1, val
[0]);
1615 rtl_write_byte(rtlpriv
, REG_T2T_SIFS
+1, val
[0]);
1616 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
, "HW_VAR_SIFS\n");
1619 case HW_VAR_SLOT_TIME
:{
1623 rtl_write_byte(rtlpriv
, REG_SLOT
, val
[0]);
1624 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
1625 "HW_VAR_SLOT_TIME %x\n", val
[0]);
1627 for (e_aci
= 0; e_aci
< AC_MAX
; e_aci
++)
1628 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1635 if (IS_WIRELESS_MODE_A(wirelessmode
) ||
1636 IS_WIRELESS_MODE_N_24G(wirelessmode
) ||
1637 IS_WIRELESS_MODE_N_5G(wirelessmode
))
1641 u1bAIFS
= sifstime
+ (2 * val
[0]);
1642 rtl_write_byte(rtlpriv
, REG_EDCA_VO_PARAM
,
1644 rtl_write_byte(rtlpriv
, REG_EDCA_VI_PARAM
,
1646 rtl_write_byte(rtlpriv
, REG_EDCA_BE_PARAM
,
1648 rtl_write_byte(rtlpriv
, REG_EDCA_BK_PARAM
,
1653 case HW_VAR_ACK_PREAMBLE
:{
1655 u8 short_preamble
= (bool)*val
;
1659 rtl_write_byte(rtlpriv
, REG_RRSR
+ 2, reg_tmp
);
1662 case HW_VAR_AMPDU_MIN_SPACE
:{
1663 u8 min_spacing_to_set
;
1666 min_spacing_to_set
= *val
;
1667 if (min_spacing_to_set
<= 7) {
1668 switch (rtlpriv
->sec
.pairwise_enc_algorithm
) {
1670 case AESCCMP_ENCRYPTION
:
1673 case WEP40_ENCRYPTION
:
1674 case WEP104_ENCRYPTION
:
1675 case TKIP_ENCRYPTION
:
1682 if (min_spacing_to_set
< sec_min_space
)
1683 min_spacing_to_set
= sec_min_space
;
1684 mac
->min_space_cfg
= ((mac
->min_space_cfg
&
1686 min_spacing_to_set
);
1687 *val
= min_spacing_to_set
;
1688 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
1689 "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
1690 mac
->min_space_cfg
);
1691 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
1692 mac
->min_space_cfg
);
1696 case HW_VAR_SHORTGI_DENSITY
:{
1699 density_to_set
= *val
;
1700 density_to_set
&= 0x1f;
1701 mac
->min_space_cfg
&= 0x07;
1702 mac
->min_space_cfg
|= (density_to_set
<< 3);
1703 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
1704 "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
1705 mac
->min_space_cfg
);
1706 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
1707 mac
->min_space_cfg
);
1710 case HW_VAR_AMPDU_FACTOR
:{
1711 u8 regtoset_normal
[4] = {0x41, 0xa8, 0x72, 0xb9};
1713 u8
*p_regtoset
= NULL
;
1716 p_regtoset
= regtoset_normal
;
1717 factor_toset
= *val
;
1718 if (factor_toset
<= 3) {
1719 factor_toset
= (1 << (factor_toset
+ 2));
1720 if (factor_toset
> 0xf)
1722 for (index
= 0; index
< 4; index
++) {
1723 if ((p_regtoset
[index
] & 0xf0) >
1724 (factor_toset
<< 4))
1726 (p_regtoset
[index
] & 0x0f)
1727 | (factor_toset
<< 4);
1728 if ((p_regtoset
[index
] & 0x0f) >
1731 (p_regtoset
[index
] & 0xf0)
1733 rtl_write_byte(rtlpriv
,
1734 (REG_AGGLEN_LMT
+ index
),
1737 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
1738 "Set HW_VAR_AMPDU_FACTOR: %#x\n",
1743 case HW_VAR_AC_PARAM
:{
1746 u16 cw_min
= le16_to_cpu(mac
->ac
[e_aci
].cw_min
);
1747 u16 cw_max
= le16_to_cpu(mac
->ac
[e_aci
].cw_max
);
1748 u16 tx_op
= le16_to_cpu(mac
->ac
[e_aci
].tx_op
);
1750 u4b_ac_param
= (u32
) mac
->ac
[e_aci
].aifs
;
1751 u4b_ac_param
|= (u32
) ((cw_min
& 0xF) <<
1752 AC_PARAM_ECW_MIN_OFFSET
);
1753 u4b_ac_param
|= (u32
) ((cw_max
& 0xF) <<
1754 AC_PARAM_ECW_MAX_OFFSET
);
1755 u4b_ac_param
|= (u32
) tx_op
<< AC_PARAM_TXOP_OFFSET
;
1756 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
1757 "queue:%x, ac_param:%x\n",
1758 e_aci
, u4b_ac_param
);
1761 rtl_write_dword(rtlpriv
, REG_EDCA_BK_PARAM
,
1765 rtl_write_dword(rtlpriv
, REG_EDCA_BE_PARAM
,
1769 rtl_write_dword(rtlpriv
, REG_EDCA_VI_PARAM
,
1773 rtl_write_dword(rtlpriv
, REG_EDCA_VO_PARAM
,
1777 WARN_ONCE(true, "rtl8192cu: invalid aci: %d !\n",
1784 rtl_write_dword(rtlpriv
, REG_RCR
, ((u32
*) (val
))[0]);
1785 mac
->rx_conf
= ((u32
*) (val
))[0];
1786 RT_TRACE(rtlpriv
, COMP_RECV
, DBG_DMESG
,
1787 "### Set RCR(0x%08x) ###\n", mac
->rx_conf
);
1790 case HW_VAR_RETRY_LIMIT
:{
1791 u8 retry_limit
= val
[0];
1793 rtl_write_word(rtlpriv
, REG_RL
,
1794 retry_limit
<< RETRY_LIMIT_SHORT_SHIFT
|
1795 retry_limit
<< RETRY_LIMIT_LONG_SHIFT
);
1796 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_DMESG
,
1797 "Set HW_VAR_RETRY_LIMIT(0x%08x)\n",
1801 case HW_VAR_DUAL_TSF_RST
:
1802 rtl_write_byte(rtlpriv
, REG_DUAL_TSF_RST
, (BIT(0) | BIT(1)));
1804 case HW_VAR_EFUSE_BYTES
:
1805 rtlefuse
->efuse_usedbytes
= *((u16
*) val
);
1807 case HW_VAR_EFUSE_USAGE
:
1808 rtlefuse
->efuse_usedpercentage
= *val
;
1811 rtl92c_phy_set_io_cmd(hw
, (*(enum io_type
*)val
));
1813 case HW_VAR_WPA_CONFIG
:
1814 rtl_write_byte(rtlpriv
, REG_SECCFG
, *val
);
1816 case HW_VAR_SET_RPWM
:{
1817 u8 rpwm_val
= rtl_read_byte(rtlpriv
, REG_USB_HRPWM
);
1819 if (rpwm_val
& BIT(7))
1820 rtl_write_byte(rtlpriv
, REG_USB_HRPWM
, *val
);
1822 rtl_write_byte(rtlpriv
, REG_USB_HRPWM
,
1826 case HW_VAR_H2C_FW_PWRMODE
:{
1829 if ((psmode
!= FW_PS_ACTIVE_MODE
) &&
1830 (!IS_92C_SERIAL(rtlhal
->version
)))
1831 rtl92c_dm_rf_saving(hw
, true);
1832 rtl92c_set_fw_pwrmode_cmd(hw
, (*val
));
1835 case HW_VAR_FW_PSMODE_STATUS
:
1836 ppsc
->fw_current_inpsmode
= *((bool *) val
);
1838 case HW_VAR_H2C_FW_JOINBSSRPT
:{
1841 bool recover
= false;
1843 if (mstatus
== RT_MEDIA_CONNECT
) {
1844 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1846 rtl_write_byte(rtlpriv
, REG_CR
+ 1, 0x03);
1847 _rtl92cu_set_bcn_ctrl_reg(hw
, 0, BIT(3));
1848 _rtl92cu_set_bcn_ctrl_reg(hw
, BIT(4), 0);
1849 tmp_reg422
= rtl_read_byte(rtlpriv
,
1850 REG_FWHW_TXQ_CTRL
+ 2);
1851 if (tmp_reg422
& BIT(6))
1853 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2,
1854 tmp_reg422
& (~BIT(6)));
1855 rtl92c_set_fw_rsvdpagepkt(hw
,
1856 &usb_cmd_send_packet
);
1857 _rtl92cu_set_bcn_ctrl_reg(hw
, BIT(3), 0);
1858 _rtl92cu_set_bcn_ctrl_reg(hw
, 0, BIT(4));
1860 rtl_write_byte(rtlpriv
,
1861 REG_FWHW_TXQ_CTRL
+ 2,
1862 tmp_reg422
| BIT(6));
1863 rtl_write_byte(rtlpriv
, REG_CR
+ 1, 0x02);
1865 rtl92c_set_fw_joinbss_report_cmd(hw
, (*val
));
1871 u2btmp
= rtl_read_word(rtlpriv
, REG_BCN_PSR_RPT
);
1873 rtl_write_word(rtlpriv
, REG_BCN_PSR_RPT
,
1874 (u2btmp
| mac
->assoc_id
));
1877 case HW_VAR_CORRECT_TSF
:{
1878 u8 btype_ibss
= val
[0];
1881 _rtl92cu_stop_tx_beacon(hw
);
1882 _rtl92cu_set_bcn_ctrl_reg(hw
, 0, BIT(3));
1883 rtl_write_dword(rtlpriv
, REG_TSFTR
, (u32
)(mac
->tsf
&
1885 rtl_write_dword(rtlpriv
, REG_TSFTR
+ 4,
1886 (u32
)((mac
->tsf
>> 32) & 0xffffffff));
1887 _rtl92cu_set_bcn_ctrl_reg(hw
, BIT(3), 0);
1889 _rtl92cu_resume_tx_beacon(hw
);
1892 case HW_VAR_MGT_FILTER
:
1893 rtl_write_word(rtlpriv
, REG_RXFLTMAP0
, *(u16
*)val
);
1894 mac
->rx_mgt_filter
= *(u16
*)val
;
1896 case HW_VAR_CTRL_FILTER
:
1897 rtl_write_word(rtlpriv
, REG_RXFLTMAP1
, *(u16
*)val
);
1898 mac
->rx_ctrl_filter
= *(u16
*)val
;
1900 case HW_VAR_DATA_FILTER
:
1901 rtl_write_word(rtlpriv
, REG_RXFLTMAP2
, *(u16
*)val
);
1902 mac
->rx_data_filter
= *(u16
*)val
;
1904 case HW_VAR_KEEP_ALIVE
:{
1907 array
[1] = *((u8
*)val
);
1908 rtl92c_fill_h2c_cmd(hw
, H2C_92C_KEEP_ALIVE_CTRL
, 2,
1913 pr_err("switch case %#x not processed\n", variable
);
1918 static void rtl92cu_update_hal_rate_table(struct ieee80211_hw
*hw
,
1919 struct ieee80211_sta
*sta
)
1921 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1922 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1923 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1924 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1927 u8 nmode
= mac
->ht_enable
;
1928 u8 mimo_ps
= IEEE80211_SMPS_OFF
;
1931 u8 curtxbw_40mhz
= mac
->bw_40
;
1932 u8 curshortgi_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
1934 u8 curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
1936 enum wireless_mode wirelessmode
= mac
->mode
;
1938 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
1939 ratr_value
= sta
->supp_rates
[1] << 4;
1941 ratr_value
= sta
->supp_rates
[0];
1942 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
1945 ratr_value
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
1946 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
1947 switch (wirelessmode
) {
1948 case WIRELESS_MODE_B
:
1949 if (ratr_value
& 0x0000000c)
1950 ratr_value
&= 0x0000000d;
1952 ratr_value
&= 0x0000000f;
1954 case WIRELESS_MODE_G
:
1955 ratr_value
&= 0x00000FF5;
1957 case WIRELESS_MODE_N_24G
:
1958 case WIRELESS_MODE_N_5G
:
1960 if (mimo_ps
== IEEE80211_SMPS_STATIC
) {
1961 ratr_value
&= 0x0007F005;
1965 if (get_rf_type(rtlphy
) == RF_1T2R
||
1966 get_rf_type(rtlphy
) == RF_1T1R
)
1967 ratr_mask
= 0x000ff005;
1969 ratr_mask
= 0x0f0ff005;
1971 ratr_value
&= ratr_mask
;
1975 if (rtlphy
->rf_type
== RF_1T2R
)
1976 ratr_value
&= 0x000ff0ff;
1978 ratr_value
&= 0x0f0ff0ff;
1983 ratr_value
&= 0x0FFFFFFF;
1985 if (nmode
&& ((curtxbw_40mhz
&&
1986 curshortgi_40mhz
) || (!curtxbw_40mhz
&&
1987 curshortgi_20mhz
))) {
1989 ratr_value
|= 0x10000000;
1990 tmp_ratr_value
= (ratr_value
>> 12);
1992 for (shortgi_rate
= 15; shortgi_rate
> 0; shortgi_rate
--) {
1993 if ((1 << shortgi_rate
) & tmp_ratr_value
)
1997 shortgi_rate
= (shortgi_rate
<< 12) | (shortgi_rate
<< 8) |
1998 (shortgi_rate
<< 4) | (shortgi_rate
);
2001 rtl_write_dword(rtlpriv
, REG_ARFR0
+ ratr_index
* 4, ratr_value
);
2003 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
, "%x\n",
2004 rtl_read_dword(rtlpriv
, REG_ARFR0
));
2007 static void rtl92cu_update_hal_rate_mask(struct ieee80211_hw
*hw
,
2008 struct ieee80211_sta
*sta
,
2009 u8 rssi_level
, bool update_bw
)
2011 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2012 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2013 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2014 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2015 struct rtl_sta_info
*sta_entry
= NULL
;
2018 u8 curtxbw_40mhz
= (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
) ? 1 : 0;
2019 u8 curshortgi_40mhz
= curtxbw_40mhz
&&
2020 (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
2022 u8 curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
2024 enum wireless_mode wirelessmode
= 0;
2025 bool shortgi
= false;
2028 u8 mimo_ps
= IEEE80211_SMPS_OFF
;
2030 sta_entry
= (struct rtl_sta_info
*) sta
->drv_priv
;
2031 wirelessmode
= sta_entry
->wireless_mode
;
2032 if (mac
->opmode
== NL80211_IFTYPE_STATION
||
2033 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
)
2034 curtxbw_40mhz
= mac
->bw_40
;
2035 else if (mac
->opmode
== NL80211_IFTYPE_AP
||
2036 mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2037 macid
= sta
->aid
+ 1;
2039 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
2040 ratr_bitmap
= sta
->supp_rates
[1] << 4;
2042 ratr_bitmap
= sta
->supp_rates
[0];
2043 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2044 ratr_bitmap
= 0xfff;
2045 ratr_bitmap
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
2046 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
2047 switch (wirelessmode
) {
2048 case WIRELESS_MODE_B
:
2049 ratr_index
= RATR_INX_WIRELESS_B
;
2050 if (ratr_bitmap
& 0x0000000c)
2051 ratr_bitmap
&= 0x0000000d;
2053 ratr_bitmap
&= 0x0000000f;
2055 case WIRELESS_MODE_G
:
2056 ratr_index
= RATR_INX_WIRELESS_GB
;
2058 if (rssi_level
== 1)
2059 ratr_bitmap
&= 0x00000f00;
2060 else if (rssi_level
== 2)
2061 ratr_bitmap
&= 0x00000ff0;
2063 ratr_bitmap
&= 0x00000ff5;
2065 case WIRELESS_MODE_A
:
2066 ratr_index
= RATR_INX_WIRELESS_A
;
2067 ratr_bitmap
&= 0x00000ff0;
2069 case WIRELESS_MODE_N_24G
:
2070 case WIRELESS_MODE_N_5G
:
2071 ratr_index
= RATR_INX_WIRELESS_NGB
;
2073 if (mimo_ps
== IEEE80211_SMPS_STATIC
) {
2074 if (rssi_level
== 1)
2075 ratr_bitmap
&= 0x00070000;
2076 else if (rssi_level
== 2)
2077 ratr_bitmap
&= 0x0007f000;
2079 ratr_bitmap
&= 0x0007f005;
2081 if (rtlphy
->rf_type
== RF_1T2R
||
2082 rtlphy
->rf_type
== RF_1T1R
) {
2083 if (curtxbw_40mhz
) {
2084 if (rssi_level
== 1)
2085 ratr_bitmap
&= 0x000f0000;
2086 else if (rssi_level
== 2)
2087 ratr_bitmap
&= 0x000ff000;
2089 ratr_bitmap
&= 0x000ff015;
2091 if (rssi_level
== 1)
2092 ratr_bitmap
&= 0x000f0000;
2093 else if (rssi_level
== 2)
2094 ratr_bitmap
&= 0x000ff000;
2096 ratr_bitmap
&= 0x000ff005;
2099 if (curtxbw_40mhz
) {
2100 if (rssi_level
== 1)
2101 ratr_bitmap
&= 0x0f0f0000;
2102 else if (rssi_level
== 2)
2103 ratr_bitmap
&= 0x0f0ff000;
2105 ratr_bitmap
&= 0x0f0ff015;
2107 if (rssi_level
== 1)
2108 ratr_bitmap
&= 0x0f0f0000;
2109 else if (rssi_level
== 2)
2110 ratr_bitmap
&= 0x0f0ff000;
2112 ratr_bitmap
&= 0x0f0ff005;
2117 if ((curtxbw_40mhz
&& curshortgi_40mhz
) ||
2118 (!curtxbw_40mhz
&& curshortgi_20mhz
)) {
2122 else if (macid
== 1)
2127 ratr_index
= RATR_INX_WIRELESS_NGB
;
2129 if (rtlphy
->rf_type
== RF_1T2R
)
2130 ratr_bitmap
&= 0x000ff0ff;
2132 ratr_bitmap
&= 0x0f0ff0ff;
2135 sta_entry
->ratr_index
= ratr_index
;
2137 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
,
2138 "ratr_bitmap :%x\n", ratr_bitmap
);
2139 *(u32
*)&rate_mask
= (ratr_bitmap
& 0x0fffffff) |
2141 rate_mask
[4] = macid
| (shortgi
? 0x20 : 0x00) | 0x80;
2142 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
,
2143 "Rate_index:%x, ratr_val:%x, %5phC\n",
2144 ratr_index
, ratr_bitmap
, rate_mask
);
2145 memcpy(rtlpriv
->rate_mask
, rate_mask
, 5);
2146 /* rtl92c_fill_h2c_cmd() does USB I/O and will result in a
2147 * "scheduled while atomic" if called directly */
2148 schedule_work(&rtlpriv
->works
.fill_h2c_cmd
);
2151 sta_entry
->ratr_index
= ratr_index
;
2154 void rtl92cu_update_hal_rate_tbl(struct ieee80211_hw
*hw
,
2155 struct ieee80211_sta
*sta
,
2156 u8 rssi_level
, bool update_bw
)
2158 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2160 if (rtlpriv
->dm
.useramask
)
2161 rtl92cu_update_hal_rate_mask(hw
, sta
, rssi_level
, update_bw
);
2163 rtl92cu_update_hal_rate_table(hw
, sta
);
2166 void rtl92cu_update_channel_access_setting(struct ieee80211_hw
*hw
)
2168 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2169 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2172 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
,
2174 if (!mac
->ht_enable
)
2175 sifs_timer
= 0x0a0a;
2177 sifs_timer
= 0x0e0e;
2178 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SIFS
, (u8
*)&sifs_timer
);
2181 bool rtl92cu_gpio_radio_on_off_checking(struct ieee80211_hw
*hw
, u8
* valid
)
2183 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2184 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
2185 enum rf_pwrstate e_rfpowerstate_toset
, cur_rfstate
;
2187 bool actuallyset
= false;
2188 unsigned long flag
= 0;
2189 /* to do - usb autosuspend */
2190 u8 usb_autosuspend
= 0;
2192 if (ppsc
->swrf_processing
)
2194 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2195 if (ppsc
->rfchange_inprogress
) {
2196 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2199 ppsc
->rfchange_inprogress
= true;
2200 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2202 cur_rfstate
= ppsc
->rfpwr_state
;
2203 if (usb_autosuspend
) {
2204 /* to do................... */
2206 if (ppsc
->pwrdown_mode
) {
2207 u1tmp
= rtl_read_byte(rtlpriv
, REG_HSISR
);
2208 e_rfpowerstate_toset
= (u1tmp
& BIT(7)) ?
2210 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
2211 "pwrdown, 0x5c(BIT7)=%02x\n", u1tmp
);
2213 rtl_write_byte(rtlpriv
, REG_MAC_PINMUX_CFG
,
2214 rtl_read_byte(rtlpriv
,
2215 REG_MAC_PINMUX_CFG
) & ~(BIT(3)));
2216 u1tmp
= rtl_read_byte(rtlpriv
, REG_GPIO_IO_SEL
);
2217 e_rfpowerstate_toset
= (u1tmp
& BIT(3)) ?
2219 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
2220 "GPIO_IN=%02x\n", u1tmp
);
2222 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
, "N-SS RF =%x\n",
2223 e_rfpowerstate_toset
);
2225 if ((ppsc
->hwradiooff
) && (e_rfpowerstate_toset
== ERFON
)) {
2226 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
2227 "GPIOChangeRF - HW Radio ON, RF ON\n");
2228 ppsc
->hwradiooff
= false;
2230 } else if ((!ppsc
->hwradiooff
) && (e_rfpowerstate_toset
==
2232 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
2233 "GPIOChangeRF - HW Radio OFF\n");
2234 ppsc
->hwradiooff
= true;
2237 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
2238 "pHalData->bHwRadioOff and eRfPowerStateToSet do not match: pHalData->bHwRadioOff %x, eRfPowerStateToSet %x\n",
2239 ppsc
->hwradiooff
, e_rfpowerstate_toset
);
2242 ppsc
->hwradiooff
= true;
2243 if (e_rfpowerstate_toset
== ERFON
) {
2244 if ((ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_ASPM
) &&
2245 RT_IN_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_ASPM
))
2246 RT_CLEAR_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_ASPM
);
2247 else if ((ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_PCI_D3
)
2248 && RT_IN_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_PCI_D3
))
2249 RT_CLEAR_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_PCI_D3
);
2251 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2252 ppsc
->rfchange_inprogress
= false;
2253 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2254 /* For power down module, we need to enable register block
2255 * contrl reg at 0x1c. Then enable power down control bit
2256 * of register 0x04 BIT4 and BIT15 as 1.
2258 if (ppsc
->pwrdown_mode
&& e_rfpowerstate_toset
== ERFOFF
) {
2259 /* Enable register area 0x0-0xc. */
2260 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x0);
2261 rtl_write_word(rtlpriv
, REG_APS_FSMCO
, 0x8812);
2263 if (e_rfpowerstate_toset
== ERFOFF
) {
2264 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_ASPM
)
2265 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_ASPM
);
2266 else if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_PCI_D3
)
2267 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_PCI_D3
);
2269 } else if (e_rfpowerstate_toset
== ERFOFF
|| cur_rfstate
== ERFOFF
) {
2270 /* Enter D3 or ASPM after GPIO had been done. */
2271 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_ASPM
)
2272 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_ASPM
);
2273 else if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_PCI_D3
)
2274 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_PCI_D3
);
2275 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2276 ppsc
->rfchange_inprogress
= false;
2277 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2279 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2280 ppsc
->rfchange_inprogress
= false;
2281 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2284 return !ppsc
->hwradiooff
;