| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include <stdio.h> |
| 21 |
#include <stdint.h> |
| 22 |
#include <unistd.h> |
| 23 |
#include <stdlib.h> |
| 24 |
#include <string.h> |
| 25 |
#include <errno.h> |
| 26 |
#include <fcntl.h> |
| 27 |
#include <stdbool.h> |
| 28 |
|
| 29 |
#include "lc15bts_bid.h" |
| 30 |
|
| 31 |
#define BOARD_REV_SYSFS "/var/lc15/platform/revision" |
| 32 |
#define BOARD_OPT_SYSFS "/var/lc15/platform/option" |
| 33 |
|
| 34 |
static const int option_type_mask[_NUM_OPTION_TYPES] = { |
| 35 |
[LC15BTS_OPTION_OCXO] = 0x07, |
| 36 |
[LC15BTS_OPTION_FPGA] = 0x03, |
| 37 |
[LC15BTS_OPTION_PA] = 0x01, |
| 38 |
[LC15BTS_OPTION_BAND] = 0x03, |
| 39 |
[LC15BTS_OPTION_TX_ISO_BYP] = 0x01, |
| 40 |
[LC15BTS_OPTION_RX_DUP_BYP] = 0x01, |
| 41 |
[LC15BTS_OPTION_RX_PB_BYP] = 0x01, |
| 42 |
[LC15BTS_OPTION_RX_DIV] = 0x01, |
| 43 |
[LC15BTS_OPTION_RX1A] = 0x01, |
| 44 |
[LC15BTS_OPTION_RX1B] = 0x01, |
| 45 |
[LC15BTS_OPTION_RX2A] = 0x01, |
| 46 |
[LC15BTS_OPTION_RX2B] = 0x01, |
| 47 |
[LC15BTS_OPTION_DDR_32B] = 0x01, |
| 48 |
[LC15BTS_OPTION_DDR_ECC] = 0x01, |
| 49 |
[LC15BTS_OPTION_LOG_DET] = 0x01, |
| 50 |
[LC15BTS_OPTION_DUAL_LOG_DET] = 0x01, |
| 51 |
}; |
| 52 |
|
| 53 |
static const int option_type_shift[_NUM_OPTION_TYPES] = { |
| 54 |
[LC15BTS_OPTION_OCXO] = 0, |
| 55 |
[LC15BTS_OPTION_FPGA] = 3, |
| 56 |
[LC15BTS_OPTION_PA] = 5, |
| 57 |
[LC15BTS_OPTION_BAND] = 6, |
| 58 |
[LC15BTS_OPTION_TX_ISO_BYP] = 8, |
| 59 |
[LC15BTS_OPTION_RX_DUP_BYP] = 9, |
| 60 |
[LC15BTS_OPTION_RX_PB_BYP] = 10, |
| 61 |
[LC15BTS_OPTION_RX_DIV] = 11, |
| 62 |
[LC15BTS_OPTION_RX1A] = 12, |
| 63 |
[LC15BTS_OPTION_RX1B] = 13, |
| 64 |
[LC15BTS_OPTION_RX2A] = 14, |
| 65 |
[LC15BTS_OPTION_RX2B] = 15, |
| 66 |
[LC15BTS_OPTION_DDR_32B] = 16, |
| 67 |
[LC15BTS_OPTION_DDR_ECC] = 17, |
| 68 |
[LC15BTS_OPTION_LOG_DET] = 18, |
| 69 |
[LC15BTS_OPTION_DUAL_LOG_DET] = 19, |
| 70 |
}; |
| 71 |
|
| 72 |
|
| 73 |
static int board_rev = -1; |
| 74 |
static int board_option = -1; |
| 75 |
|
| 76 |
static inline bool read_board(const char *src, const char *spec, void *dst) |
| 77 |
{ |
| 78 |
FILE *fp = fopen(src, "r"); |
| 79 |
if (!fp) { |
| 80 |
fprintf(stderr, "Failed to open %s due to '%s' error\n", src, strerror(errno)); |
| 81 |
return false; |
| 82 |
} |
| 83 |
|
| 84 |
if (fscanf(fp, spec, dst) != 1) { |
| 85 |
fclose(fp); |
| 86 |
fprintf(stderr, "Failed to read %s due to '%s' error\n", src, strerror(errno)); |
| 87 |
return false; |
| 88 |
} |
| 89 |
fclose(fp); |
| 90 |
return true; |
| 91 |
} |
| 92 |
|
| 93 |
int lc15bts_rev_get(void) |
| 94 |
{ |
| 95 |
char rev; |
| 96 |
|
| 97 |
if (board_rev != -1) { |
| 98 |
return board_rev; |
| 99 |
} |
| 100 |
|
| 101 |
if (!read_board(BOARD_REV_SYSFS, "%c", &rev)) |
| 102 |
return -1; |
| 103 |
|
| 104 |
board_rev = rev; |
| 105 |
return board_rev; |
| 106 |
} |
| 107 |
|
| 108 |
int lc15bts_model_get(void) |
| 109 |
{ |
| 110 |
int opt; |
| 111 |
|
| 112 |
if (board_option != -1) |
| 113 |
return board_option; |
| 114 |
|
| 115 |
if (!read_board(BOARD_OPT_SYSFS, "%X", &opt)) |
| 116 |
return -1; |
| 117 |
|
| 118 |
board_option = opt; |
| 119 |
return board_option; |
| 120 |
} |
| 121 |
|
| 122 |
int lc15bts_option_get(enum lc15bts_option_type type) |
| 123 |
{ |
| 124 |
int rc; |
| 125 |
int option; |
| 126 |
|
| 127 |
if (type >= _NUM_OPTION_TYPES) { |
| 128 |
return -EINVAL; |
| 129 |
} |
| 130 |
|
| 131 |
if (board_option == -1) { |
| 132 |
rc = lc15bts_model_get(); |
| 133 |
if (rc < 0) return rc; |
| 134 |
} |
| 135 |
|
| 136 |
option = (board_option >> option_type_shift[type]) |
| 137 |
& option_type_mask[type]; |
| 138 |
|
| 139 |
return option; |
| 140 |
} |
| 141 |
|
| 142 |
const char* get_hwversion_desc() |
| 143 |
{ |
| 144 |
int rev; |
| 145 |
int model; |
| 146 |
size_t len; |
| 147 |
static char model_name[64] = {0, }; |
| 148 |
len = snprintf(model_name, sizeof(model_name), "NuRAN Litecell 1.5 BTS"); |
| 149 |
|
| 150 |
rev = lc15bts_rev_get(); |
| 151 |
if (rev >= 0) { |
| 152 |
len += snprintf(model_name + len, sizeof(model_name) - len, |
| 153 |
" Rev %c", (char)rev); |
| 154 |
} |
| 155 |
|
| 156 |
model = lc15bts_model_get(); |
| 157 |
if (model >= 0) { |
| 158 |
snprintf(model_name + len, sizeof(model_name) - len, |
| 159 |
"%s (%05X)", model_name, model); |
| 160 |
} |
| 161 |
return model_name; |
| 162 |
} |