1
2/*
3 * Copyright (c) 2010-2011 Adrian Chadd, Xenion Pty Ltd.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD$
27 */
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <unistd.h>
32#include <string.h>
33#include <sys/types.h>
34#include <err.h>
35
36typedef enum {
37        AH_FALSE = 0,           /* NB: lots of code assumes false is zero */
38        AH_TRUE  = 1,
39} HAL_BOOL;
40
41typedef enum {
42        HAL_OK          = 0,    /* No error */
43} HAL_STATUS;
44
45struct ath_hal;
46
47#include "ah_eeprom_v4k.h"
48
49void
50eeprom_v4k_base_print(uint16_t *buf)
51{
52	HAL_EEPROM_v4k *eep = (HAL_EEPROM_v4k *) buf;
53	BASE_EEP4K_HEADER *eh = &eep->ee_base.baseEepHeader;
54
55	printf("| Version: 0x%.4x   | Length: 0x%.4x | Checksum: 0x%.4x ",
56	    eh->version, eh->length, eh->checksum);
57	printf("| CapFlags: 0x%.2x  | eepMisc: 0x%.2x | RegDomain: 0x%.4x 0x%.4x | \n",
58	    eh->opCapFlags, eh->eepMisc, eh->regDmn[0], eh->regDmn[1]);
59	printf("| MAC: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x ",
60	    eh->macAddr[0], eh->macAddr[1], eh->macAddr[2],
61	    eh->macAddr[3], eh->macAddr[4], eh->macAddr[5]);
62	printf("| RxMask: 0x%.2x | TxMask: 0x%.2x | RfSilent: 0x%.4x | btOptions: 0x%.4x |\n",
63	    eh->rxMask, eh->txMask, eh->rfSilent, eh->blueToothOptions);
64	printf("| DeviceCap: 0x%.4x | binBuildNumber: %.8x | deviceType: 0x%.2x | txGainType 0x%.2x |\n",
65	    eh->deviceCap, eh->binBuildNumber, eh->deviceType, eh->txGainType);
66}
67
68void
69eeprom_v4k_custdata_print(uint16_t *buf)
70{
71	HAL_EEPROM_v4k *eep = (HAL_EEPROM_v4k *) buf;
72	uint8_t *custdata = (uint8_t *) &eep->ee_base.custData;
73	int i;
74
75	printf("\n| Custdata:                                       |\n");
76	for (i = 0; i < 20; i++) {
77		printf("%s0x%.2x %s",
78		    i % 16 == 0 ? "| " : "",
79		    custdata[i],
80		    i % 16 == 15 ? "|\n" : "");
81	}
82	printf("\n");
83}
84
85void
86eeprom_v4k_modal_print(uint16_t *buf)
87{
88	HAL_EEPROM_v4k *eep = (HAL_EEPROM_v4k *) buf;
89	MODAL_EEP4K_HEADER *mh = &eep->ee_base.modalHeader;
90	int i;
91
92	printf("| antCtrlCommon: 0x%.8x |\n", mh->antCtrlCommon);
93	printf("| switchSettling: 0x%.2x |\n", mh->switchSettling);
94	printf("| adcDesiredSize: %d |\n| pgaDesiredSize: %.2f dBm |\n",
95	    mh->adcDesiredSize, (float) mh->pgaDesiredSize / 2.0);
96
97	printf("| antCtrlChain:        0:0x%.4x |\n", mh->antCtrlChain[0]);
98	printf("| antennaGainCh:       0:0x%.2x |\n", mh->antennaGainCh[0]);
99	printf("| txRxAttenCh:         0:0x%.2x |\n", mh->txRxAttenCh[0]);
100	printf("| rxTxMarginCh:        0:0x%.2x |\n", mh->rxTxMarginCh[0]);
101 	printf("| noiseFloorThresCh:   0:0x%.2x |\n", mh->noiseFloorThreshCh[0]);
102	printf("| xlnaGainCh:          0:0x%.2x |\n", mh->xlnaGainCh[0]);
103	printf("| iqCalICh:            0:0x%.2x |\n", mh->iqCalICh[0]);
104	printf("| iqCalQCh:            0:0x%.2x |\n", mh->iqCalQCh[0]);
105	printf("| bswAtten:            0:0x%.2x |\n", mh->bswAtten[0]);
106	printf("| bswMargin:           0:0x%.2x |\n", mh->bswMargin[0]);
107	printf("| xatten2Db:           0:0x%.2x |\n", mh->xatten2Db[0]);
108	printf("| xatten2Margin:       0:0x%.2x |\n", mh->xatten2Margin[0]);
109
110	printf("| txEndToXpaOff: 0x%.2x | txEndToRxOn: 0x%.2x | txFrameToXpaOn: 0x%.2x |\n",
111	    mh->txEndToXpaOff, mh->txEndToRxOn, mh->txFrameToXpaOn);
112	printf("| thres62: 0x%.2x\n", mh->thresh62);
113	printf("| xpdGain: 0x%.2x | xpd: 0x%.2x |\n", mh->xpdGain, mh->xpd);
114
115	printf("| pdGainOverlap: 0x%.2x xpaBiasLvl: 0x%.2x |\n", mh->pdGainOverlap, mh->xpaBiasLvl);
116	printf("| txFrameToDataStart: 0x%.2x | txFrameToPaOn: 0x%.2x |\n", mh->txFrameToDataStart, mh->txFrameToPaOn);
117	printf("| ht40PowerIncForPdadc: 0x%.2x |\n", mh->ht40PowerIncForPdadc);
118	printf("| swSettleHt40: 0x%.2x |\n", mh->swSettleHt40);
119
120	printf("| ob_0: 0x%.2x | ob_1: 0x%.2x | ob_2: 0x%.2x | ob_3: 0x%.2x |\n",
121	    mh->ob_0, mh->ob_1, mh->ob_2, mh->ob_3);
122	printf("| db_1_0: 0x%.2x | db_1_1: 0x%.2x | db_1_2: 0x%.2x | db_1_3: 0x%.2x db_1_4: 0x%.2x|\n",
123	    mh->db1_0, mh->db1_1, mh->db1_2, mh->db1_3, mh->db1_4);
124	printf("| db_1_0: 0x%.2x | db_1_1: 0x%.2x | db_1_2: 0x%.2x | db_1_3: 0x%.2x db_1_4: 0x%.2x|\n",
125	    mh->db2_0, mh->db2_1, mh->db2_2, mh->db2_3, mh->db2_4);
126
127	printf("| antdiv_ctl1: 0x%.2x antdiv_ctl2: 0x%.2x |\n", mh->antdiv_ctl1, mh->antdiv_ctl2);
128
129	printf("| Modal Version: %.2x |\n", mh->version);
130
131	printf("| futureModal: 0x%.2x 0x%.2x 0x%.2x 0x%.2x |\n",
132	    mh->futureModal[0],
133	    mh->futureModal[1],
134	    mh->futureModal[2],
135	    mh->futureModal[3]
136	);
137
138	/* and now, spur channels */
139	for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
140		printf("| Spur %d: spurChan: 0x%.4x spurRangeLow: 0x%.2x spurRangeHigh: 0x%.2x |\n",
141		    i, mh->spurChans[i].spurChan,
142		    (int) mh->spurChans[i].spurRangeLow,
143		    (int) mh->spurChans[i].spurRangeHigh);
144	}
145}
146
147static void
148eeprom_v4k_print_caldata_perfreq(CAL_DATA_PER_FREQ_4K *f)
149{
150	int i, j;
151
152	for (i = 0; i < AR5416_4K_NUM_PD_GAINS; i++) {
153		printf("    Gain %d: pwr dBm/vpd: ", i);
154		for (j = 0; j < AR5416_PD_GAIN_ICEPTS; j++) {
155			/* These are stored in 0.25dBm increments */
156			/* XXX is this assumption correct for ar9285? */
157			/* XXX shouldn't we care about the power table offset, if there is one? */
158			printf("%d:(%.2f/%d) ", j, (float) f->pwrPdg[i][j] / 4.00,
159			    f->vpdPdg[i][j]);
160		}
161		printf("\n");
162	}
163}
164
165void
166eeprom_v4k_calfreqpiers_print(uint16_t *buf)
167{
168	HAL_EEPROM_v4k *eep = (HAL_EEPROM_v4k *) buf;
169	int i, n;
170
171	/* 2ghz cal piers */
172	printf("calFreqPier2G: ");
173	for (i = 0; i < AR5416_4K_NUM_2G_CAL_PIERS; i++) {
174		printf(" 0x%.2x ", eep->ee_base.calFreqPier2G[i]);
175	}
176	printf("|\n");
177
178	for (i = 0; i < AR5416_4K_NUM_2G_CAL_PIERS; i++) {
179		if (eep->ee_base.calFreqPier2G[i] == 0xff)
180			continue;
181		printf("2Ghz Cal Pier %d\n", i);
182		for (n = 0; n < AR5416_4K_MAX_CHAINS; n++) {
183			printf("  Chain %d:\n", n);
184			eeprom_v4k_print_caldata_perfreq(&eep->ee_base.calPierData2G[n][i]);
185		}
186	}
187
188	printf("\n");
189}
190
191/* XXX these should just reference the v14 print routines */
192static void
193eeprom_v14_target_legacy_print(CAL_TARGET_POWER_LEG *l)
194{
195	int i;
196	if (l->bChannel == 0xff)
197		return;
198	printf("  bChannel: %d;", l->bChannel);
199	for (i = 0; i < 4; i++) {
200		printf(" %.2f", (float) l->tPow2x[i] / 2.0);
201	}
202	printf(" (dBm)\n");
203}
204
205static void
206eeprom_v14_target_ht_print(CAL_TARGET_POWER_HT *l)
207{
208	int i;
209	if (l->bChannel == 0xff)
210		return;
211	printf("  bChannel: %d;", l->bChannel);
212	for (i = 0; i < 8; i++) {
213		printf(" %.2f", (float) l->tPow2x[i] / 2.0);
214	}
215	printf(" (dBm)\n");
216}
217
218void
219eeprom_v4k_print_targets(uint16_t *buf)
220{
221	HAL_EEPROM_v4k *eep = (HAL_EEPROM_v4k *) buf;
222	int i;
223
224	/* 2ghz rates */
225	printf("2Ghz CCK:\n");
226	for (i = 0; i < AR5416_4K_NUM_2G_CCK_TARGET_POWERS; i++) {
227		eeprom_v14_target_legacy_print(&eep->ee_base.calTargetPowerCck[i]);
228	}
229	printf("2Ghz 11g:\n");
230	for (i = 0; i < AR5416_4K_NUM_2G_20_TARGET_POWERS; i++) {
231		eeprom_v14_target_legacy_print(&eep->ee_base.calTargetPower2G[i]);
232	}
233	printf("2Ghz HT20:\n");
234	for (i = 0; i < AR5416_4K_NUM_2G_20_TARGET_POWERS; i++) {
235		eeprom_v14_target_ht_print(&eep->ee_base.calTargetPower2GHT20[i]);
236	}
237	printf("2Ghz HT40:\n");
238	for (i = 0; i < AR5416_4K_NUM_2G_40_TARGET_POWERS; i++) {
239		eeprom_v14_target_ht_print(&eep->ee_base.calTargetPower2GHT40[i]);
240	}
241
242}
243
244static void
245eeprom_v4k_ctl_edge_print(CAL_CTL_DATA_4K *ctl)
246{
247	int i, j;
248	uint8_t pow, flag;
249
250	for (i = 0; i < AR5416_4K_MAX_CHAINS; i++) {
251		printf("  chain %d: ", i);
252		for (j = 0; j < AR5416_4K_NUM_BAND_EDGES; j++) {
253			pow = ctl->ctlEdges[i][j].tPowerFlag & 0x3f;
254			flag = (ctl->ctlEdges[i][j].tPowerFlag & 0xc0) >> 6;
255			printf(" %d:pow=%d,flag=%.2x", j, pow, flag);
256		}
257		printf("\n");
258	}
259}
260
261void
262eeprom_v4k_ctl_print(uint16_t *buf)
263{
264	HAL_EEPROM_v4k *eep = (HAL_EEPROM_v4k *) buf;
265	int i;
266
267	for (i = 0; i < AR5416_4K_NUM_CTLS; i++) {
268		if (eep->ee_base.ctlIndex[i] == 0)
269			continue;
270		printf("| ctlIndex: offset %d, value %d\n", i, eep->ee_base.ctlIndex[i]);
271		eeprom_v4k_ctl_edge_print(&eep->ee_base.ctlData[i]);
272	}
273}
274
275void
276eeprom_v4k_print_edges(uint16_t *buf)
277{
278	HAL_EEPROM_v4k *eep = (HAL_EEPROM_v4k *) buf;
279	int i;
280
281	printf("| eeNumCtls: %d\n", eep->ee_numCtls);
282	for (i = 0; i < NUM_EDGES*eep->ee_numCtls; i++) {
283		/* XXX is flag 8 or 32 bits? */
284		printf("|  edge %2d/%2d: rdEdge: %5d EdgePower: %.2f dBm Flag: 0x%.8x\n",
285			i / NUM_EDGES, i % NUM_EDGES,
286			eep->ee_rdEdgesPower[i].rdEdge,
287			(float) eep->ee_rdEdgesPower[i].twice_rdEdgePower / 2.0,
288			eep->ee_rdEdgesPower[i].flag);
289
290		if (i % NUM_EDGES == (NUM_EDGES -1))
291			printf("|\n");
292	}
293}
294
295void
296eeprom_v4k_print_other(uint16_t *buf)
297{
298	HAL_EEPROM_v4k *eep = (HAL_EEPROM_v4k *) buf;
299	printf("| ee_antennaGainMax: %.2x\n", eep->ee_antennaGainMax);
300}
301