xref: /freebsd/sys/dev/ath/ath_hal/ah_eeprom_v4k.h (revision 95ee2897)
16e778a7eSPedro F. Giffuni /*-
26e778a7eSPedro F. Giffuni  * SPDX-License-Identifier: ISC
36e778a7eSPedro F. Giffuni  *
44eaee90eSRui Paulo  * Copyright (c) 2009 Rui Paulo <rpaulo@FreeBSD.org>
54eaee90eSRui Paulo  * Copyright (c) 2008 Sam Leffler, Errno Consulting
64eaee90eSRui Paulo  * Copyright (c) 2008 Atheros Communications, Inc.
74eaee90eSRui Paulo  *
84eaee90eSRui Paulo  * Permission to use, copy, modify, and/or distribute this software for any
94eaee90eSRui Paulo  * purpose with or without fee is hereby granted, provided that the above
104eaee90eSRui Paulo  * copyright notice and this permission notice appear in all copies.
114eaee90eSRui Paulo  *
124eaee90eSRui Paulo  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
134eaee90eSRui Paulo  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
144eaee90eSRui Paulo  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
154eaee90eSRui Paulo  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
164eaee90eSRui Paulo  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
174eaee90eSRui Paulo  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
184eaee90eSRui Paulo  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
194eaee90eSRui Paulo  */
204eaee90eSRui Paulo #ifndef _AH_EEPROM_V4K_H_
214eaee90eSRui Paulo #define _AH_EEPROM_V4K_H_
224eaee90eSRui Paulo 
234eaee90eSRui Paulo #include "ah_eeprom.h"
244eaee90eSRui Paulo #include "ah_eeprom_v14.h"
254eaee90eSRui Paulo 
263545027dSAdrian Chadd #if	_BYTE_ORDER == _BIG_ENDIAN
273545027dSAdrian Chadd #define	__BIG_ENDIAN_BITFIELD
283545027dSAdrian Chadd #endif
293545027dSAdrian Chadd 
304f49ef43SRui Paulo #define	AR9285_RDEXT_DEFAULT	0x1F
314f49ef43SRui Paulo 
320d2dd30cSAdrian Chadd #define	AR5416_4K_EEP_PD_GAIN_BOUNDARY_DEFAULT	58
330d2dd30cSAdrian Chadd 
344eaee90eSRui Paulo #undef owl_eep_start_loc
354eaee90eSRui Paulo #ifdef __LINUX_ARM_ARCH__ /* AP71 */
364eaee90eSRui Paulo #define owl_eep_start_loc		0
374eaee90eSRui Paulo #else
384eaee90eSRui Paulo #define owl_eep_start_loc		64
394eaee90eSRui Paulo #endif
404eaee90eSRui Paulo 
414eaee90eSRui Paulo // 16-bit offset location start of calibration struct
424eaee90eSRui Paulo #define AR5416_4K_EEP_START_LOC         64
434eaee90eSRui Paulo #define AR5416_4K_NUM_2G_CAL_PIERS     	3
444eaee90eSRui Paulo #define AR5416_4K_NUM_2G_CCK_TARGET_POWERS 3
454eaee90eSRui Paulo #define AR5416_4K_NUM_2G_20_TARGET_POWERS  3
464eaee90eSRui Paulo #define AR5416_4K_NUM_2G_40_TARGET_POWERS  3
474eaee90eSRui Paulo #define AR5416_4K_NUM_CTLS              12
484eaee90eSRui Paulo #define AR5416_4K_NUM_BAND_EDGES       	4
494eaee90eSRui Paulo #define AR5416_4K_NUM_PD_GAINS         	2
504eaee90eSRui Paulo #define AR5416_4K_MAX_CHAINS           	1
514eaee90eSRui Paulo 
524eaee90eSRui Paulo /*
534eaee90eSRui Paulo  * NB: The format in EEPROM has words 0 and 2 swapped (i.e. version
544eaee90eSRui Paulo  * and length are swapped).  We reverse their position after reading
554eaee90eSRui Paulo  * the data into host memory so the version field is at the same
564eaee90eSRui Paulo  * offset as in previous EEPROM layouts.  This makes utilities that
574eaee90eSRui Paulo  * inspect the EEPROM contents work without looking at the PCI device
584eaee90eSRui Paulo  * id which may or may not be reliable.
594eaee90eSRui Paulo  */
604eaee90eSRui Paulo typedef struct BaseEepHeader4k {
614eaee90eSRui Paulo 	uint16_t	version;	/* NB: length in EEPROM */
624eaee90eSRui Paulo 	uint16_t	checksum;
634eaee90eSRui Paulo 	uint16_t	length;		/* NB: version in EEPROM */
644eaee90eSRui Paulo 	uint8_t		opCapFlags;
654eaee90eSRui Paulo 	uint8_t		eepMisc;
664eaee90eSRui Paulo 	uint16_t	regDmn[2];
674eaee90eSRui Paulo 	uint8_t		macAddr[6];
684eaee90eSRui Paulo 	uint8_t		rxMask;
694eaee90eSRui Paulo 	uint8_t		txMask;
704eaee90eSRui Paulo 	uint16_t	rfSilent;
714eaee90eSRui Paulo 	uint16_t	blueToothOptions;
724eaee90eSRui Paulo 	uint16_t	deviceCap;
734eaee90eSRui Paulo 	uint32_t	binBuildNumber;
744eaee90eSRui Paulo 	uint8_t		deviceType;
754eaee90eSRui Paulo 	uint8_t		txGainType;	/* high power tx gain table support */
764eaee90eSRui Paulo } __packed BASE_EEP4K_HEADER; // 32 B
774eaee90eSRui Paulo 
784eaee90eSRui Paulo typedef struct ModalEepHeader4k {
793545027dSAdrian Chadd 	uint32_t	antCtrlChain[AR5416_4K_MAX_CHAINS];	// 4
804eaee90eSRui Paulo 	uint32_t	antCtrlCommon;				// 4
814eaee90eSRui Paulo 	int8_t		antennaGainCh[AR5416_4K_MAX_CHAINS];	// 1
824eaee90eSRui Paulo 	uint8_t		switchSettling;				// 1
834eaee90eSRui Paulo 	uint8_t		txRxAttenCh[AR5416_4K_MAX_CHAINS];	// 1
844eaee90eSRui Paulo 	uint8_t		rxTxMarginCh[AR5416_4K_MAX_CHAINS];	// 1
854eaee90eSRui Paulo 	uint8_t		adcDesiredSize;				// 1
864eaee90eSRui Paulo 	int8_t		pgaDesiredSize;				// 1
874eaee90eSRui Paulo 	uint8_t		xlnaGainCh[AR5416_4K_MAX_CHAINS];	// 1
884eaee90eSRui Paulo 	uint8_t		txEndToXpaOff;				// 1
894eaee90eSRui Paulo 	uint8_t		txEndToRxOn;				// 1
904eaee90eSRui Paulo 	uint8_t		txFrameToXpaOn;				// 1
914eaee90eSRui Paulo 	uint8_t		thresh62;				// 1
924eaee90eSRui Paulo 	uint8_t		noiseFloorThreshCh[AR5416_4K_MAX_CHAINS];	// 1
934eaee90eSRui Paulo 	uint8_t		xpdGain;				// 1
944eaee90eSRui Paulo 	uint8_t		xpd;					// 1
954eaee90eSRui Paulo 	int8_t		iqCalICh[AR5416_4K_MAX_CHAINS];		// 1
964eaee90eSRui Paulo 	int8_t		iqCalQCh[AR5416_4K_MAX_CHAINS];		// 1
97fb14f716SAdrian Chadd 
984eaee90eSRui Paulo 	uint8_t		pdGainOverlap;				// 1
99fb14f716SAdrian Chadd 
1003545027dSAdrian Chadd #ifdef __BIG_ENDIAN_BITFIELD
1013545027dSAdrian Chadd 	uint8_t		ob_1:4, ob_0:4;				// 1
1023545027dSAdrian Chadd 	uint8_t		db1_1:4, db1_0:4;			// 1
103fb14f716SAdrian Chadd #else
104fb14f716SAdrian Chadd 	uint8_t		ob_0:4, ob_1:4;
105fb14f716SAdrian Chadd 	uint8_t		db1_0:4, db1_1:4;
1064eaee90eSRui Paulo #endif
107fb14f716SAdrian Chadd 
108fb14f716SAdrian Chadd 	uint8_t		xpaBiasLvl;				// 1
1094eaee90eSRui Paulo 	uint8_t		txFrameToDataStart;			// 1
1104eaee90eSRui Paulo 	uint8_t		txFrameToPaOn;				// 1
1114eaee90eSRui Paulo 	uint8_t		ht40PowerIncForPdadc;			// 1
1124eaee90eSRui Paulo 	uint8_t		bswAtten[AR5416_4K_MAX_CHAINS];		// 1
1134eaee90eSRui Paulo 	uint8_t		bswMargin[AR5416_4K_MAX_CHAINS];	// 1
1144eaee90eSRui Paulo 	uint8_t		swSettleHt40;				// 1
1154eaee90eSRui Paulo 	uint8_t		xatten2Db[AR5416_4K_MAX_CHAINS];    	// 1
1164eaee90eSRui Paulo 	uint8_t		xatten2Margin[AR5416_4K_MAX_CHAINS];	// 1
117fb14f716SAdrian Chadd 
1183545027dSAdrian Chadd #ifdef __BIG_ENDIAN_BITFIELD
119fb14f716SAdrian Chadd         uint8_t		db2_1:4, db2_0:4;			// 1
120fb14f716SAdrian Chadd #else
121fb14f716SAdrian Chadd 	uint8_t		db2_0:4, db2_1:4;			// 1
122fb14f716SAdrian Chadd #endif
123fb14f716SAdrian Chadd 
124fb14f716SAdrian Chadd 	uint8_t		version;				// 1
125fb14f716SAdrian Chadd 
1263545027dSAdrian Chadd #ifdef __BIG_ENDIAN_BITFIELD
1273545027dSAdrian Chadd 	uint8_t		ob_3:4, ob_2:4;				// 1
1283545027dSAdrian Chadd 	uint8_t		antdiv_ctl1:4, ob_4:4;			// 1
1293545027dSAdrian Chadd 	uint8_t		db1_3:4, db1_2:4;			// 1
1303545027dSAdrian Chadd 	uint8_t		antdiv_ctl2:4, db1_4:4;			// 1
1313545027dSAdrian Chadd 	uint8_t		db2_2:4, db2_3:4;			// 1
1323545027dSAdrian Chadd 	uint8_t		reserved:4, db2_4:4;			// 1
133fb14f716SAdrian Chadd #else
134fb14f716SAdrian Chadd 	uint8_t		ob_2:4, ob_3:4;
135fb14f716SAdrian Chadd 	uint8_t		ob_4:4, antdiv_ctl1:4;
136fb14f716SAdrian Chadd 	uint8_t		db1_2:4, db1_3:4;
137fb14f716SAdrian Chadd 	uint8_t		db1_4:4, antdiv_ctl2:4;
138fb14f716SAdrian Chadd 	uint8_t		db2_2:4, db2_3:4;
139fb14f716SAdrian Chadd 	uint8_t		db2_4:4, reserved:4;
140fb14f716SAdrian Chadd #endif
14169849895SAdrian Chadd 	uint8_t		tx_diversity;
14269849895SAdrian Chadd 	uint8_t		flc_pwr_thresh;
14369849895SAdrian Chadd 	uint8_t		bb_scale_smrt_antenna;
14469849895SAdrian Chadd #define	EEP_4K_BB_DESIRED_SCALE_MASK	0x1f
14569849895SAdrian Chadd 	uint8_t		futureModal[1];
1464eaee90eSRui Paulo 
1474eaee90eSRui Paulo 	SPUR_CHAN spurChans[AR5416_EEPROM_MODAL_SPURS];	// 20 B
1483545027dSAdrian Chadd } __packed MODAL_EEP4K_HEADER;				// == 68 B
1494eaee90eSRui Paulo 
1504eaee90eSRui Paulo typedef struct CalCtlData4k {
1514eaee90eSRui Paulo 	CAL_CTL_EDGES		ctlEdges[AR5416_4K_MAX_CHAINS][AR5416_4K_NUM_BAND_EDGES];
1524eaee90eSRui Paulo } __packed CAL_CTL_DATA_4K;
1534eaee90eSRui Paulo 
1544eaee90eSRui Paulo typedef struct calDataPerFreq4k {
155f3d3bf87SRui Paulo 	uint8_t		pwrPdg[AR5416_4K_NUM_PD_GAINS][AR5416_PD_GAIN_ICEPTS];
156f3d3bf87SRui Paulo 	uint8_t		vpdPdg[AR5416_4K_NUM_PD_GAINS][AR5416_PD_GAIN_ICEPTS];
1574eaee90eSRui Paulo } __packed CAL_DATA_PER_FREQ_4K;
1584eaee90eSRui Paulo 
1594eaee90eSRui Paulo struct ar5416eeprom_4k {
1604eaee90eSRui Paulo 	BASE_EEP4K_HEADER	baseEepHeader;         // 32 B
1614eaee90eSRui Paulo 	uint8_t			custData[20];          // 20 B
1624eaee90eSRui Paulo 	MODAL_EEP4K_HEADER	modalHeader;           // 68 B
1634eaee90eSRui Paulo 	uint8_t			calFreqPier2G[AR5416_4K_NUM_2G_CAL_PIERS];
1644eaee90eSRui Paulo 	CAL_DATA_PER_FREQ_4K	calPierData2G[AR5416_4K_MAX_CHAINS][AR5416_4K_NUM_2G_CAL_PIERS];
1654eaee90eSRui Paulo 	CAL_TARGET_POWER_LEG	calTargetPowerCck[AR5416_4K_NUM_2G_CCK_TARGET_POWERS];
1664eaee90eSRui Paulo 	CAL_TARGET_POWER_LEG	calTargetPower2G[AR5416_4K_NUM_2G_20_TARGET_POWERS];
1674eaee90eSRui Paulo 	CAL_TARGET_POWER_HT	calTargetPower2GHT20[AR5416_4K_NUM_2G_20_TARGET_POWERS];
1684eaee90eSRui Paulo 	CAL_TARGET_POWER_HT	calTargetPower2GHT40[AR5416_4K_NUM_2G_40_TARGET_POWERS];
1694eaee90eSRui Paulo 	uint8_t			ctlIndex[AR5416_4K_NUM_CTLS];
1704eaee90eSRui Paulo 	CAL_CTL_DATA_4K		ctlData[AR5416_4K_NUM_CTLS];
1714eaee90eSRui Paulo 	uint8_t			padding;
1724eaee90eSRui Paulo } __packed;
1734eaee90eSRui Paulo 
1744eaee90eSRui Paulo typedef struct {
1754eaee90eSRui Paulo 	struct ar5416eeprom_4k ee_base;
1764eaee90eSRui Paulo #define NUM_EDGES	 8
1774eaee90eSRui Paulo 	uint16_t	ee_numCtls;
1784eaee90eSRui Paulo 	RD_EDGES_POWER	ee_rdEdgesPower[NUM_EDGES*AR5416_4K_NUM_CTLS];
1794eaee90eSRui Paulo 	/* XXX these are dynamically calculated for use by shared code */
1804f49ef43SRui Paulo 	int8_t		ee_antennaGainMax;
1814eaee90eSRui Paulo } HAL_EEPROM_v4k;
1824eaee90eSRui Paulo #endif /* _AH_EEPROM_V4K_H_ */
183