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 #include "rtl8723a_bt_intf.h"
24 #ifdef CONFIG_8723AU_BT_COEXIST
25 #include "rtl8723a_bt-coexist.h"
27 #include "rtl8723a_dm.h"
28 #include "rtl8723a_recv.h"
29 #include "rtl8723a_xmit.h"
30 #include "rtl8723a_cmd.h"
31 #include "rtl8723a_sreset.h"
32 #include "rtw_efuse.h"
33 #include "rtw_eeprom.h"
35 #include "odm_precomp.h"
39 /* 2TODO: We should define 8192S firmware related macro settings here!! */
40 #define RTL819X_DEFAULT_RF_TYPE RF_1T2R
41 #define RTL819X_TOTAL_RF_PATH 2
44 /* RTL8723S From header */
48 #define Rtl8723_FwImageArray Rtl8723UFwImgArray
49 #define Rtl8723_FwUMCBCutImageArrayWithBT Rtl8723UFwUMCBCutImgArrayWithBT
50 #define Rtl8723_FwUMCBCutImageArrayWithoutBT Rtl8723UFwUMCBCutImgArrayWithoutBT
52 #define Rtl8723_ImgArrayLength Rtl8723UImgArrayLength
53 #define Rtl8723_UMCBCutImgArrayWithBTLength Rtl8723UUMCBCutImgArrayWithBTLength
54 #define Rtl8723_UMCBCutImgArrayWithoutBTLength Rtl8723UUMCBCutImgArrayWithoutBTLength
56 #define Rtl8723_PHY_REG_Array_PG Rtl8723UPHY_REG_Array_PG
57 #define Rtl8723_PHY_REG_Array_PGLength Rtl8723UPHY_REG_Array_PGLength
59 #define Rtl8723_FwUMCBCutMPImageArray Rtl8723SFwUMCBCutMPImgAr
60 #define Rtl8723_UMCBCutMPImgArrayLength Rtl8723SUMCBCutMPImgArrayLength
62 #define DRVINFO_SZ 4 /* unit is 8bytes */
63 #define PageNum_128(_Len) (u32)(((_Len)>>7) + ((_Len)&0x7F ? 1:0))
65 #define FW_8723A_SIZE 0x8000
66 #define FW_8723A_START_ADDRESS 0x1000
67 #define FW_8723A_END_ADDRESS 0x1FFF /* 0x5FFF */
69 #define MAX_PAGE_SIZE 4096 /* @ page : 4k bytes */
71 #define IS_FW_HEADER_EXIST(_pFwHdr) ((le16_to_cpu(_pFwHdr->Signature)&0xFFF0) == 0x92C0 ||\
72 (le16_to_cpu(_pFwHdr->Signature)&0xFFF0) == 0x88C0 ||\
73 (le16_to_cpu(_pFwHdr->Signature)&0xFFF0) == 0x2300)
76 /* This structure must be cared byte-ordering */
78 /* Added by tynli. 2009.12.04. */
79 struct rt_8723a_firmware_hdr {
80 /* 8-byte alinment required */
82 /* LONG WORD 0 ---- */
83 u16 Signature; /* 92C0: test chip; 92C, 88C0: test chip; 88C1: MP A-cut; 92C1: MP A-cut */
84 u8 Category; /* AP/NIC and USB/PCI */
85 u8 Function; /* Reserved for different FW function indcation, for further use when driver needs to download different FW in different conditions */
86 u16 Version; /* FW Version */
87 u8 Subversion; /* FW Subversion, default 0x00 */
91 /* LONG WORD 1 ---- */
92 u8 Month; /* Release time Month field */
93 u8 Date; /* Release time Date field */
94 u8 Hour; /* Release time Hour field */
95 u8 Minute; /* Release time Minute field */
96 u16 RamCodeSize; /* The size of RAM code */
99 /* LONG WORD 2 ---- */
100 u32 SvnIdx; /* The SVN entry index */
103 /* LONG WORD 3 ---- */
108 #define DRIVER_EARLY_INT_TIME 0x05
109 #define BCN_DMA_ATIME_INT_TIME 0x02
112 /* BK, BE, VI, VO, HCCA, MANAGEMENT, COMMAND, HIGH, BEACON. */
113 #define MAX_TX_QUEUE 9
115 #define TX_SELE_HQ BIT(0) /* High Queue */
116 #define TX_SELE_LQ BIT(1) /* Low Queue */
117 #define TX_SELE_NQ BIT(2) /* Normal Queue */
119 /* Note: We will divide number of page equally for each queue other than public queue! */
120 #define TX_TOTAL_PAGE_NUMBER 0xF8
121 #define TX_PAGE_BOUNDARY (TX_TOTAL_PAGE_NUMBER + 1)
123 /* For Normal Chip Setting */
124 /* (HPQ + LPQ + NPQ + PUBQ) shall be TX_TOTAL_PAGE_NUMBER */
125 #define NORMAL_PAGE_NUM_PUBQ 0xE7
126 #define NORMAL_PAGE_NUM_HPQ 0x0C
127 #define NORMAL_PAGE_NUM_LPQ 0x02
128 #define NORMAL_PAGE_NUM_NPQ 0x02
130 /* For Test Chip Setting */
131 /* (HPQ + LPQ + PUBQ) shall be TX_TOTAL_PAGE_NUMBER */
132 #define TEST_PAGE_NUM_PUBQ 0x7E
134 /* For Test Chip Setting */
135 #define WMM_TEST_TX_TOTAL_PAGE_NUMBER 0xF5
136 #define WMM_TEST_TX_PAGE_BOUNDARY (WMM_TEST_TX_TOTAL_PAGE_NUMBER + 1) /* F6 */
138 #define WMM_TEST_PAGE_NUM_PUBQ 0xA3
139 #define WMM_TEST_PAGE_NUM_HPQ 0x29
140 #define WMM_TEST_PAGE_NUM_LPQ 0x29
142 /* Note: For Normal Chip Setting, modify later */
143 #define WMM_NORMAL_TX_TOTAL_PAGE_NUMBER 0xF5
144 #define WMM_NORMAL_TX_PAGE_BOUNDARY (WMM_TEST_TX_TOTAL_PAGE_NUMBER + 1) /* F6 */
146 #define WMM_NORMAL_PAGE_NUM_PUBQ 0xB0
147 #define WMM_NORMAL_PAGE_NUM_HPQ 0x29
148 #define WMM_NORMAL_PAGE_NUM_LPQ 0x1C
149 #define WMM_NORMAL_PAGE_NUM_NPQ 0x1C
155 #define CHIP_BONDING_IDENTIFIER(_value) (((_value)>>22)&0x3)
156 #define CHIP_BONDING_92C_1T2R 0x1
157 #define CHIP_BONDING_88C_USB_MCARD 0x2
158 #define CHIP_BONDING_88C_USB_HP 0x1
160 #include "HalVerDef.h"
181 #define EFUSE_REAL_CONTENT_LEN 512
182 #define EFUSE_MAP_LEN 128
183 #define EFUSE_MAX_SECTION 16
184 #define EFUSE_IC_ID_OFFSET 506 /* For some inferiority IC purpose. added by Roger, 2009.09.02. */
185 #define AVAILABLE_EFUSE_ADDR(addr) (addr < EFUSE_REAL_CONTENT_LEN)
188 /* To prevent out of boundary programming case, */
189 /* leave 1byte and program full section */
190 /* 9bytes + 1byt + 5bytes and pre 1byte. */
191 /* For worst case: */
192 /* | 1byte|----8bytes----|1byte|--5bytes--| */
193 /* | | Reserved(14bytes) | */
196 /* PG data exclude header, dummy 6 bytes frome CP test and reserved 1byte. */
197 #define EFUSE_OOB_PROTECT_BYTES 15
199 #define EFUSE_REAL_CONTENT_LEN_8723A 512
200 #define EFUSE_MAP_LEN_8723A 256
201 #define EFUSE_MAX_SECTION_8723A 32
204 /* EFUSE for BT definition */
206 #define EFUSE_BT_REAL_BANK_CONTENT_LEN 512
207 #define EFUSE_BT_REAL_CONTENT_LEN 1536 /* 512*3 */
208 #define EFUSE_BT_MAP_LEN 1024 /* 1k bytes */
209 #define EFUSE_BT_MAX_SECTION 128 /* 1024/8 */
211 #define EFUSE_PROTECT_BYTES_BANK 16
214 /* <Roger_Notes> For RTL8723 WiFi/BT/GPS multi-function configuration. 2010.10.06. */
217 RT_MULTI_FUNC_NONE = 0x00,
218 RT_MULTI_FUNC_WIFI = 0x01,
219 RT_MULTI_FUNC_BT = 0x02,
220 RT_MULTI_FUNC_GPS = 0x04,
224 /* <Roger_Notes> For RTL8723 WiFi PDn/GPIO polarity control configuration. 2010.10.08. */
226 enum RT_POLARITY_CTL {
227 RT_POLARITY_LOW_ACT = 0,
228 RT_POLARITY_HIGH_ACT = 1,
231 /* For RTL8723 regulator mode. by tynli. 2011.01.14. */
232 enum RT_REGULATOR_MODE {
233 RT_SWITCHING_REGULATOR = 0,
234 RT_LDO_REGULATOR = 1,
237 /* Description: Determine the types of C2H events that are the same in driver and Fw. */
238 /* Fisrt constructed by tynli. 2009.10.09. */
243 C2H_CCX_TX_RPT = 3, /* The FW notify the report of the specific tx packet. */
247 C2H_HW_INFO_EXCH = 10,
248 C2H_C2H_H2C_TEST = 11,
254 struct hal_data_8723a {
255 struct hal_version VersionID;
256 enum rt_customer_id CustomerID;
259 u16 FirmwareVersionRev;
260 u16 FirmwareSubVersion;
261 u16 FirmwareSignature;
263 /* current WIFI_PHY values */
265 enum WIRELESS_MODE CurrentWirelessMode;
266 enum ht_channel_width CurrentChannelBW;
268 u8 nCur40MhzPrimeSC;/* Control channel sub-carrier */
280 /* EEPROM setting. */
288 u8 EEPROMSubCustomerID;
290 u8 EEPROMThermalMeter;
291 u8 EEPROMBluetoothCoexist;
292 u8 EEPROMBluetoothType;
293 u8 EEPROMBluetoothAntNum;
294 u8 EEPROMBluetoothAntIsolation;
295 u8 EEPROMBluetoothRadioShared;
297 u8 bTXPowerDataReadFromEEPORM;
298 u8 bAPKThermalMeterIgnore;
303 u8 TxPwrLevelCck[RF_PATH_MAX][CHANNEL_MAX_NUMBER];
304 u8 TxPwrLevelHT40_1S[RF_PATH_MAX][CHANNEL_MAX_NUMBER]; /* For HT 40MHZ pwr */
305 u8 TxPwrLevelHT40_2S[RF_PATH_MAX][CHANNEL_MAX_NUMBER]; /* For HT 40MHZ pwr */
306 u8 TxPwrHt20Diff[RF_PATH_MAX][CHANNEL_MAX_NUMBER];/* HT 20<->40 Pwr diff */
307 u8 TxPwrLegacyHtDiff[RF_PATH_MAX][CHANNEL_MAX_NUMBER];/* For HT<->legacy pwr diff */
308 /* For power group */
309 u8 PwrGroupHT20[RF_PATH_MAX][CHANNEL_MAX_NUMBER];
310 u8 PwrGroupHT40[RF_PATH_MAX][CHANNEL_MAX_NUMBER];
312 u8 LegacyHTTxPowerDiff;/* Legacy to HT rate power diff */
314 /* Read/write are allow for following hardware information variables */
318 u8 DefaultInitialGain[4];
320 u32 MCSTxPowerLevelOriginalOffset[7][16];
321 u32 CCKTxPowerLevelOriginalOffset;
323 u32 AntennaTxPath; /* Antenna path Tx */
324 u32 AntennaRxPath; /* Antenna path Rx */
327 u8 bLedOpenDrain; /* Support Open-drain arrangement for controlling the LED. Added by Roger, 2009.10.16. */
329 u8 b1x1RecvCombine; /* for 1T1R receive combining */
331 /* For EDCA Turbo mode */
333 u32 AcParam_BE; /* Original parameter for BE, use for EDCA turbo. */
335 /* vivi, for tx power tracking, 20080407 */
336 /* u16 TSSI_13dBm; */
338 /* The current Tx Power Level */
339 u8 CurrentCckTxPwrIdx;
340 u8 CurrentOfdm24GTxPwrIdx;
342 struct bb_reg_define PHYRegDef[4]; /* Radio A/B/C/D */
344 bool bRFPathRxEnable[4]; /* We support 4 RF path now. */
353 /* for host message to fw */
358 /* Beacon function related global variable. */
363 struct dm_priv dmpriv;
364 struct dm_odm_t odmpriv;
365 struct sreset_priv srestpriv;
367 #ifdef CONFIG_8723AU_BT_COEXIST
370 struct bt_30info BtInfo;
371 /* For bluetooth co-existance */
372 struct bt_coexist_str bt_coexist;
375 u8 bDumpRxPkt;/* for debug */
376 u8 FwRsvdPageStartOffset; /* 2010.06.23. Added by tynli. Reserve page start offset except beacon in TxQ. */
378 /* 2010/08/09 MH Add CU power down mode. */
381 /* Add for dual MAC 0--Mac0 1--Mac1 */
387 /* 2010/12/10 MH Add for USB aggreation mode dynamic shceme. */
388 bool UsbRxHighSpeedMode;
390 /* 2010/11/22 MH Add for slim combo debug mode selective. */
391 /* This is used for fix the drawback of CU TSMC-A/UMC-A cut. HW auto suspend ability. Close BT clock. */
395 /* Add For EEPROM Efuse switch and Efuse Shadow map Setting */
399 u16 BTEfuseUsedBytes;
401 /* Interrupt relatd register information. */
406 /* 2011/02/23 MH Add for 8723 mylti function definition. The define should be moved to an */
407 /* independent file in the future. */
409 /* 8723-----------------------------------------*/
410 enum RT_MULTI_FUNC MultiFunc; /* For multi-function consideration. */
411 enum RT_POLARITY_CTL PolarityCtl; /* For Wifi PDn Polarity control. */
412 enum RT_REGULATOR_MODE RegulatorMode; /* switching regulator or LDO */
413 /* 8723-----------------------------------------
414 * 2011/02/23 MH Add for 8723 mylti function definition. The define should be moved to an */
415 /* independent file in the future. */
419 /* Interrupt related register information. */
424 #define GET_HAL_DATA(__pAdapter) ((struct hal_data_8723a *)((__pAdapter)->HalData))
425 #define GET_RF_TYPE(priv) (GET_HAL_DATA(priv)->rf_type)
427 #define INCLUDE_MULTI_FUNC_BT(_Adapter) (GET_HAL_DATA(_Adapter)->MultiFunc & RT_MULTI_FUNC_BT)
428 #define INCLUDE_MULTI_FUNC_GPS(_Adapter) (GET_HAL_DATA(_Adapter)->MultiFunc & RT_MULTI_FUNC_GPS)
430 struct rxreport_8723a {
501 /* rtl8723a_hal_init.c */
502 s32 rtl8723a_FirmwareDownload(struct rtw_adapter *padapter);
503 void rtl8723a_FirmwareSelfReset(struct rtw_adapter *padapter);
504 void rtl8723a_InitializeFirmwareVars(struct rtw_adapter *padapter);
506 void rtl8723a_InitAntenna_Selection(struct rtw_adapter *padapter);
507 void rtl8723a_DeinitAntenna_Selection(struct rtw_adapter *padapter);
508 void rtl8723a_CheckAntenna_Selection(struct rtw_adapter *padapter);
509 void rtl8723a_init_default_value(struct rtw_adapter *padapter);
511 s32 InitLLTTable23a(struct rtw_adapter *padapter, u32 boundary);
513 s32 CardDisableHWSM(struct rtw_adapter *padapter, u8 resetMCU);
514 s32 CardDisableWithoutHWSM(struct rtw_adapter *padapter);
517 u8 GetEEPROMSize8723A(struct rtw_adapter *padapter);
518 void Hal_InitPGData(struct rtw_adapter *padapter, u8 *PROMContent);
519 void Hal_EfuseParseIDCode(struct rtw_adapter *padapter, u8 *hwinfo);
520 void Hal_EfuseParsetxpowerinfo_8723A(struct rtw_adapter *padapter, u8 *PROMContent, bool AutoLoadFail);
521 void Hal_EfuseParseBTCoexistInfo_8723A(struct rtw_adapter *padapter, u8 *hwinfo, bool AutoLoadFail);
522 void Hal_EfuseParseEEPROMVer(struct rtw_adapter *padapter, u8 *hwinfo, bool AutoLoadFail);
523 void rtl8723a_EfuseParseChnlPlan(struct rtw_adapter *padapter, u8 *hwinfo, bool AutoLoadFail);
524 void Hal_EfuseParseCustomerID(struct rtw_adapter *padapter, u8 *hwinfo, bool AutoLoadFail);
525 void Hal_EfuseParseAntennaDiversity(struct rtw_adapter *padapter, u8 *hwinfo, bool AutoLoadFail);
526 void Hal_EfuseParseRateIndicationOption(struct rtw_adapter *padapter, u8 *hwinfo, bool AutoLoadFail);
527 void Hal_EfuseParseXtal_8723A(struct rtw_adapter *pAdapter, u8 *hwinfo, u8 AutoLoadFail);
528 void Hal_EfuseParseThermalMeter_8723A(struct rtw_adapter *padapter, u8 *hwinfo, bool AutoLoadFail);
530 void Hal_InitChannelPlan23a(struct rtw_adapter *padapter);
533 void SetBcnCtrlReg23a(struct rtw_adapter *padapter, u8 SetBits, u8 ClearBits);
534 void rtl8723a_InitBeaconParameters(struct rtw_adapter *padapter);
536 void rtl8723a_start_thread(struct rtw_adapter *padapter);
537 void rtl8723a_stop_thread(struct rtw_adapter *padapter);
539 bool c2h_id_filter_ccx_8723a(u8 id);
540 int c2h_handler_8723a(struct rtw_adapter *padapter, struct c2h_evt_hdr *c2h_evt);
542 void rtl8723a_read_adapter_info(struct rtw_adapter *Adapter);
543 void rtl8723a_read_chip_version(struct rtw_adapter *padapter);
544 void rtl8723a_notch_filter(struct rtw_adapter *adapter, bool enable);
545 void rtl8723a_SetBeaconRelatedRegisters(struct rtw_adapter *padapter);
546 void rtl8723a_SetHalODMVar(struct rtw_adapter *Adapter,
547 enum hal_odm_variable eVariable,
548 void *pValue1, bool bSet);
550 rtl8723a_readefuse(struct rtw_adapter *padapter,
551 u8 efuseType, u16 _offset, u16 _size_byte, u8 *pbuf);
552 u16 rtl8723a_EfuseGetCurrentSize_WiFi(struct rtw_adapter *padapter);
553 u16 rtl8723a_EfuseGetCurrentSize_BT(struct rtw_adapter *padapter);
554 void rtl8723a_update_ramask(struct rtw_adapter *padapter,
555 u32 mac_id, u8 rssi_level);