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 ******************************************************************************/
15 #ifndef __RTL8723A_HAL_H__
16 #define __RTL8723A_HAL_H__
18 #include "rtl8723a_spec.h"
19 #include "rtl8723a_pg.h"
20 #include "Hal8723APhyReg.h"
21 #include "Hal8723APhyCfg.h"
22 #include "rtl8723a_rf.h"
23 #ifdef CONFIG_8723AU_BT_COEXIST
24 #include "rtl8723a_bt-coexist.h"
26 #include "rtl8723a_dm.h"
27 #include "rtl8723a_recv.h"
28 #include "rtl8723a_xmit.h"
29 #include "rtl8723a_cmd.h"
30 #include "rtl8723a_sreset.h"
31 #include "rtw_efuse.h"
33 #include "odm_precomp.h"
36 /* 2TODO: We should define 8192S firmware related macro settings here!! */
37 #define RTL819X_DEFAULT_RF_TYPE RF_1T2R
38 #define RTL819X_TOTAL_RF_PATH 2
40 /* TODO: The following need to check!! */
41 #define RTL8723_FW_UMC_IMG "rtl8192CU\\rtl8723fw.bin"
42 #define RTL8723_FW_UMC_B_IMG "rtl8192CU\\rtl8723fw_B.bin"
43 #define RTL8723_PHY_REG "rtl8723S\\PHY_REG_1T.txt"
44 #define RTL8723_PHY_RADIO_A "rtl8723S\\radio_a_1T.txt"
45 #define RTL8723_PHY_RADIO_B "rtl8723S\\radio_b_1T.txt"
46 #define RTL8723_AGC_TAB "rtl8723S\\AGC_TAB_1T.txt"
47 #define RTL8723_PHY_MACREG "rtl8723S\\MAC_REG.txt"
48 #define RTL8723_PHY_REG_PG "rtl8723S\\PHY_REG_PG.txt"
49 #define RTL8723_PHY_REG_MP "rtl8723S\\PHY_REG_MP.txt"
52 /* RTL8723S From header */
56 #define Rtl8723_FwImageArray Rtl8723UFwImgArray
57 #define Rtl8723_FwUMCBCutImageArrayWithBT Rtl8723UFwUMCBCutImgArrayWithBT
58 #define Rtl8723_FwUMCBCutImageArrayWithoutBT Rtl8723UFwUMCBCutImgArrayWithoutBT
60 #define Rtl8723_ImgArrayLength Rtl8723UImgArrayLength
61 #define Rtl8723_UMCBCutImgArrayWithBTLength Rtl8723UUMCBCutImgArrayWithBTLength
62 #define Rtl8723_UMCBCutImgArrayWithoutBTLength Rtl8723UUMCBCutImgArrayWithoutBTLength
64 #define Rtl8723_PHY_REG_Array_PG Rtl8723UPHY_REG_Array_PG
65 #define Rtl8723_PHY_REG_Array_PGLength Rtl8723UPHY_REG_Array_PGLength
67 #define Rtl8723_FwUMCBCutMPImageArray Rtl8723SFwUMCBCutMPImgAr
68 #define Rtl8723_UMCBCutMPImgArrayLength Rtl8723SUMCBCutMPImgArrayLength
70 #define DRVINFO_SZ 4 /* unit is 8bytes */
71 #define PageNum_128(_Len) (u32)(((_Len)>>7) + ((_Len)&0x7F ? 1:0))
73 #define FW_8723A_SIZE 0x8000
74 #define FW_8723A_START_ADDRESS 0x1000
75 #define FW_8723A_END_ADDRESS 0x1FFF /* 0x5FFF */
77 #define MAX_PAGE_SIZE 4096 /* @ page : 4k bytes */
79 #define IS_FW_HEADER_EXIST(_pFwHdr) ((le16_to_cpu(_pFwHdr->Signature)&0xFFF0) == 0x92C0 ||\
80 (le16_to_cpu(_pFwHdr->Signature)&0xFFF0) == 0x88C0 ||\
81 (le16_to_cpu(_pFwHdr->Signature)&0xFFF0) == 0x2300)
84 /* This structure must be cared byte-ordering */
86 /* Added by tynli. 2009.12.04. */
87 struct rt_8723a_firmware_hdr {
88 /* 8-byte alinment required */
90 /* LONG WORD 0 ---- */
91 u16 Signature; /* 92C0: test chip; 92C, 88C0: test chip; 88C1: MP A-cut; 92C1: MP A-cut */
92 u8 Category; /* AP/NIC and USB/PCI */
93 u8 Function; /* Reserved for different FW function indcation, for further use when driver needs to download different FW in different conditions */
94 u16 Version; /* FW Version */
95 u8 Subversion; /* FW Subversion, default 0x00 */
99 /* LONG WORD 1 ---- */
100 u8 Month; /* Release time Month field */
101 u8 Date; /* Release time Date field */
102 u8 Hour; /* Release time Hour field */
103 u8 Minute; /* Release time Minute field */
104 u16 RamCodeSize; /* The size of RAM code */
107 /* LONG WORD 2 ---- */
108 u32 SvnIdx; /* The SVN entry index */
111 /* LONG WORD 3 ---- */
116 #define DRIVER_EARLY_INT_TIME 0x05
117 #define BCN_DMA_ATIME_INT_TIME 0x02
120 /* BK, BE, VI, VO, HCCA, MANAGEMENT, COMMAND, HIGH, BEACON. */
121 #define MAX_TX_QUEUE 9
123 #define TX_SELE_HQ BIT(0) /* High Queue */
124 #define TX_SELE_LQ BIT(1) /* Low Queue */
125 #define TX_SELE_NQ BIT(2) /* Normal Queue */
127 /* Note: We will divide number of page equally for each queue other than public queue! */
128 #define TX_TOTAL_PAGE_NUMBER 0xF8
129 #define TX_PAGE_BOUNDARY (TX_TOTAL_PAGE_NUMBER + 1)
131 /* For Normal Chip Setting */
132 /* (HPQ + LPQ + NPQ + PUBQ) shall be TX_TOTAL_PAGE_NUMBER */
133 #define NORMAL_PAGE_NUM_PUBQ 0xE7
134 #define NORMAL_PAGE_NUM_HPQ 0x0C
135 #define NORMAL_PAGE_NUM_LPQ 0x02
136 #define NORMAL_PAGE_NUM_NPQ 0x02
138 /* For Test Chip Setting */
139 /* (HPQ + LPQ + PUBQ) shall be TX_TOTAL_PAGE_NUMBER */
140 #define TEST_PAGE_NUM_PUBQ 0x7E
142 /* For Test Chip Setting */
143 #define WMM_TEST_TX_TOTAL_PAGE_NUMBER 0xF5
144 #define WMM_TEST_TX_PAGE_BOUNDARY (WMM_TEST_TX_TOTAL_PAGE_NUMBER + 1) /* F6 */
146 #define WMM_TEST_PAGE_NUM_PUBQ 0xA3
147 #define WMM_TEST_PAGE_NUM_HPQ 0x29
148 #define WMM_TEST_PAGE_NUM_LPQ 0x29
150 /* Note: For Normal Chip Setting, modify later */
151 #define WMM_NORMAL_TX_TOTAL_PAGE_NUMBER 0xF5
152 #define WMM_NORMAL_TX_PAGE_BOUNDARY (WMM_TEST_TX_TOTAL_PAGE_NUMBER + 1) /* F6 */
154 #define WMM_NORMAL_PAGE_NUM_PUBQ 0xB0
155 #define WMM_NORMAL_PAGE_NUM_HPQ 0x29
156 #define WMM_NORMAL_PAGE_NUM_LPQ 0x1C
157 #define WMM_NORMAL_PAGE_NUM_NPQ 0x1C
163 #define CHIP_BONDING_IDENTIFIER(_value) (((_value)>>22)&0x3)
164 #define CHIP_BONDING_92C_1T2R 0x1
165 #define CHIP_BONDING_88C_USB_MCARD 0x2
166 #define CHIP_BONDING_88C_USB_HP 0x1
168 #include "HalVerDef.h"
189 #define EFUSE_REAL_CONTENT_LEN 512
190 #define EFUSE_MAP_LEN 128
191 #define EFUSE_MAX_SECTION 16
192 #define EFUSE_IC_ID_OFFSET 506 /* For some inferiority IC purpose. added by Roger, 2009.09.02. */
193 #define AVAILABLE_EFUSE_ADDR(addr) (addr < EFUSE_REAL_CONTENT_LEN)
196 /* To prevent out of boundary programming case, */
197 /* leave 1byte and program full section */
198 /* 9bytes + 1byt + 5bytes and pre 1byte. */
199 /* For worst case: */
200 /* | 1byte|----8bytes----|1byte|--5bytes--| */
201 /* | | Reserved(14bytes) | */
204 /* PG data exclude header, dummy 6 bytes frome CP test and reserved 1byte. */
205 #define EFUSE_OOB_PROTECT_BYTES 15
207 #define EFUSE_REAL_CONTENT_LEN_8723A 512
208 #define EFUSE_MAP_LEN_8723A 256
209 #define EFUSE_MAX_SECTION_8723A 32
212 /* EFUSE for BT definition */
214 #define EFUSE_BT_REAL_BANK_CONTENT_LEN 512
215 #define EFUSE_BT_REAL_CONTENT_LEN 1536 /* 512*3 */
216 #define EFUSE_BT_MAP_LEN 1024 /* 1k bytes */
217 #define EFUSE_BT_MAX_SECTION 128 /* 1024/8 */
219 #define EFUSE_PROTECT_BYTES_BANK 16
222 /* <Roger_Notes> For RTL8723 WiFi/BT/GPS multi-function configuration. 2010.10.06. */
225 RT_MULTI_FUNC_NONE = 0x00,
226 RT_MULTI_FUNC_WIFI = 0x01,
227 RT_MULTI_FUNC_BT = 0x02,
228 RT_MULTI_FUNC_GPS = 0x04,
232 /* <Roger_Notes> For RTL8723 WiFi PDn/GPIO polarity control configuration. 2010.10.08. */
234 enum RT_POLARITY_CTL {
235 RT_POLARITY_LOW_ACT = 0,
236 RT_POLARITY_HIGH_ACT = 1,
239 /* For RTL8723 regulator mode. by tynli. 2011.01.14. */
240 enum RT_REGULATOR_MODE {
241 RT_SWITCHING_REGULATOR = 0,
242 RT_LDO_REGULATOR = 1,
245 /* Description: Determine the types of C2H events that are the same in driver and Fw. */
246 /* Fisrt constructed by tynli. 2009.10.09. */
251 C2H_CCX_TX_RPT = 3, /* The FW notify the report of the specific tx packet. */
255 C2H_HW_INFO_EXCH = 10,
256 C2H_C2H_H2C_TEST = 11,
262 struct hal_data_8723a {
263 struct hal_version VersionID;
264 enum rt_customer_id CustomerID;
267 u16 FirmwareVersionRev;
268 u16 FirmwareSubVersion;
269 u16 FirmwareSignature;
271 /* current WIFI_PHY values */
273 enum WIRELESS_MODE CurrentWirelessMode;
274 enum ht_channel_width CurrentChannelBW;
276 u8 nCur40MhzPrimeSC;/* Control channel sub-carrier */
288 /* EEPROM setting. */
296 u8 EEPROMSubCustomerID;
298 u8 EEPROMThermalMeter;
299 u8 EEPROMBluetoothCoexist;
300 u8 EEPROMBluetoothType;
301 u8 EEPROMBluetoothAntNum;
302 u8 EEPROMBluetoothAntIsolation;
303 u8 EEPROMBluetoothRadioShared;
305 u8 bTXPowerDataReadFromEEPORM;
306 u8 bAPKThermalMeterIgnore;
311 u8 TxPwrLevelCck[RF_PATH_MAX][CHANNEL_MAX_NUMBER];
312 u8 TxPwrLevelHT40_1S[RF_PATH_MAX][CHANNEL_MAX_NUMBER]; /* For HT 40MHZ pwr */
313 u8 TxPwrLevelHT40_2S[RF_PATH_MAX][CHANNEL_MAX_NUMBER]; /* For HT 40MHZ pwr */
314 u8 TxPwrHt20Diff[RF_PATH_MAX][CHANNEL_MAX_NUMBER];/* HT 20<->40 Pwr diff */
315 u8 TxPwrLegacyHtDiff[RF_PATH_MAX][CHANNEL_MAX_NUMBER];/* For HT<->legacy pwr diff */
316 /* For power group */
317 u8 PwrGroupHT20[RF_PATH_MAX][CHANNEL_MAX_NUMBER];
318 u8 PwrGroupHT40[RF_PATH_MAX][CHANNEL_MAX_NUMBER];
320 u8 LegacyHTTxPowerDiff;/* Legacy to HT rate power diff */
322 /* Read/write are allow for following hardware information variables */
326 u8 DefaultInitialGain[4];
328 u32 MCSTxPowerLevelOriginalOffset[7][16];
329 u32 CCKTxPowerLevelOriginalOffset;
331 u32 AntennaTxPath; /* Antenna path Tx */
332 u32 AntennaRxPath; /* Antenna path Rx */
335 u8 bLedOpenDrain; /* Support Open-drain arrangement for controlling the LED. Added by Roger, 2009.10.16. */
337 u8 b1x1RecvCombine; /* for 1T1R receive combining */
339 /* For EDCA Turbo mode */
341 u32 AcParam_BE; /* Original parameter for BE, use for EDCA turbo. */
343 /* vivi, for tx power tracking, 20080407 */
344 /* u16 TSSI_13dBm; */
346 /* The current Tx Power Level */
347 u8 CurrentCckTxPwrIdx;
348 u8 CurrentOfdm24GTxPwrIdx;
350 struct bb_reg_define PHYRegDef[4]; /* Radio A/B/C/D */
352 bool bRFPathRxEnable[4]; /* We support 4 RF path now. */
361 /* for host message to fw */
366 /* Beacon function related global variable. */
371 struct dm_priv dmpriv;
372 struct dm_odm_t odmpriv;
373 struct sreset_priv srestpriv;
375 #ifdef CONFIG_8723AU_BT_COEXIST
378 struct bt_30info BtInfo;
379 /* For bluetooth co-existance */
380 struct bt_coexist_str bt_coexist;
383 u8 bDumpRxPkt;/* for debug */
384 u8 FwRsvdPageStartOffset; /* 2010.06.23. Added by tynli. Reserve page start offset except beacon in TxQ. */
386 /* 2010/08/09 MH Add CU power down mode. */
389 /* Add for dual MAC 0--Mac0 1--Mac1 */
395 /* 2010/12/10 MH Add for USB aggreation mode dynamic shceme. */
396 bool UsbRxHighSpeedMode;
398 /* 2010/11/22 MH Add for slim combo debug mode selective. */
399 /* This is used for fix the drawback of CU TSMC-A/UMC-A cut. HW auto suspend ability. Close BT clock. */
403 /* Add For EEPROM Efuse switch and Efuse Shadow map Setting */
407 u16 BTEfuseUsedBytes;
409 /* Interrupt relatd register information. */
414 /* 2011/02/23 MH Add for 8723 mylti function definition. The define should be moved to an */
415 /* independent file in the future. */
417 /* 8723-----------------------------------------*/
418 enum RT_MULTI_FUNC MultiFunc; /* For multi-function consideration. */
419 enum RT_POLARITY_CTL PolarityCtl; /* For Wifi PDn Polarity control. */
420 enum RT_REGULATOR_MODE RegulatorMode; /* switching regulator or LDO */
421 /* 8723-----------------------------------------
422 * 2011/02/23 MH Add for 8723 mylti function definition. The define should be moved to an */
423 /* independent file in the future. */
427 #ifdef CONFIG_8723AU_P2P
428 struct P2P_PS_Offload_t p2p_ps_offload;
433 /* For USB Interface HAL related */
437 /* Interrupt related register information. */
442 /* For SDIO Interface HAL related */
445 /* Auto FSM to Turn On, include clock, isolation, power control for MAC only */
450 #define GET_HAL_DATA(__pAdapter) ((struct hal_data_8723a *)((__pAdapter)->HalData))
451 #define GET_RF_TYPE(priv) (GET_HAL_DATA(priv)->rf_type)
453 #define INCLUDE_MULTI_FUNC_BT(_Adapter) (GET_HAL_DATA(_Adapter)->MultiFunc & RT_MULTI_FUNC_BT)
454 #define INCLUDE_MULTI_FUNC_GPS(_Adapter) (GET_HAL_DATA(_Adapter)->MultiFunc & RT_MULTI_FUNC_GPS)
456 struct rxreport_8723a {
527 /* rtl8723a_hal_init.c */
528 s32 rtl8723a_FirmwareDownload(struct rtw_adapter *padapter);
529 void rtl8723a_FirmwareSelfReset(struct rtw_adapter *padapter);
530 void rtl8723a_InitializeFirmwareVars(struct rtw_adapter *padapter);
532 void rtl8723a_InitAntenna_Selection(struct rtw_adapter *padapter);
533 void rtl8723a_DeinitAntenna_Selection(struct rtw_adapter *padapter);
534 void rtl8723a_CheckAntenna_Selection(struct rtw_adapter *padapter);
535 void rtl8723a_init_default_value(struct rtw_adapter *padapter);
537 s32 InitLLTTable23a(struct rtw_adapter *padapter, u32 boundary);
539 s32 CardDisableHWSM(struct rtw_adapter *padapter, u8 resetMCU);
540 s32 CardDisableWithoutHWSM(struct rtw_adapter *padapter);
543 u8 GetEEPROMSize8723A(struct rtw_adapter *padapter);
544 void Hal_InitPGData(struct rtw_adapter *padapter, u8 *PROMContent);
545 void Hal_EfuseParseIDCode(struct rtw_adapter *padapter, u8 *hwinfo);
546 void Hal_EfuseParsetxpowerinfo_8723A(struct rtw_adapter *padapter, u8 *PROMContent, bool AutoLoadFail);
547 void Hal_EfuseParseBTCoexistInfo_8723A(struct rtw_adapter *padapter, u8 *hwinfo, bool AutoLoadFail);
548 void Hal_EfuseParseEEPROMVer(struct rtw_adapter *padapter, u8 *hwinfo, bool AutoLoadFail);
549 void rtl8723a_EfuseParseChnlPlan(struct rtw_adapter *padapter, u8 *hwinfo, bool AutoLoadFail);
550 void Hal_EfuseParseCustomerID(struct rtw_adapter *padapter, u8 *hwinfo, bool AutoLoadFail);
551 void Hal_EfuseParseAntennaDiversity(struct rtw_adapter *padapter, u8 *hwinfo, bool AutoLoadFail);
552 void Hal_EfuseParseRateIndicationOption(struct rtw_adapter *padapter, u8 *hwinfo, bool AutoLoadFail);
553 void Hal_EfuseParseXtal_8723A(struct rtw_adapter *pAdapter, u8 *hwinfo, u8 AutoLoadFail);
554 void Hal_EfuseParseThermalMeter_8723A(struct rtw_adapter *padapter, u8 *hwinfo, u8 AutoLoadFail);
556 void Hal_InitChannelPlan23a(struct rtw_adapter *padapter);
558 void rtl8723a_set_hal_ops(struct hal_ops *pHalFunc);
559 void SetHwReg8723A(struct rtw_adapter *padapter, u8 variable, u8 *val);
560 void GetHwReg8723A(struct rtw_adapter *padapter, u8 variable, u8 *val);
561 #ifdef CONFIG_8723AU_BT_COEXIST
562 void rtl8723a_SingleDualAntennaDetection(struct rtw_adapter *padapter);
566 void SetBcnCtrlReg23a(struct rtw_adapter *padapter, u8 SetBits, u8 ClearBits);
567 void rtl8723a_InitBeaconParameters(struct rtw_adapter *padapter);
569 void rtl8723a_clone_haldata(struct rtw_adapter *dst_adapter, struct rtw_adapter *src_adapter);
570 void rtl8723a_start_thread(struct rtw_adapter *padapter);
571 void rtl8723a_stop_thread(struct rtw_adapter *padapter);
573 s32 c2h_id_filter_ccx_8723a(u8 id);