treewide: remove FSF address
[osmocom-bb.git] / src / target / firmware / board / common / readcal_tiffs.c
blob175f25a7cd9283c8af7abbc4006ca20c5f1d0407
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/vcxocal.h>
26 #include <rf/txcal.h>
27 #include <tiffs.h>
29 static int16_t afcdac_shifted;
31 static void afcdac_postproc(void)
33 afc_initial_dac_value = afcdac_shifted >> 3;
36 static const struct calmap {
37 char *pathname;
38 size_t record_len;
39 void *buffer;
40 void (*postproc)(void);
41 } rf_cal_list[] = {
42 { "/gsm/rf/afcdac", 2, &afcdac_shifted, afcdac_postproc },
43 { "/gsm/rf/tx/ramps.850", 512, rf_tx_ramps_850, NULL },
44 { "/gsm/rf/tx/levels.850", 128, rf_tx_levels_850, NULL },
45 { "/gsm/rf/tx/calchan.850", 128, rf_tx_chan_cal_850, NULL },
46 { "/gsm/rf/tx/ramps.900", 512, rf_tx_ramps_900, NULL },
47 { "/gsm/rf/tx/levels.900", 128, rf_tx_levels_900, NULL },
48 { "/gsm/rf/tx/calchan.900", 128, rf_tx_chan_cal_900, NULL },
49 { "/gsm/rf/tx/ramps.1800", 512, rf_tx_ramps_1800, NULL },
50 { "/gsm/rf/tx/levels.1800", 128, rf_tx_levels_1800, NULL },
51 { "/gsm/rf/tx/calchan.1800", 128, rf_tx_chan_cal_1800, NULL },
52 { "/gsm/rf/tx/ramps.1900", 512, rf_tx_ramps_1900, NULL },
53 { "/gsm/rf/tx/levels.1900", 128, rf_tx_levels_1900, NULL },
54 { "/gsm/rf/tx/calchan.1900", 128, rf_tx_chan_cal_1900, NULL },
55 { NULL, 0, NULL, NULL }
58 void read_factory_rf_calibration(void)
60 const struct calmap *tp;
61 uint8_t buf[512];
62 int rc;
64 puts("Checking TIFFS for the RF calibration records\n");
65 for (tp = rf_cal_list; tp->pathname; tp++) {
66 rc = tiffs_read_file_fixedlen(tp->pathname, buf,
67 tp->record_len);
68 if (rc <= 0)
69 continue;
70 printf("Found '%s', applying\n", tp->pathname);
71 memcpy(tp->buffer, buf, tp->record_len);
72 if (tp->postproc)
73 tp->postproc();