[coreboot-gerrit] New patch to review for coreboot: google/gru: Determine Board ID based on the input voltage of ADC1

Patrick Georgi (pgeorgi@google.com) gerrit at coreboot.org
Sat May 7 08:30:41 CEST 2016


Patrick Georgi (pgeorgi at google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/14722

-gerrit

commit 410a40c1aca39d9ea32d8c3d7ffeead22807a9de
Author: Vadim Bendebury <vbendeb at chromium.org>
Date:   Fri Apr 22 07:03:43 2016 -0700

    google/gru: Determine Board ID based on the input voltage of ADC1
    
    The Board ID on the Gru family of boards is determined by reading the
    voltage from a resistor divider, each hardware revision is supposed to
    have a unique resistor ratio, which allows to distinctly tell between
    different Board ID.
    
    While the long time approach to mapping resistor ratios (and voltages)
    into Board ID remains under discussion, we know for sure the values
    for Proto 1 and Proto 2. Let's just use them for now.
    
    Since Board ID can be queried multiple times during boot, ideally it
    should be read once and placed in the coreboot table to be available
    to all coreboot stages. For now we just cache it so that at least
    during the same stage the ADC has to run only once.
    
    BRANCH=None
    BUG=chrome-os-partner:51537
    TEST=verified that the voltage reading on Proto 1 is as expected, and
         Board ID 0 is reported.
    
    Change-Id: I94bc7fc235dae4155feb6ca35b5ef0ab20c3ec9c
    Signed-off-by: Patrick Georgi <pgeorgi at chromium.org>
    Original-Commit-Id: bb4064d0af8174b6ae247cdad9378b7f4e5f22ba
    Original-Change-Id: I105ea97f8862b5707b582904c6f2e3e9406a0f07
    Original-Signed-off-by: Vadim Bendebury <vbendeb at chromium.org>
    Original-Reviewed-on: https://chromium-review.googlesource.com/340428
    Original-Reviewed-by: Patrick Georgi <patrick at georgi-clan.de>
---
 src/mainboard/google/gru/Makefile.inc |  3 ---
 src/mainboard/google/gru/boardid.c    | 37 +++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/src/mainboard/google/gru/Makefile.inc b/src/mainboard/google/gru/Makefile.inc
index da61513..a209d1b 100644
--- a/src/mainboard/google/gru/Makefile.inc
+++ b/src/mainboard/google/gru/Makefile.inc
@@ -13,16 +13,13 @@
 ## GNU General Public License for more details.
 ##
 
-bootblock-y += boardid.c
 bootblock-y += bootblock.c
 bootblock-y += chromeos.c
 bootblock-y += memlayout.ld
 bootblock-y += reset.c
 
-verstage-y += boardid.c
 verstage-y += chromeos.c
 verstage-y += memlayout.ld
-verstage-y += memlayout.ld
 verstage-y += reset.c
 
 romstage-y += boardid.c
diff --git a/src/mainboard/google/gru/boardid.c b/src/mainboard/google/gru/boardid.c
index f62fe97..5f030ad 100644
--- a/src/mainboard/google/gru/boardid.c
+++ b/src/mainboard/google/gru/boardid.c
@@ -16,9 +16,46 @@
 #include <boardid.h>
 #include <console/console.h>
 #include <stdlib.h>
+#include <soc/saradc.h>
+
+/*
+ * This matches two Kevin prototypes, needs to be sorted out with HW engs to
+ * have more regular mapping between the voltage and board ID.
+ */
+static const int board_id_readings[] = { 42, 120 };
+
+/*
+ * The ADC produces a 10 bit value, the resistor accuracy is 1%, let's leave
+ * 2% room for error on both sides, total variation would be 4%, which is
+ * approximately 40 points with a 10 bit ADC. The hardware specification
+ * guarantees valid readings to be at least 64 bits (2^6) apart.
+ */
+#define ACCEPTABLE_DELTA  (int)(1024 * .02)
 
 uint8_t board_id(void)
 {
+	static int cached_board_id = -1;
+	int i;
+	int adc_reading;
+
+	if (cached_board_id != -1)
+		return cached_board_id;
+
+	adc_reading = get_saradc_value(1);
+	for (i = 0; i < ARRAY_SIZE(board_id_readings); i++) {
+		int delta = board_id_readings[i] - adc_reading;
+
+		if ((delta < ACCEPTABLE_DELTA) && (delta > -ACCEPTABLE_DELTA)) {
+			printk(BIOS_DEBUG, "ADC reading %d, "
+			       "expected value %d board ID %d\n",
+			       adc_reading, delta + adc_reading, i);
+			cached_board_id = i;
+			return i;
+		}
+	}
+
+	printk(BIOS_ERR, "Unmatched ADC reading of %d, using Board ID of 0\n",
+	       adc_reading);
 	return 0;
 }
 



More information about the coreboot-gerrit mailing list