| 1 |
|
| 2 |
|
| 3 |
#include <boardid.h> |
| 4 |
#include <console/console.h> |
| 5 |
#include <gpio.h> |
| 6 |
#include <soc/saradc.h> |
| 7 |
|
| 8 |
static const int id_readings[] = { |
| 9 |
|
| 10 |
|
| 11 |
#if CONFIG(BOARD_GOOGLE_KEVIN) |
| 12 |
91, |
| 13 |
#else |
| 14 |
81, |
| 15 |
#endif |
| 16 |
150, |
| 17 |
211, |
| 18 |
274, |
| 19 |
342, |
| 20 |
411, |
| 21 |
477, |
| 22 |
545, |
| 23 |
613, |
| 24 |
675, |
| 25 |
733, |
| 26 |
795, |
| 27 |
861, |
| 28 |
925, |
| 29 |
989, |
| 30 |
1023 |
| 31 |
}; |
| 32 |
_Static_assert(ARRAY_SIZE(id_readings) == 16, "Yo' messed up da table, bruh!"); |
| 33 |
static int cached_board_id = -1; |
| 34 |
static int cached_ram_id = -1; |
| 35 |
|
| 36 |
static uint32_t get_index(uint32_t channel, int *cached_id) |
| 37 |
{ |
| 38 |
int i; |
| 39 |
int adc_reading; |
| 40 |
|
| 41 |
if (*cached_id != -1) |
| 42 |
return *cached_id; |
| 43 |
|
| 44 |
adc_reading = get_saradc_value(channel); |
| 45 |
for (i = 0; i < ARRAY_SIZE(id_readings); i++) { |
| 46 |
if (adc_reading <= id_readings[i]) { |
| 47 |
printk(BIOS_DEBUG, "ADC reading %d, ID %d\n", |
| 48 |
adc_reading, i); |
| 49 |
*cached_id = i; |
| 50 |
return i; |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
die("Read impossible value (> 1023) from 10-bit ADC!"); |
| 55 |
} |
| 56 |
|
| 57 |
uint32_t board_id(void) |
| 58 |
{ |
| 59 |
return get_index(1, &cached_board_id); |
| 60 |
} |
| 61 |
|
| 62 |
uint32_t ram_code(void) |
| 63 |
{ |
| 64 |
return get_index(0, &cached_ram_id); |
| 65 |
} |
| 66 |
|
| 67 |
uint32_t sku_id(void) |
| 68 |
{ |
| 69 |
if (!CONFIG(GRU_BASEBOARD_SCARLET)) |
| 70 |
return UNDEFINED_STRAPPING_ID; |
| 71 |
|
| 72 |
static uint32_t sku_id = UNDEFINED_STRAPPING_ID; |
| 73 |
if (sku_id != UNDEFINED_STRAPPING_ID) |
| 74 |
return sku_id; |
| 75 |
|
| 76 |
gpio_t pins[3] = {[2] = GPIO(3, D, 6), [1] = GPIO(3, D, 5), |
| 77 |
[0] = GPIO(3, D, 4)}; |
| 78 |
|
| 79 |
sku_id = gpio_pullup_base2_value(pins, ARRAY_SIZE(pins)); |
| 80 |
return sku_id; |
| 81 |
} |