Hello CK HU,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/coreboot/+/46391
to review the following change.
Change subject: mb/google/asurada: Get ram id from AUX_IN3 ......................................................................
mb/google/asurada: Get ram id from AUX_IN3
Mapping the voltage of AUX_IN3 to ram id.
Signed-off-by: CK Hu ck.hu@mediatek.com Change-Id: Iaadabea1b6aa91c48b137f7c6784ab7ee0adc473 --- M src/mainboard/google/asurada/boardid.c 1 file changed, 55 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/91/46391/1
diff --git a/src/mainboard/google/asurada/boardid.c b/src/mainboard/google/asurada/boardid.c index 2c8efcd..6dc1f7a 100644 --- a/src/mainboard/google/asurada/boardid.c +++ b/src/mainboard/google/asurada/boardid.c @@ -1,9 +1,58 @@ /* SPDX-License-Identifier: GPL-2.0-only */
+#include <assert.h> #include <boardid.h> +#include <console/console.h> +#include <soc/auxadc.h>
/* board_id is provided by ec/google/chromeec/ec_boardid.c */
+#define ADC_LEVELS 15 + +enum { + RAM_ID_CHANNEL = 3, +}; + +static const int ram_voltages[ADC_LEVELS] = { + /* ID : Voltage (unit: uV) */ + /* 0 : */ 74300, + /* 1 : */ 211700, + /* 2 : */ 318800, + /* 3 : */ 428600, + /* 4 : */ 541700, + /* 5 : */ 665800, + /* 6 : */ 781400, + /* 7 : */ 900000, + /* 8 : */ 1023100, + /* 9 : */ 1137000, + /* 10 : */ 1240000, + /* 11 : */ 1342600, + /* 12 : */ 1457500, + /* 13 : */ 1575600, + /* 14 : */ 1683600, +}; + +static const int *adc_voltages[] = { + [RAM_ID_CHANNEL] = ram_voltages, +}; + +static uint32_t get_adc_index(unsigned int channel) +{ + int value = auxadc_get_voltage(channel); + + assert(channel < ARRAY_SIZE(adc_voltages)); + const int *voltages = adc_voltages[channel]; + assert(voltages); + + /* Find the closest voltage */ + uint32_t id; + for (id = 0; id < ADC_LEVELS - 1; id++) + if (value < (voltages[id] + voltages[id + 1]) / 2) + break; + printk(BIOS_DEBUG, "ADC[%d]: Raw value=%d ID=%d\n", channel, value, id); + return id; +} + uint32_t sku_id(void) { return 0; @@ -11,5 +60,10 @@
uint32_t ram_code(void) { - return 0; + static uint32_t cached_ram_code = BOARD_ID_INIT; + + if (cached_ram_code == BOARD_ID_INIT) + cached_ram_code = get_adc_index(RAM_ID_CHANNEL); + + return cached_ram_code; }