]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/tools/ath/ath_ee_v4k_print/v4k.c
Merge lldb trunk r321017 to contrib/llvm/tools/lldb.
[FreeBSD/FreeBSD.git] / tools / tools / ath / ath_ee_v4k_print / v4k.c
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 <sys/types.h>
30
31 #include <err.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <unistd.h>
36
37 typedef enum {
38         AH_FALSE = 0,           /* NB: lots of code assumes false is zero */
39         AH_TRUE  = 1,
40 } HAL_BOOL;
41
42 typedef enum {
43         HAL_OK          = 0,    /* No error */
44 } HAL_STATUS;
45
46 struct ath_hal;
47
48 #include "ah_eeprom_v4k.h"
49
50 void
51 eeprom_v4k_base_print(uint16_t *buf)
52 {
53         HAL_EEPROM_v4k *eep = (HAL_EEPROM_v4k *) buf;
54         BASE_EEP4K_HEADER *eh = &eep->ee_base.baseEepHeader;
55
56         printf("| Version: 0x%.4x   | Length: 0x%.4x | Checksum: 0x%.4x ",
57             eh->version, eh->length, eh->checksum);
58         printf("| CapFlags: 0x%.2x  | eepMisc: 0x%.2x | RegDomain: 0x%.4x 0x%.4x | \n",
59             eh->opCapFlags, eh->eepMisc, eh->regDmn[0], eh->regDmn[1]);
60         printf("| MAC: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x ",
61             eh->macAddr[0], eh->macAddr[1], eh->macAddr[2],
62             eh->macAddr[3], eh->macAddr[4], eh->macAddr[5]);
63         printf("| RxMask: 0x%.2x | TxMask: 0x%.2x | RfSilent: 0x%.4x | btOptions: 0x%.4x |\n",
64             eh->rxMask, eh->txMask, eh->rfSilent, eh->blueToothOptions);
65         printf("| DeviceCap: 0x%.4x | binBuildNumber: %.8x | deviceType: 0x%.2x | txGainType 0x%.2x |\n",
66             eh->deviceCap, eh->binBuildNumber, eh->deviceType, eh->txGainType);
67 }
68
69 void
70 eeprom_v4k_custdata_print(uint16_t *buf)
71 {
72         HAL_EEPROM_v4k *eep = (HAL_EEPROM_v4k *) buf;
73         uint8_t *custdata = (uint8_t *) &eep->ee_base.custData;
74         int i;
75
76         printf("\n| Custdata:                                       |\n");
77         for (i = 0; i < 20; i++) {
78                 printf("%s0x%.2x %s",
79                     i % 16 == 0 ? "| " : "",
80                     custdata[i],
81                     i % 16 == 15 ? "|\n" : "");
82         }
83         printf("\n");
84 }
85
86 void
87 eeprom_v4k_modal_print(uint16_t *buf)
88 {
89         HAL_EEPROM_v4k *eep = (HAL_EEPROM_v4k *) buf;
90         MODAL_EEP4K_HEADER *mh = &eep->ee_base.modalHeader;
91         int i;
92
93         printf("| antCtrlCommon: 0x%.8x |\n", mh->antCtrlCommon);
94         printf("| switchSettling: 0x%.2x |\n", mh->switchSettling);
95         printf("| adcDesiredSize: %d |\n| pgaDesiredSize: %.2f dBm |\n",
96             mh->adcDesiredSize, (float) mh->pgaDesiredSize / 2.0);
97
98         printf("| antCtrlChain:        0:0x%.4x |\n", mh->antCtrlChain[0]);
99         printf("| antennaGainCh:       0:0x%.2x |\n", mh->antennaGainCh[0]);
100         printf("| txRxAttenCh:         0:0x%.2x |\n", mh->txRxAttenCh[0]);
101         printf("| rxTxMarginCh:        0:0x%.2x |\n", mh->rxTxMarginCh[0]);
102         printf("| noiseFloorThresCh:   0:0x%.2x |\n", mh->noiseFloorThreshCh[0]);
103         printf("| xlnaGainCh:          0:0x%.2x |\n", mh->xlnaGainCh[0]);
104         printf("| iqCalICh:            0:0x%.2x |\n", mh->iqCalICh[0]);
105         printf("| iqCalQCh:            0:0x%.2x |\n", mh->iqCalQCh[0]);
106         printf("| bswAtten:            0:0x%.2x |\n", mh->bswAtten[0]);
107         printf("| bswMargin:           0:0x%.2x |\n", mh->bswMargin[0]);
108         printf("| xatten2Db:           0:0x%.2x |\n", mh->xatten2Db[0]);
109         printf("| xatten2Margin:       0:0x%.2x |\n", mh->xatten2Margin[0]);
110
111         printf("| txEndToXpaOff: 0x%.2x | txEndToRxOn: 0x%.2x | txFrameToXpaOn: 0x%.2x |\n",
112             mh->txEndToXpaOff, mh->txEndToRxOn, mh->txFrameToXpaOn);
113         printf("| thres62: 0x%.2x\n", mh->thresh62);
114         printf("| xpdGain: 0x%.2x | xpd: 0x%.2x |\n", mh->xpdGain, mh->xpd);
115
116         printf("| pdGainOverlap: 0x%.2x xpaBiasLvl: 0x%.2x |\n", mh->pdGainOverlap, mh->xpaBiasLvl);
117         printf("| txFrameToDataStart: 0x%.2x | txFrameToPaOn: 0x%.2x |\n", mh->txFrameToDataStart, mh->txFrameToPaOn);
118         printf("| ht40PowerIncForPdadc: 0x%.2x |\n", mh->ht40PowerIncForPdadc);
119         printf("| swSettleHt40: 0x%.2x |\n", mh->swSettleHt40);
120
121         printf("| ob_0: 0x%.2x | ob_1: 0x%.2x | ob_2: 0x%.2x | ob_3: 0x%.2x |\n",
122             mh->ob_0, mh->ob_1, mh->ob_2, mh->ob_3);
123         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",
124             mh->db1_0, mh->db1_1, mh->db1_2, mh->db1_3, mh->db1_4);
125         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",
126             mh->db2_0, mh->db2_1, mh->db2_2, mh->db2_3, mh->db2_4);
127
128         printf("| antdiv_ctl1: 0x%.2x antdiv_ctl2: 0x%.2x |\n", mh->antdiv_ctl1, mh->antdiv_ctl2);
129
130         printf("| Modal Version: %.2x |\n", mh->version);
131
132         printf("| tx_diversity: 0x%.2x |\n", mh->tx_diversity);
133         printf("| flc_pwr_thresh: 0x%.2x |\n", mh->flc_pwr_thresh);
134         printf("| bb_scale_smrt_antenna: 0x%.2x |\n", mh->bb_scale_smrt_antenna);
135         printf("| futureModal: 0x%.2x |\n", mh->futureModal[0]);
136
137         /* and now, spur channels */
138         for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
139                 printf("| Spur %d: spurChan: 0x%.4x spurRangeLow: 0x%.2x spurRangeHigh: 0x%.2x |\n",
140                     i, mh->spurChans[i].spurChan,
141                     (int) mh->spurChans[i].spurRangeLow,
142                     (int) mh->spurChans[i].spurRangeHigh);
143         }
144 }
145
146 static void
147 eeprom_v4k_print_caldata_perfreq(CAL_DATA_PER_FREQ_4K *f)
148 {
149         int i, j;
150
151         for (i = 0; i < AR5416_4K_NUM_PD_GAINS; i++) {
152                 printf("    Gain %d: pwr dBm/vpd: ", i);
153                 for (j = 0; j < AR5416_PD_GAIN_ICEPTS; j++) {
154                         /* These are stored in 0.25dBm increments */
155                         /* XXX is this assumption correct for ar9285? */
156                         /* XXX shouldn't we care about the power table offset, if there is one? */
157                         printf("%d:(%.2f/%d) ", j, (float) f->pwrPdg[i][j] / 4.00,
158                             f->vpdPdg[i][j]);
159                 }
160                 printf("\n");
161         }
162 }
163
164 void
165 eeprom_v4k_calfreqpiers_print(uint16_t *buf)
166 {
167         HAL_EEPROM_v4k *eep = (HAL_EEPROM_v4k *) buf;
168         int i, n;
169
170         /* 2ghz cal piers */
171         printf("calFreqPier2G: ");
172         for (i = 0; i < AR5416_4K_NUM_2G_CAL_PIERS; i++) {
173                 printf(" 0x%.2x ", eep->ee_base.calFreqPier2G[i]);
174         }
175         printf("|\n");
176
177         for (i = 0; i < AR5416_4K_NUM_2G_CAL_PIERS; i++) {
178                 if (eep->ee_base.calFreqPier2G[i] == 0xff)
179                         continue;
180                 printf("2Ghz Cal Pier %d\n", i);
181                 for (n = 0; n < AR5416_4K_MAX_CHAINS; n++) {
182                         printf("  Chain %d:\n", n);
183                         eeprom_v4k_print_caldata_perfreq(&eep->ee_base.calPierData2G[n][i]);
184                 }
185         }
186
187         printf("\n");
188 }
189
190 /* XXX these should just reference the v14 print routines */
191 static void
192 eeprom_v14_target_legacy_print(CAL_TARGET_POWER_LEG *l)
193 {
194         int i;
195         if (l->bChannel == 0xff)
196                 return;
197         printf("  bChannel: %d;", l->bChannel);
198         for (i = 0; i < 4; i++) {
199                 printf(" %.2f", (float) l->tPow2x[i] / 2.0);
200         }
201         printf(" (dBm)\n");
202 }
203
204 static void
205 eeprom_v14_target_ht_print(CAL_TARGET_POWER_HT *l)
206 {
207         int i;
208         if (l->bChannel == 0xff)
209                 return;
210         printf("  bChannel: %d;", l->bChannel);
211         for (i = 0; i < 8; i++) {
212                 printf(" %.2f", (float) l->tPow2x[i] / 2.0);
213         }
214         printf(" (dBm)\n");
215 }
216
217 void
218 eeprom_v4k_print_targets(uint16_t *buf)
219 {
220         HAL_EEPROM_v4k *eep = (HAL_EEPROM_v4k *) buf;
221         int i;
222
223         /* 2ghz rates */
224         printf("2Ghz CCK:\n");
225         for (i = 0; i < AR5416_4K_NUM_2G_CCK_TARGET_POWERS; i++) {
226                 eeprom_v14_target_legacy_print(&eep->ee_base.calTargetPowerCck[i]);
227         }
228         printf("2Ghz 11g:\n");
229         for (i = 0; i < AR5416_4K_NUM_2G_20_TARGET_POWERS; i++) {
230                 eeprom_v14_target_legacy_print(&eep->ee_base.calTargetPower2G[i]);
231         }
232         printf("2Ghz HT20:\n");
233         for (i = 0; i < AR5416_4K_NUM_2G_20_TARGET_POWERS; i++) {
234                 eeprom_v14_target_ht_print(&eep->ee_base.calTargetPower2GHT20[i]);
235         }
236         printf("2Ghz HT40:\n");
237         for (i = 0; i < AR5416_4K_NUM_2G_40_TARGET_POWERS; i++) {
238                 eeprom_v14_target_ht_print(&eep->ee_base.calTargetPower2GHT40[i]);
239         }
240
241 }
242
243 static void
244 eeprom_v4k_ctl_edge_print(CAL_CTL_DATA_4K *ctl)
245 {
246         int i, j;
247         uint8_t pow, flag;
248
249         for (i = 0; i < AR5416_4K_MAX_CHAINS; i++) {
250                 printf("  chain %d: ", i);
251                 for (j = 0; j < AR5416_4K_NUM_BAND_EDGES; j++) {
252                         pow = ctl->ctlEdges[i][j].tPowerFlag & 0x3f;
253                         flag = (ctl->ctlEdges[i][j].tPowerFlag & 0xc0) >> 6;
254                         printf(" %d:pow=%d,flag=%.2x", j, pow, flag);
255                 }
256                 printf("\n");
257         }
258 }
259
260 void
261 eeprom_v4k_ctl_print(uint16_t *buf)
262 {
263         HAL_EEPROM_v4k *eep = (HAL_EEPROM_v4k *) buf;
264         int i;
265
266         for (i = 0; i < AR5416_4K_NUM_CTLS; i++) {
267                 if (eep->ee_base.ctlIndex[i] == 0)
268                         continue;
269                 printf("| ctlIndex: offset %d, value %d\n", i, eep->ee_base.ctlIndex[i]);
270                 eeprom_v4k_ctl_edge_print(&eep->ee_base.ctlData[i]);
271         }
272 }
273
274 void
275 eeprom_v4k_print_edges(uint16_t *buf)
276 {
277         HAL_EEPROM_v4k *eep = (HAL_EEPROM_v4k *) buf;
278         int i;
279
280         printf("| eeNumCtls: %d\n", eep->ee_numCtls);
281         for (i = 0; i < NUM_EDGES*eep->ee_numCtls; i++) {
282                 /* XXX is flag 8 or 32 bits? */
283                 printf("|  edge %2d/%2d: rdEdge: %5d EdgePower: %.2f dBm Flag: 0x%.8x\n",
284                         i / NUM_EDGES, i % NUM_EDGES,
285                         eep->ee_rdEdgesPower[i].rdEdge,
286                         (float) eep->ee_rdEdgesPower[i].twice_rdEdgePower / 2.0,
287                         eep->ee_rdEdgesPower[i].flag);
288
289                 if (i % NUM_EDGES == (NUM_EDGES -1))
290                         printf("|\n");
291         }
292 }
293
294 void
295 eeprom_v4k_print_other(uint16_t *buf)
296 {
297         HAL_EEPROM_v4k *eep = (HAL_EEPROM_v4k *) buf;
298         printf("| ee_antennaGainMax: %.2x\n", eep->ee_antennaGainMax);
299 }