summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTristan Shieh <tristan.shieh@mediatek.com>2018-10-12 13:27:15 +0800
committerJulius Werner <jwerner@chromium.org>2018-11-02 19:57:55 +0000
commit42adb29853215576a5b331b2126d867f3d56bf9f (patch)
tree71a7d5de2009d02daefe7e91f02751b6c46bb2cb /src
parent96631f941dc3e958585cc4798d3c7c74c032c7bd (diff)
google/kukui: Add board id support
Get board id from AUXIN4 and RAM code from AUXIN3. BUG=b:80501386 BRANCH=none TEST=AUXIN4 is 0.074v and AUXIN3 is 0.212v on P0. AUXIN4 is 0.212v and AUXIN3 is 0.212v on P1. Change-Id: I50533e851d2fae66ae8c5e4e1aa36708d9058e94 Signed-off-by: Tristan Shieh <tristan.shieh@mediatek.com> Reviewed-on: https://review.coreboot.org/29062 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'src')
-rw-r--r--src/mainboard/google/kukui/Makefile.inc3
-rw-r--r--src/mainboard/google/kukui/boardid.c68
2 files changed, 71 insertions, 0 deletions
diff --git a/src/mainboard/google/kukui/Makefile.inc b/src/mainboard/google/kukui/Makefile.inc
index aa6bf11812..a98541a35c 100644
--- a/src/mainboard/google/kukui/Makefile.inc
+++ b/src/mainboard/google/kukui/Makefile.inc
@@ -1,3 +1,4 @@
+bootblock-y += boardid.c
bootblock-y += bootblock.c
bootblock-y += chromeos.c
bootblock-y += memlayout.ld
@@ -6,10 +7,12 @@ decompressor-y += memlayout.ld
verstage-y += chromeos.c
verstage-y += memlayout.ld
+romstage-y += boardid.c
romstage-y += chromeos.c
romstage-y += memlayout.ld
romstage-y += romstage.c
+ramstage-y += boardid.c
ramstage-y += chromeos.c
ramstage-y += mainboard.c
ramstage-y += memlayout.ld
diff --git a/src/mainboard/google/kukui/boardid.c b/src/mainboard/google/kukui/boardid.c
new file mode 100644
index 0000000000..26ae82f3a6
--- /dev/null
+++ b/src/mainboard/google/kukui/boardid.c
@@ -0,0 +1,68 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2018 MediaTek Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <assert.h>
+#include <boardid.h>
+#include <soc/auxadc.h>
+#include <stddef.h>
+
+static uint32_t get_index(unsigned int channel, uint32_t *cached_id)
+{
+ static const int voltages[] = {
+ /* ID : Voltage (unit: uV) */
+ /* 0 : */ 74000,
+ /* 1 : */ 212000,
+ /* 2 : */ 319000,
+ /* 3 : */ 429000,
+ /* 4 : */ 542000,
+ /* 5 : */ 666000,
+ /* 6 : */ 781000,
+ /* 7 : */ 900000,
+ /* 8 : */ 1023000,
+ /* 9 : */ 1137000,
+ /* 10 : */ 1240000,
+ /* 11 : */ 1343000,
+ /* 12 : */ 1457000
+ };
+
+ uint32_t id;
+
+ if (*cached_id != BOARD_ID_UNKNOWN)
+ return *cached_id;
+
+ int value = auxadc_get_voltage(channel);
+ /* Find the closest voltage */
+ for (id = 0; id < ARRAY_SIZE(voltages) - 1; id++)
+ if (value < (voltages[id] + voltages[id + 1]) / 2)
+ break;
+
+ const int tolerance = 10000; /* 10,000 uV */
+ assert(ABS(value - voltages[id]) < tolerance);
+
+ *cached_id = id;
+ return id;
+}
+
+uint32_t board_id(void)
+{
+ static uint32_t cached_board_id = BOARD_ID_UNKNOWN;
+ return get_index(4, &cached_board_id);
+}
+
+uint32_t ram_code(void)
+{
+ static uint32_t cached_ram_code = BOARD_ID_UNKNOWN;
+ return get_index(3, &cached_ram_code);
+}