Skip to content

Commit dde8a89

Browse files
committed
eep5416: make PD calibration dumping common
The same format of closed loop power control calibration data is used for AR9285/AR9287/AR9827 EEPROM formats. So move Power Detector calibration dumping routine to common code to be able to reuse it for other EEPROM formats too. No functional changes, just a code relocation.
1 parent fb68e84 commit dde8a89

File tree

3 files changed

+163
-156
lines changed

3 files changed

+163
-156
lines changed

eep_5416.c

Lines changed: 5 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -435,157 +435,6 @@ static void eep_5416_dump_modal_header(struct atheepmgr *aem)
435435
#undef PR_LINE
436436
}
437437

438-
static void
439-
eep_5416_dump_closeloop_item(const uint8_t *pwr, const uint8_t *vpd,
440-
int maxicepts, int maxstoredgains, int gainmask,
441-
int power_table_offset)
442-
{
443-
const char * const gains[AR5416_NUM_PD_GAINS] = {"4", "2", "1", "0.5"};
444-
uint8_t mpwr[maxicepts * maxstoredgains];
445-
uint8_t mvpd[ARRAY_SIZE(mpwr) * maxstoredgains];
446-
/* Map of Mask Gain bit Index to Calibrated per-Gain icepts set Index */
447-
int mgi2cgi[ARRAY_SIZE(gains)];
448-
int cgii[maxstoredgains]; /* Array of indexes for merge */
449-
int gainidx, ngains, pwridx, npwr; /* Indexes and index limits */
450-
uint8_t pwrmin;
451-
452-
/**
453-
* Index of bits in the gains mask is not the same as gain index in the
454-
* calibration data. Calibration data are stored without gaps. And non
455-
* available per-gain sets are skipped if gain is not enabled via the
456-
* gains mask. E.g. if the gains mask have a value of 0x06 then you
457-
* should use sets #0 and #1 from the calibration data. Where set #0 is
458-
* corespond to gains mask bit #1 and set #1 coresponds to gains mask
459-
* bit #3.
460-
*
461-
* To simplify further code we build a map of gain indexes to
462-
* calibration data sets indexes using the gains mask. Also count a
463-
* number of gains mask bit that are set aka number of configured
464-
* gains.
465-
*/
466-
ngains = 0;
467-
for (gainidx = 0; gainidx < ARRAY_SIZE(gains); ++gainidx) {
468-
if (gainmask & (1 << gainidx)) {
469-
mgi2cgi[gainidx] = ngains;
470-
ngains++;
471-
} else {
472-
mgi2cgi[gainidx] = -1;
473-
}
474-
}
475-
if (ngains > maxstoredgains) {
476-
printf(" PD gain mask activates more gains then possible to store -- %d > %d\n",
477-
ngains, maxstoredgains);
478-
return;
479-
}
480-
481-
/* Merge calibration per-gain power lists to filter duplicates */
482-
memset(mpwr, 0xff, sizeof(mpwr));
483-
memset(mvpd, 0xff, sizeof(mvpd));
484-
memset(cgii, 0x00, sizeof(cgii));
485-
for (pwridx = 0; pwridx < ARRAY_SIZE(mpwr); ++pwridx) {
486-
pwrmin = 0xff;
487-
/* Looking for unmerged yet power value */
488-
for (gainidx = 0; gainidx < ngains; ++gainidx) {
489-
if (cgii[gainidx] >= maxicepts)
490-
continue;
491-
if (pwr[gainidx * maxicepts + cgii[gainidx]] < pwrmin)
492-
pwrmin = pwr[gainidx * maxicepts + cgii[gainidx]];
493-
}
494-
if (pwrmin == 0xff)
495-
break;
496-
mpwr[pwridx] = pwrmin;
497-
/* Copy Vpd of all gains for this power */
498-
for (gainidx = 0; gainidx < ngains; ++gainidx) {
499-
if (cgii[gainidx] >= AR5416_PD_GAIN_ICEPTS ||
500-
pwr[gainidx * maxicepts + cgii[gainidx]] != pwrmin)
501-
continue;
502-
mvpd[pwridx * maxstoredgains + gainidx] =
503-
vpd[gainidx * maxicepts + cgii[gainidx]];
504-
cgii[gainidx]++;
505-
}
506-
}
507-
npwr = pwridx;
508-
509-
/* Print merged data */
510-
printf(" Tx Power, dBm:");
511-
for (pwridx = 0; pwridx < npwr; ++pwridx)
512-
printf(" %5.2f", (double)mpwr[pwridx] / 4 +
513-
power_table_offset);
514-
printf("\n");
515-
printf(" --------------");
516-
for (pwridx = 0; pwridx < npwr; ++pwridx)
517-
printf(" -----");
518-
printf("\n");
519-
for (gainidx = 0; gainidx < ARRAY_SIZE(gains); ++gainidx) {
520-
if (!(gainmask & (1 << gainidx)))
521-
continue;
522-
printf(" Gain x%-3s VPD:", gains[gainidx]);
523-
for (pwridx = 0; pwridx < npwr; ++pwridx) {
524-
uint8_t vpd = mvpd[pwridx * maxstoredgains + mgi2cgi[gainidx]];
525-
526-
if (vpd == 0xff)
527-
printf(" ");
528-
else
529-
printf(" %3u", vpd);
530-
}
531-
printf("\n");
532-
}
533-
}
534-
535-
/**
536-
* Data is an array of per-chain & per-frequency sets of calibrations.
537-
* Each set calibrations consists of two parts: first part contains a set of
538-
* output power values, while the second part contains a corresponding power
539-
* detector values. Each part (power and detector) has a similar structure, it
540-
* is an array of per PD gain sets of measurements (icepts). Each type of
541-
* values (power and detector) has the similar size of one octet.
542-
*
543-
* So to calculate position of per-chain & per-frequency data we should know
544-
* size of this data. Such data block size is a sum of its parts, i.e. sum of
545-
* output power data size and power detector data size. The size of each part
546-
* is a multiplication of a number of PD gains (maxstoredgains) and of a number
547-
* of calibration points (maxicepts).
548-
*
549-
* So having all this numbers we are able to easly calculate size of various
550-
* elements and their positions.
551-
*/
552-
static void eep_5416_dump_closeloop(const uint8_t *freqs, int maxfreq,
553-
int is_2g, int maxchains, int chainmask,
554-
const void *data, int maxicepts,
555-
int maxstoredgains, int gainmask,
556-
int power_table_offset)
557-
{
558-
/* Sizes of TxPower and Detector sets of data */
559-
const int fpwrdatasz = maxicepts * maxstoredgains * sizeof(uint8_t);
560-
const int fvpddatasz = maxicepts * maxstoredgains * sizeof(uint8_t);
561-
const int fdatasz = fpwrdatasz + fvpddatasz; /* Per-chain & per-freq data sz */
562-
const uint8_t *fdata, *fpwrdata, *fvpddata;
563-
int chain, freq; /* Indexes */
564-
565-
for (chain = 0; chain < maxchains; ++chain) {
566-
if (!(chainmask & (1 << chain)))
567-
continue;
568-
printf(" Chain %d:\n", chain);
569-
printf("\n");
570-
for (freq = 0; freq < maxfreq; ++freq) {
571-
if (freqs[freq] == AR5416_BCHAN_UNUSED)
572-
break;
573-
574-
printf(" %4u MHz:\n", FBIN2FREQ(freqs[freq], is_2g));
575-
576-
fdata = data + fdatasz * (chain * maxfreq + freq);
577-
fpwrdata = fdata + 0;/* Power data begins immediatly */
578-
fvpddata = fdata + fpwrdatasz; /* Skip power data */
579-
580-
eep_5416_dump_closeloop_item(fpwrdata, fvpddata,
581-
maxicepts, maxstoredgains,
582-
gainmask, power_table_offset);
583-
584-
printf("\n");
585-
}
586-
}
587-
}
588-
589438
static void eep_5416_dump_pd_cal(const uint8_t *freq, int maxfreq,
590439
const void *caldata, int is_openloop,
591440
int is_2g, int chainmask, int gainmask,
@@ -594,11 +443,11 @@ static void eep_5416_dump_pd_cal(const uint8_t *freq, int maxfreq,
594443
if (is_openloop) {
595444
printf(" Open-loop PD calibration dumping is not supported\n");
596445
} else {
597-
eep_5416_dump_closeloop(freq, maxfreq, is_2g, AR5416_MAX_CHAINS,
598-
chainmask, caldata,
599-
AR5416_PD_GAIN_ICEPTS,
600-
AR5416_NUM_PD_GAINS,
601-
gainmask, power_table_offset);
446+
ar5416_dump_pwrctl_closeloop(freq, maxfreq, is_2g,
447+
AR5416_MAX_CHAINS, chainmask,
448+
caldata, AR5416_PD_GAIN_ICEPTS,
449+
AR5416_NUM_PD_GAINS, gainmask,
450+
power_table_offset);
602451
}
603452
}
604453

eep_common.c

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,159 @@ void ar5416_dump_eep_init(const struct ar5416_eep_init *ini, size_t size)
219219
printf("\n");
220220
}
221221

222+
static void
223+
ar5416_dump_pwrctl_closeloop_item(const uint8_t *pwr, const uint8_t *vpd,
224+
int maxicepts, int maxstoredgains,
225+
int gainmask, int power_table_offset)
226+
{
227+
const char * const gains[AR5416_NUM_PD_GAINS] = {"4", "2", "1", "0.5"};
228+
uint8_t mpwr[maxicepts * maxstoredgains];
229+
uint8_t mvpd[ARRAY_SIZE(mpwr) * maxstoredgains];
230+
/* Map of Mask Gain bit Index to Calibrated per-Gain icepts set Index */
231+
int mgi2cgi[ARRAY_SIZE(gains)];
232+
int cgii[maxstoredgains]; /* Array of indexes for merge */
233+
int gainidx, ngains, pwridx, npwr; /* Indexes and index limits */
234+
uint8_t pwrmin;
235+
236+
/**
237+
* Index of bits in the gains mask is not the same as gain index in the
238+
* calibration data. Calibration data are stored without gaps. And non
239+
* available per-gain sets are skipped if gain is not enabled via the
240+
* gains mask. E.g. if the gains mask have a value of 0x06 then you
241+
* should use sets #0 and #1 from the calibration data. Where set #0 is
242+
* corespond to gains mask bit #1 and set #1 coresponds to gains mask
243+
* bit #3.
244+
*
245+
* To simplify further code we build a map of gain indexes to
246+
* calibration data sets indexes using the gains mask. Also count a
247+
* number of gains mask bit that are set aka number of configured
248+
* gains.
249+
*/
250+
ngains = 0;
251+
for (gainidx = 0; gainidx < ARRAY_SIZE(gains); ++gainidx) {
252+
if (gainmask & (1 << gainidx)) {
253+
mgi2cgi[gainidx] = ngains;
254+
ngains++;
255+
} else {
256+
mgi2cgi[gainidx] = -1;
257+
}
258+
}
259+
if (ngains > maxstoredgains) {
260+
printf(" PD gain mask activates more gains then possible to store -- %d > %d\n",
261+
ngains, maxstoredgains);
262+
return;
263+
}
264+
265+
/* Merge calibration per-gain power lists to filter duplicates */
266+
memset(mpwr, 0xff, sizeof(mpwr));
267+
memset(mvpd, 0xff, sizeof(mvpd));
268+
memset(cgii, 0x00, sizeof(cgii));
269+
for (pwridx = 0; pwridx < ARRAY_SIZE(mpwr); ++pwridx) {
270+
pwrmin = 0xff;
271+
/* Looking for unmerged yet power value */
272+
for (gainidx = 0; gainidx < ngains; ++gainidx) {
273+
if (cgii[gainidx] >= maxicepts)
274+
continue;
275+
if (pwr[gainidx * maxicepts + cgii[gainidx]] < pwrmin)
276+
pwrmin = pwr[gainidx * maxicepts + cgii[gainidx]];
277+
}
278+
if (pwrmin == 0xff)
279+
break;
280+
mpwr[pwridx] = pwrmin;
281+
/* Copy Vpd of all gains for this power */
282+
for (gainidx = 0; gainidx < ngains; ++gainidx) {
283+
if (cgii[gainidx] >= AR5416_PD_GAIN_ICEPTS ||
284+
pwr[gainidx * maxicepts + cgii[gainidx]] != pwrmin)
285+
continue;
286+
mvpd[pwridx * maxstoredgains + gainidx] =
287+
vpd[gainidx * maxicepts + cgii[gainidx]];
288+
cgii[gainidx]++;
289+
}
290+
}
291+
npwr = pwridx;
292+
293+
/* Print merged data */
294+
printf(" Tx Power, dBm:");
295+
for (pwridx = 0; pwridx < npwr; ++pwridx)
296+
printf(" %5.2f", (double)mpwr[pwridx] / 4 +
297+
power_table_offset);
298+
printf("\n");
299+
printf(" --------------");
300+
for (pwridx = 0; pwridx < npwr; ++pwridx)
301+
printf(" -----");
302+
printf("\n");
303+
for (gainidx = 0; gainidx < ARRAY_SIZE(gains); ++gainidx) {
304+
if (!(gainmask & (1 << gainidx)))
305+
continue;
306+
printf(" Gain x%-3s VPD:", gains[gainidx]);
307+
for (pwridx = 0; pwridx < npwr; ++pwridx) {
308+
uint8_t vpd = mvpd[pwridx * maxstoredgains + mgi2cgi[gainidx]];
309+
310+
if (vpd == 0xff)
311+
printf(" ");
312+
else
313+
printf(" %3u", vpd);
314+
}
315+
printf("\n");
316+
}
317+
}
318+
319+
/**
320+
* Data is an array of per-chain & per-frequency sets of calibrations.
321+
* Each set calibrations consists of two parts: first part contains a set of
322+
* output power values, while the second part contains a corresponding power
323+
* detector values. Each part (power and detector) has a similar structure, it
324+
* is an array of per PD gain sets of measurements (icepts). Each type of
325+
* values (power and detector) has the similar size of one octet.
326+
*
327+
* So to calculate position of per-chain & per-frequency data we should know
328+
* size of this data. Such data block size is a sum of its parts, i.e. sum of
329+
* output power data size and power detector data size. The size of each part
330+
* is a multiplication of a number of PD gains (maxstoredgains) and of a number
331+
* of calibration points (maxicepts).
332+
*
333+
* So having all this numbers we are able to easly calculate size of various
334+
* elements and their positions.
335+
*/
336+
void ar5416_dump_pwrctl_closeloop(const uint8_t *freqs, int maxfreqs, int is_2g,
337+
int maxchains, int chainmask,
338+
const void *data, int maxicepts,
339+
int maxstoredgains, int gainmask,
340+
int power_table_offset)
341+
{
342+
/* Sizes of TxPower and Detector sets of data */
343+
const int fpwrdatasz = maxicepts * maxstoredgains * sizeof(uint8_t);
344+
const int fvpddatasz = maxicepts * maxstoredgains * sizeof(uint8_t);
345+
const int fdatasz = fpwrdatasz + fvpddatasz; /* Per-chain & per-freq data sz */
346+
const uint8_t *fdata, *fpwrdata, *fvpddata;
347+
int chain, freq; /* Indexes */
348+
349+
for (chain = 0; chain < maxchains; ++chain) {
350+
if (!(chainmask & (1 << chain)))
351+
continue;
352+
printf(" Chain %d:\n", chain);
353+
printf("\n");
354+
for (freq = 0; freq < maxfreqs; ++freq) {
355+
if (freqs[freq] == AR5416_BCHAN_UNUSED)
356+
break;
357+
358+
printf(" %4u MHz:\n", FBIN2FREQ(freqs[freq], is_2g));
359+
360+
fdata = data + fdatasz * (chain * maxfreqs + freq);
361+
fpwrdata = fdata + 0;/* Power data begins immediatly */
362+
fvpddata = fdata + fpwrdatasz; /* Skip power data */
363+
364+
ar5416_dump_pwrctl_closeloop_item(fpwrdata, fvpddata,
365+
maxicepts,
366+
maxstoredgains,
367+
gainmask,
368+
power_table_offset);
369+
370+
printf("\n");
371+
}
372+
}
373+
}
374+
222375
void ar5416_dump_target_power(const struct ar5416_cal_target_power *caldata,
223376
int maxchans, const char * const rates[],
224377
int nrates, int is_2g)

eep_common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ bool __ar5416_toggle_byteswap(struct atheepmgr *aem, uint32_t eepmisc_off,
197197

198198
void ar5416_dump_eep_init(const struct ar5416_eep_init *ini, size_t size);
199199

200+
void ar5416_dump_pwrctl_closeloop(const uint8_t *freqs, int maxfreqs, int is_2g,
201+
int maxchains, int chainmask,
202+
const void *data, int maxicepts,
203+
int maxstoredgains, int gainmask,
204+
int power_table_offset);
200205
void ar5416_dump_target_power(const struct ar5416_cal_target_power *pow,
201206
int maxchans, const char * const rates[],
202207
int nrates, int is_2g);

0 commit comments

Comments
 (0)