]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - tools/tools/ath/ath_ee_9300_print/main.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / tools / tools / ath / ath_ee_9300_print / main.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 <stdio.h>
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <string.h>
33 #include <sys/types.h>
34 #include <err.h>
35
36 struct ath_hal;
37
38 #include "ar9300/ar9300eep.h"
39
40 static void
41 eeprom_9300_hdr_print(const uint16_t *buf)
42 {
43         const ar9300_eeprom_t *ee = (ar9300_eeprom_t *) buf;
44
45         printf("| Version: %d, Template: %d, MAC: %02x:%02x:%02x:%02x:%02x:%02x |\n",
46             ee->eeprom_version,
47             ee->template_version,
48             ee->mac_addr[0],
49             ee->mac_addr[1],
50             ee->mac_addr[2],
51             ee->mac_addr[3],
52             ee->mac_addr[4],
53             ee->mac_addr[5]);
54 }
55
56 static void
57 eeprom_9300_base_print(const uint16_t *buf)
58 {
59         const ar9300_eeprom_t *ee = (ar9300_eeprom_t *) buf;
60         const OSPREY_BASE_EEP_HEADER *ee_base = &ee->base_eep_header;
61
62         printf("| RegDomain: 0x%02x 0x%02x TxRxMask: 0x%02x OpFlags: 0x%02x OpMisc: 0x%02x |\n",
63             ee_base->reg_dmn[0],
64             ee_base->reg_dmn[1],
65             ee_base->txrx_mask,
66             ee_base->op_cap_flags.op_flags,
67             ee_base->op_cap_flags.eepMisc);
68
69         printf("| RfSilent: 0x%02x BtOptions: 0x%02x DeviceCap: 0x%02x DeviceType: 0x%02x |\n",
70             ee_base->rf_silent,
71             ee_base->blue_tooth_options,
72             ee_base->device_cap,
73             ee_base->device_type);
74
75         printf("| pwrTableOffset: %d dB, feature_enable: 0x%02x MiscConfig: 0x%02x |\n",
76             ee_base->pwrTableOffset,
77             ee_base->feature_enable,
78             ee_base->misc_configuration);
79
80         printf("| EepromWriteGpio: %d, WlanDisableGpio: %d, WlanLedGpio: %d RxBandSelectGpio: %d |\n",
81             ee_base->eeprom_write_enable_gpio,
82             ee_base->wlan_disable_gpio,
83             ee_base->wlan_led_gpio,
84             ee_base->rx_band_select_gpio);
85
86         printf("| TxRxGain: %d, SwReg: %d |\n",
87             ee_base->txrxgain,
88             ee_base->swreg);
89 }
90
91 static void
92 eeprom_9300_modal_print(const OSPREY_MODAL_EEP_HEADER *m)
93 {
94         int i;
95
96         printf("| AntCtrl: 0x%08x AntCtrl2: 0x%08x |\n",
97             m->ant_ctrl_common,
98             m->ant_ctrl_common2);
99
100         for (i = 0; i < OSPREY_MAX_CHAINS; i++) {
101                 printf("| Ch %d: AntCtrl: 0x%08x Atten1: %d, atten1_margin: %d, NfThresh: %d |\n",
102                     i,
103                     m->ant_ctrl_chain[i],
104                     m->xatten1_db[i],
105                     m->xatten1_margin[i],
106                     m->noise_floor_thresh_ch[i]);
107         }
108
109         printf("| Spur: ");
110         for (i = 0; i < OSPREY_EEPROM_MODAL_SPURS; i++) {
111                 printf("(%d: %d) ", i, m->spur_chans[i]);
112         }
113         printf("|\n");
114
115         printf("| TempSlope: %d, VoltSlope: %d, QuickDrop: %d, XpaBiasLvl %d |\n",
116             m->temp_slope,
117             m->voltSlope,
118             m->quick_drop,
119             m->xpa_bias_lvl);
120
121         printf("| txFrameToDataStart: %d, TxFrameToPaOn: %d, TxEndToXpaOff: %d, TxEndToRxOn: %d, TxFrameToXpaOn: %d |\n",
122             m->tx_frame_to_data_start,
123             m->tx_frame_to_pa_on,
124             m->tx_end_to_xpa_off,
125             m->txEndToRxOn,
126             m->tx_frame_to_xpa_on);
127
128         printf("| txClip: %d, AntGain: %d, SwitchSettling: %d, adcDesiredSize: %d |\n",
129             m->txClip,
130             m->antenna_gain,
131             m->switchSettling,
132             m->adcDesiredSize);
133
134         printf("| Thresh62: %d, PaprdMaskHt20: 0x%08x, PaPrdMaskHt40: 0x%08x |\n",
135             m->thresh62,
136             m->paprd_rate_mask_ht20,
137             m->paprd_rate_mask_ht40);
138
139         printf("| SwitchComSpdt: %02x, XlnaBiasStrength: %d, RfGainCap: %d, TxGainCap: %x\n",
140             m->switchcomspdt,
141             m->xLNA_bias_strength,
142             m->rf_gain_cap,
143             m->tx_gain_cap);
144
145 #if 0
146     u_int8_t   reserved[MAX_MODAL_RESERVED];
147     u_int16_t  switchcomspdt;
148     u_int8_t   xLNA_bias_strength;                      // bit: 0,1:chain0, 2,3:chain1, 4,5:chain2
149     u_int8_t   rf_gain_cap;
150     u_int8_t   tx_gain_cap;                             // bit0:4 txgain cap, txgain index for max_txgain + 20 (10dBm higher than max txgain)
151     u_int8_t   futureModal[MAX_MODAL_FUTURE];
152     // last 12 bytes stolen and moved to newly created base extension structure
153 #endif
154 }
155
156 static void
157 load_eeprom_dump(const char *file, uint16_t *buf)
158 {
159         unsigned int r[8];
160         FILE *fp;
161         char b[1024];
162         int i;
163
164         fp = fopen(file, "r");
165         if (!fp)
166                 err(1, "fopen");
167
168         while (!feof(fp)) {
169                 if (fgets(b, 1024, fp) == NULL)
170                         break;
171                 if (feof(fp))
172                         break;
173                 if (strlen(b) > 0)
174                         b[strlen(b)-1] = '\0';
175                 if (strlen(b) == 0)
176                         break;
177                 sscanf(b, "%x: %x %x %x %x %x %x %x %x\n",
178                     &i, &r[0], &r[1], &r[2], &r[3], &r[4],
179                     &r[5], &r[6], &r[7]);
180                 buf[i++] = r[0];
181                 buf[i++] = r[1];
182                 buf[i++] = r[2];
183                 buf[i++] = r[3];
184                 buf[i++] = r[4];
185                 buf[i++] = r[5];
186                 buf[i++] = r[6];
187                 buf[i++] = r[7];
188         }
189         fclose(fp);
190 }
191
192 void
193 usage(char *argv[])
194 {
195         printf("Usage: %s <eeprom dump file>\n", argv[0]);
196         printf("\n");
197         printf("  The eeprom dump file is a text hexdump of an EEPROM.\n");
198         printf("  The lines must be formatted as follows:\n");
199         printf("  0xAAAA: 0xDD 0xDD 0xDD 0xDD 0xDD 0xDD 0xDD 0xDD\n");
200         printf("  where each line must have exactly eight data bytes.\n");
201         exit(127);
202 }
203
204 int
205 main(int argc, char *argv[])
206 {
207         uint16_t *eep = NULL;
208         const ar9300_eeprom_t *ee;
209
210         eep = calloc(4096, sizeof(int16_t));
211
212         if (argc < 2)
213                 usage(argv);
214
215         load_eeprom_dump(argv[1], eep);
216         ee = (ar9300_eeprom_t *) eep;
217
218         eeprom_9300_hdr_print(eep);
219         eeprom_9300_base_print(eep);
220
221         printf("\n2GHz modal:\n");
222         eeprom_9300_modal_print(&ee->modal_header_2g);
223
224         printf("\n5GHz modal:\n");
225         eeprom_9300_modal_print(&ee->modal_header_5g);
226
227         free(eep);
228         exit(0);
229 }