-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy patheep_9287.c
489 lines (430 loc) · 15.5 KB
/
eep_9287.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
/*
* Copyright (c) 2012 Qualcomm Atheros, Inc.
* Copyright (c) 2013,2017-2020 Sergey Ryazanov <[email protected]>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "atheepmgr.h"
#include "utils.h"
#include "eep_common.h"
#include "eep_9287.h"
struct eep_9287_priv {
union {
struct ar5416_eep_init ini;
uint16_t init_data[AR9287_DATA_START_LOC];
};
struct ar9287_eeprom eep;
};
static int eep_9287_get_ver(struct eep_9287_priv *emp)
{
return (emp->eep.baseEepHeader.version >> 12) & 0xF;
}
static int eep_9287_get_rev(struct eep_9287_priv *emp)
{
return (emp->eep.baseEepHeader.version) & 0xFFF;
}
static bool eep_9287_load_eeprom(struct atheepmgr *aem, bool raw)
{
struct eep_9287_priv *emp = aem->eepmap_priv;
uint16_t *eep_data = (uint16_t *)&emp->eep;
uint16_t *eep_init = (uint16_t *)&emp->ini;
uint16_t *buf = aem->eep_buf;
int addr;
/* Check byteswaping requirements for non-RAW operation */
if (!raw && !AR5416_TOGGLE_BYTESWAP(9287))
return false;
/* Read to the intermediate buffer */
for (addr = 0; addr < AR9287_DATA_START_LOC + AR9287_DATA_SZ; ++addr) {
if (!EEP_READ(addr, &buf[addr])) {
fprintf(stderr, "Unable to read EEPROM to buffer\n");
return false;
}
}
aem->eep_len = addr;
if (raw) /* Earlier exit on RAW contents loading */
return true;
/* Copy from buffer to the Init data */
for (addr = 0; addr < AR9287_DATA_START_LOC; ++addr)
eep_init[addr] = buf[addr];
/* Copy from buffer to the EEPROM structure */
for (addr = 0; addr < AR9287_DATA_SZ; ++addr)
eep_data[addr] = buf[AR9287_DATA_START_LOC + addr];
return true;
}
static bool eep_9287_check_eeprom(struct atheepmgr *aem)
{
struct eep_9287_priv *emp = aem->eepmap_priv;
struct ar5416_eep_init *ini = &emp->ini;
struct ar9287_eeprom *eep = &emp->eep;
struct ar9287_base_eep_hdr *pBase = &eep->baseEepHeader;
const uint16_t *buf = aem->eep_buf;
uint16_t sum;
int i, el;
if (ini->magic != AR5416_EEPROM_MAGIC &&
bswap_16(ini->magic) != AR5416_EEPROM_MAGIC) {
fprintf(stderr, "Invalid EEPROM Magic 0x%04x, expected 0x%04x\n",
ini->magic, AR5416_EEPROM_MAGIC);
return false;
}
if (!!(pBase->eepMisc & AR5416_EEPMISC_BIG_ENDIAN) != aem->host_is_be) {
struct ar9287_modal_eep_hdr *pModal;
printf("EEPROM Endianness is not native.. Changing\n");
for (i = 0; i < ARRAY_SIZE(emp->init_data); ++i)
bswap_16_inplace(emp->init_data[i]);
bswap_16_inplace(pBase->length);
bswap_16_inplace(pBase->checksum);
bswap_16_inplace(pBase->version);
bswap_16_inplace(pBase->regDmn[0]);
bswap_16_inplace(pBase->regDmn[1]);
bswap_16_inplace(pBase->rfSilent);
bswap_16_inplace(pBase->blueToothOptions);
bswap_16_inplace(pBase->deviceCap);
bswap_32_inplace(pBase->binBuildNumber);
pModal = &eep->modalHeader;
bswap_32_inplace(pModal->antCtrlCommon);
for (i = 0; i < ARRAY_SIZE(pModal->antCtrlChain); ++i)
bswap_32_inplace(pModal->antCtrlChain[i]);
for (i = 0; i < ARRAY_SIZE(pModal->spurChans); ++i)
bswap_16_inplace(pModal->spurChans[i].spurChan);
}
if (eep_9287_get_ver(emp) != AR5416_EEP_VER ||
eep_9287_get_rev(emp) < AR5416_EEP_NO_BACK_VER) {
fprintf(stderr, "Bad EEPROM version 0x%04x (%d.%d)\n",
pBase->version, eep_9287_get_ver(emp),
eep_9287_get_rev(emp));
return false;
}
el = pBase->length / sizeof(uint16_t);
if (el > AR9287_DATA_SZ)
el = AR9287_DATA_SZ;
sum = eep_calc_csum(&buf[AR9287_DATA_START_LOC], el);
if (sum != 0xffff) {
fprintf(stderr, "Bad EEPROM checksum 0x%04x\n", sum);
return false;
}
return true;
}
static void eep_9287_dump_init_data(struct atheepmgr *aem)
{
struct eep_9287_priv *emp = aem->eepmap_priv;
struct ar5416_eep_init *ini = &emp->ini;
EEP_PRINT_SECT_NAME("Chip init data");
ar5416_dump_eep_init(ini, sizeof(emp->init_data) / 2);
}
static void eep_9287_dump_base_header(struct atheepmgr *aem)
{
struct eep_9287_priv *emp = aem->eepmap_priv;
struct ar9287_eeprom *eep = &emp->eep;
struct ar9287_base_eep_hdr *pBase = &eep->baseEepHeader;
EEP_PRINT_SECT_NAME("EEPROM Base Header");
printf("%-30s : %2d\n", "Major Version",
pBase->version >> 12);
printf("%-30s : %2d\n", "Minor Version",
pBase->version & 0xFFF);
printf("%-30s : 0x%04X\n", "Checksum",
pBase->checksum);
printf("%-30s : 0x%04X\n", "Length",
pBase->length);
printf("%-30s : 0x%04X\n", "RegDomain1",
pBase->regDmn[0]);
printf("%-30s : 0x%04X\n", "RegDomain2",
pBase->regDmn[1]);
printf("%-30s : %02X:%02X:%02X:%02X:%02X:%02X\n",
"MacAddress",
pBase->macAddr[0], pBase->macAddr[1], pBase->macAddr[2],
pBase->macAddr[3], pBase->macAddr[4], pBase->macAddr[5]);
printf("%-30s : 0x%04X\n",
"TX Mask", pBase->txMask);
printf("%-30s : 0x%04X\n",
"RX Mask", pBase->rxMask);
if (pBase->rfSilent & AR5416_RFSILENT_ENABLED)
printf("%-30s : GPIO:%u Pol:%c\n", "RfSilent",
MS(pBase->rfSilent, AR5416_RFSILENT_GPIO_SEL),
MS(pBase->rfSilent, AR5416_RFSILENT_POLARITY)?'H':'L');
else
printf("%-30s : disabled\n", "RfSilent");
printf("%-30s : %d\n",
"OpFlags(5GHz)",
!!(pBase->opCapFlags & AR5416_OPFLAGS_11A));
printf("%-30s : %d\n",
"OpFlags(2GHz)",
!!(pBase->opCapFlags & AR5416_OPFLAGS_11G));
printf("%-30s : %d\n",
"OpFlags(Disable 2GHz HT20)",
!!(pBase->opCapFlags & AR5416_OPFLAGS_N_2G_HT20));
printf("%-30s : %d\n",
"OpFlags(Disable 2GHz HT40)",
!!(pBase->opCapFlags & AR5416_OPFLAGS_N_2G_HT40));
printf("%-30s : %d\n",
"OpFlags(Disable 5Ghz HT20)",
!!(pBase->opCapFlags & AR5416_OPFLAGS_N_5G_HT20));
printf("%-30s : %d\n",
"OpFlags(Disable 5Ghz HT40)",
!!(pBase->opCapFlags & AR5416_OPFLAGS_N_5G_HT40));
printf("%-30s : %d\n",
"Big Endian",
!!(pBase->eepMisc & AR5416_EEPMISC_BIG_ENDIAN));
printf("%-30s : %d\n",
"Wake on Wireless",
!!(pBase->eepMisc & AR9287_EEPMISC_WOW));
printf("%-30s : %d\n",
"Cal Bin Major Ver",
(pBase->binBuildNumber >> 24) & 0xFF);
printf("%-30s : %d\n",
"Cal Bin Minor Ver",
(pBase->binBuildNumber >> 16) & 0xFF);
printf("%-30s : %d\n",
"Cal Bin Build",
(pBase->binBuildNumber >> 8) & 0xFF);
printf("%-30s : %d\n",
"OpenLoop PowerControl",
(pBase->openLoopPwrCntl & 0x1));
printf("%-30s : %d\n", "Power Table Offset, dBm",
pBase->pwrTableOffset);
if (eep_9287_get_rev(emp) >= AR5416_EEP_MINOR_VER_3) {
printf("%-30s : %s\n",
"Device Type",
sDeviceType[(pBase->deviceType & 0x7)]);
}
printf("\nCustomer Data in hex:\n");
hexdump_print(eep->custData, sizeof(eep->custData));
printf("\n");
}
static void eep_9287_dump_modal_header(struct atheepmgr *aem)
{
#define PR(_token, _p, _val_fmt, _val) \
do { \
printf("%-23s %-2s", (_token), ":"); \
printf("%s%"_val_fmt, _p, (_val)); \
printf("\n"); \
} while(0)
struct eep_9287_priv *emp = aem->eepmap_priv;
struct ar9287_eeprom *eep = &emp->eep;
struct ar9287_modal_eep_hdr *pModal = &eep->modalHeader;
EEP_PRINT_SECT_NAME("EEPROM Modal Header");
PR("Chain0 Ant. Control", "0x", "X", pModal->antCtrlChain[0]);
PR("Chain1 Ant. Control", "0x", "X", pModal->antCtrlChain[1]);
PR("Ant. Common Control", "0x", "X", pModal->antCtrlCommon);
PR("Chain0 Ant. Gain", "", "d", pModal->antennaGainCh[0]);
PR("Chain1 Ant. Gain", "", "d", pModal->antennaGainCh[1]);
PR("Switch Settle", "", "d", pModal->switchSettling);
PR("Chain0 TxRxAtten", "", "d", pModal->txRxAttenCh[0]);
PR("Chain1 TxRxAtten", "", "d", pModal->txRxAttenCh[1]);
PR("Chain0 RxTxMargin", "", "d", pModal->rxTxMarginCh[0]);
PR("Chain1 RxTxMargin", "", "d", pModal->rxTxMarginCh[1]);
PR("ADC Desired size", "", "d", pModal->adcDesiredSize);
PR("txEndToXpaOff", "", "d", pModal->txEndToXpaOff);
PR("txEndToRxOn", "", "d", pModal->txEndToRxOn);
PR("txFrameToXpaOn", "", "d", pModal->txFrameToXpaOn);
PR("CCA Threshold)", "", "d", pModal->thresh62);
PR("Chain0 NF Threshold", "", "d", pModal->noiseFloorThreshCh[0]);
PR("Chain1 NF Threshold", "", "d", pModal->noiseFloorThreshCh[1]);
PR("xpdGain", "0x", "x", pModal->xpdGain);
PR("External PD", "", "d", pModal->xpd);
PR("Chain0 I Coefficient", "", "d", pModal->iqCalICh[0]);
PR("Chain1 I Coefficient", "", "d", pModal->iqCalICh[1]);
PR("Chain0 Q Coefficient", "", "d", pModal->iqCalQCh[0]);
PR("Chain1 Q Coefficient", "", "d", pModal->iqCalQCh[1]);
PR("pdGainOverlap", "", "d", pModal->pdGainOverlap);
PR("xPA Bias Level", "", "d", pModal->xpaBiasLvl);
PR("txFrameToDataStart", "", "d", pModal->txFrameToDataStart);
PR("txFrameToPaOn", "", "d", pModal->txFrameToPaOn);
PR("HT40 Power Inc.", "", "d", pModal->ht40PowerIncForPdadc);
PR("Chain0 bswAtten", "", "d", pModal->bswAtten[0]);
PR("Chain1 bswAtten", "", "d", pModal->bswAtten[1]);
PR("Chain0 bswMargin", "", "d", pModal->bswMargin[0]);
PR("Chain1 bswMargin", "", "d", pModal->bswMargin[1]);
PR("HT40 Switch Settle", "", "d", pModal->swSettleHt40);
PR("AR92x7 Version", "", "d", pModal->version);
PR("DriverBias1", "", "d", pModal->db1);
PR("DriverBias2", "", "d", pModal->db1);
PR("CCK OutputBias", "", "d", pModal->ob_cck);
PR("PSK OutputBias", "", "d", pModal->ob_psk);
PR("QAM OutputBias", "", "d", pModal->ob_qam);
PR("PAL_OFF OutputBias", "", "d", pModal->ob_pal_off);
printf("\n");
}
static void
eep_9287_dump_pwrctl_openloop_item(const struct ar9287_cal_data_op_loop *data,
int gainmask)
{
const char * const gains[AR5416_NUM_PD_GAINS] = {"4", "2", "1", "0.5"};
int i, pos;
printf(" Field: pwrPdg vpdPdg pcdac empty\n");
printf(" ---------- ------ ------ ------ ------\n");
pos = -1;
for (i = 0; i < ARRAY_SIZE(gains); ++i) {
if (!(gainmask & (1 << i)))
continue;
pos++;
if (pos >= ARRAY_SIZE(data->pwrPdg)) {
printf(" Too many gains activated, no data available\n");
break;
}
printf(" Gain x%-3s:", gains[i]);
/**
* In all dumps what I saw, only the first elements of arrays
* are filled with meaningful data. Moreover driver uses only
* first elements too. So do not even try to output garbage
* from other elements.
*/
printf(" %5.2f", (double)data->pwrPdg[pos][0] / 4);
printf(" %5u", data->vpdPdg[pos][0]);
printf(" %5u", data->pcdac[pos][0]);
printf(" %5u", data->empty[pos][0]);
printf("\n");
}
}
static void
eep_9287_dump_pwrctl_openloop(const uint8_t *freqs, int chainmask, int gainmask,
const union ar9287_cal_data_per_freq_u *data,
int power_table_offset)
{
const union ar9287_cal_data_per_freq_u *item;
int chain, freq; /* Indexes */
for (chain = 0; chain < AR9287_MAX_CHAINS; ++chain) {
if (!(chainmask & (1 << chain)))
continue;
printf(" Chain %d:\n", chain);
printf("\n");
for (freq = 0; freq < AR9287_NUM_2G_CAL_PIERS; ++freq) {
if (freqs[freq] == AR5416_BCHAN_UNUSED)
break;
printf(" %4u MHz:\n", FBIN2FREQ(freqs[freq], 1));
item = data + (chain * AR9287_NUM_2G_CAL_PIERS + freq);
eep_9287_dump_pwrctl_openloop_item(&item->calDataOpen,
gainmask);
printf("\n");
}
}
}
static void eep_9287_dump_power_info(struct atheepmgr *aem)
{
#define PR_TARGET_POWER(__pref, __field, __rates) \
EEP_PRINT_SUBSECT_NAME(__pref " per-rate target power");\
ar5416_dump_target_power((void *)eep->__field, \
ARRAY_SIZE(eep->__field), \
__rates, ARRAY_SIZE(__rates), 1); \
printf("\n");
struct eep_9287_priv *emp = aem->eepmap_priv;
const struct ar9287_eeprom *eep = &emp->eep;
int maxradios = 0, i;
EEP_PRINT_SECT_NAME("EEPROM Power Info");
EEP_PRINT_SUBSECT_NAME("2 GHz per-freq PD cal. data");
if (eep->baseEepHeader.openLoopPwrCntl & 0x01) {
eep_9287_dump_pwrctl_openloop(eep->calFreqPier2G,
eep->baseEepHeader.txMask,
eep->modalHeader.xpdGain,
&eep->calPierData2G[0][0],
eep->baseEepHeader.pwrTableOffset);
} else {
ar5416_dump_pwrctl_closeloop(eep->calFreqPier2G,
ARRAY_SIZE(eep->calFreqPier2G), 1,
AR9287_MAX_CHAINS,
eep->baseEepHeader.txMask,
(uint8_t *)eep->calPierData2G,
AR9287_PD_GAIN_ICEPTS,
AR5416_NUM_PD_GAINS,
eep->modalHeader.xpdGain,
eep->baseEepHeader.pwrTableOffset);
}
printf("\n");
PR_TARGET_POWER("2 GHz CCK", calTargetPowerCck, eep_rates_cck);
PR_TARGET_POWER("2 GHz OFDM", calTargetPower2G, eep_rates_ofdm);
PR_TARGET_POWER("2 GHz HT20", calTargetPower2GHT20, eep_rates_ht);
PR_TARGET_POWER("2 GHz HT40", calTargetPower2GHT40, eep_rates_ht);
EEP_PRINT_SUBSECT_NAME("CTL data");
for (i = 0; i < AR9287_MAX_CHAINS; ++i) {
if (eep->baseEepHeader.txMask & (1 << i))
maxradios++;
}
ar5416_dump_ctl(eep->ctlIndex, &eep->ctlData[0].ctlEdges[0][0],
AR9287_NUM_CTLS, AR9287_MAX_CHAINS, maxradios,
AR9287_NUM_BAND_EDGES);
#undef PR_TARGET_POWER
}
static bool eep_9287_update_eeprom(struct atheepmgr *aem, int param,
const void *data)
{
struct eep_9287_priv *emp = aem->eepmap_priv;
struct ar9287_eeprom *eep = &emp->eep;
uint16_t *buf = aem->eep_buf;
int data_pos, data_len = 0, addr, el;
uint16_t sum;
switch (param) {
case EEP_UPDATE_MAC:
data_pos = AR9287_DATA_START_LOC +
EEP_FIELD_OFFSET(baseEepHeader.macAddr);
data_len = EEP_FIELD_SIZE(baseEepHeader.macAddr);
memcpy(&buf[data_pos], data, data_len * sizeof(uint16_t));
break;
#ifdef CONFIG_I_KNOW_WHAT_I_AM_DOING
case EEP_ERASE_CTL:
/* It is enough to erase the CTL index only */
data_pos = AR9287_DATA_START_LOC + EEP_FIELD_OFFSET(ctlIndex);
data_len = EEP_FIELD_SIZE(ctlIndex);
for (addr = data_pos; addr < (data_pos + data_len); ++addr)
buf[addr] = 0x0000;
break;
#endif
default:
fprintf(stderr, "Internal error: unknown parameter Id\n");
return false;
}
/* Store updated data */
for (addr = data_pos; addr < (data_pos + data_len); ++addr) {
if (!EEP_WRITE(addr, buf[addr])) {
fprintf(stderr, "Unable to write EEPROM data at 0x%04x\n",
addr);
return false;
}
}
/* Update checksum if need it */
if (data_pos > AR9287_DATA_START_LOC) {
el = eep->baseEepHeader.length / sizeof(uint16_t);
if (el > AR9287_DATA_SZ)
el = AR9287_DATA_SZ;
buf[AR9287_DATA_CSUM_LOC] = 0xffff;
sum = eep_calc_csum(&buf[AR9287_DATA_START_LOC], el);
buf[AR9287_DATA_CSUM_LOC] = sum;
if (!EEP_WRITE(AR9287_DATA_CSUM_LOC, sum)) {
fprintf(stderr, "Unable to update EEPROM checksum\n");
return false;
}
}
return true;
}
const struct eepmap eepmap_9287 = {
.name = "9287",
.desc = "AR9287 chip EEPROM map",
.features = EEPMAP_F_RAW_EEP,
.chip_regs = {
.srev = 0x4020,
},
.priv_data_sz = sizeof(struct eep_9287_priv),
.eep_buf_sz = AR9287_DATA_START_LOC + AR9287_DATA_SZ,
.load_eeprom = eep_9287_load_eeprom,
.check_eeprom = eep_9287_check_eeprom,
.dump = {
[EEP_SECT_INIT] = eep_9287_dump_init_data,
[EEP_SECT_BASE] = eep_9287_dump_base_header,
[EEP_SECT_MODAL] = eep_9287_dump_modal_header,
[EEP_SECT_POWER] = eep_9287_dump_power_info,
},
.update_eeprom = eep_9287_update_eeprom,
.params_mask = BIT(EEP_UPDATE_MAC)
#ifdef CONFIG_I_KNOW_WHAT_I_AM_DOING
| BIT(EEP_ERASE_CTL)
#endif
,
};