treewide: remove FSF address
[osmocom-bb.git] / src / target / firmware / board / pirelli_dpl10 / readcal.c
blob40f608f8590f929c938f1e24db93ad27dee75ca3
1 /*
2 * This code was written by Mychaela Falconia <falcon@freecalypso.org>
3 * who refuses to claim copyright on it and has released it as public domain
4 * instead. NO rights reserved, all rights relinquished.
6 * Tweaked (coding style changes) by Vadim Yanitskiy <axilirator@gmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
20 #include <stdio.h>
21 #include <stdint.h>
22 #include <string.h>
24 #include <rf/readcal.h>
25 #include <rf/txcal.h>
26 #include <rf/vcxocal.h>
28 static int16_t afcdac_shifted;
30 static void afcdac_postproc(void)
32 afc_initial_dac_value = afcdac_shifted >> 3;
35 static int verify_checksum(const uint8_t *start, size_t len)
37 const uint8_t *p, *endp;
38 uint8_t accum;
40 p = start;
41 endp = start + len;
42 accum = 0;
43 while (p < endp)
44 accum += *p++;
46 if (accum == *p)
47 return 0; /* good */
48 else
49 return -1; /* bad */
52 static const struct calmap {
53 char *desc;
54 unsigned offset;
55 size_t record_len;
56 void *buffer;
57 void (*postproc)(void);
58 } rf_cal_list[] = {
59 { "afcdac", 0x528, 2, &afcdac_shifted, afcdac_postproc },
60 { "Tx ramps 900", 0x72B, 512, rf_tx_ramps_900, NULL },
61 { "Tx levels 900", 0x92C, 128, rf_tx_levels_900, NULL },
62 { "Tx calchan 900", 0x9AD, 128, rf_tx_chan_cal_900, NULL },
63 { "Tx ramps 1800", 0xA2E, 512, rf_tx_ramps_1800, NULL },
64 { "Tx levels 1800", 0xC2F, 128, rf_tx_levels_1800, NULL },
65 { "Tx calchan 1800", 0xCB0, 128, rf_tx_chan_cal_1800, NULL },
66 { "Tx ramps 1900", 0xD31, 512, rf_tx_ramps_1900, NULL },
67 { "Tx levels 1900", 0xF32, 128, rf_tx_levels_1900, NULL },
68 { "Tx calchan 1900", 0xFB3, 128, rf_tx_chan_cal_1900, NULL },
69 { NULL, 0, 0, NULL, NULL }
72 void read_factory_rf_calibration(void)
74 const struct calmap *tp;
75 const uint8_t *record;
77 puts("Checking factory data block for the RF calibration records\n");
78 for (tp = rf_cal_list; tp->desc; tp++) {
79 record = (const uint8_t *)0x027F0000 + tp->offset;
80 if (verify_checksum(record, tp->record_len) < 0)
81 continue;
82 printf("Found '%s' record, applying\n", tp->desc);
83 memcpy(tp->buffer, record, tp->record_len);
84 if (tp->postproc)
85 tp->postproc();