summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMichał Barnaś <mb@semihalf.com>2021-08-06 14:16:34 +0200
committerCommit Bot <commit-bot@chromium.org>2021-08-18 01:33:10 +0000
commitdac94834ba1fe8a60ec6e6b0f3884782dd95a270 (patch)
tree67e734e4917024406fa7a72f222e2bab4a4771e0 /common
parent1f723e545eafada64da2ce0bd9b5b9e5d183d5aa (diff)
downloadchrome-ec-dac94834ba1fe8a60ec6e6b0f3884782dd95a270.tar.gz
zephyr: provide unified method to get sku id and board version
Previously, functions for reading board version and sku id were defined in board.c files which are not compiled in Zephyr builds. Logic from board.c files should be moved to the DeviceTree files. This commit adds support for defining board version and sku id pins and numeral system used to decode them. BRANCH=main BUG=b:194136536 TEST=Call system_get_sku_id and system_get_board_version on CrOS EC and Zephyr, values should be correct and the same on both versions Change-Id: I61b5e205cb2a2299ad86c5dff38c05a9659eb2d3 Signed-off-by: Michał Barnaś <mb@semihalf.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3048102 Reviewed-by: Wai-Hong Tam <waihong@google.com> Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Wai-Hong Tam <waihong@google.com> Tested-by: Wai-Hong Tam <waihong@google.com>
Diffstat (limited to 'common')
-rw-r--r--common/util.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/common/util.c b/common/util.c
index 7ed4c45c53..deaa62f37f 100644
--- a/common/util.c
+++ b/common/util.c
@@ -767,3 +767,27 @@ int binary_first_base3_from_bits(int *bits, int nbits)
/* binary_below is normal binary system value if !has_z. */
return binary_below;
}
+
+int binary_from_bits(int *bits, int nbits)
+{
+ int value = 0;
+ int i;
+
+ /* Loop through every binary digit, from MSB to LSB. */
+ for (i = nbits - 1; i >= 0; i--)
+ value = (value << 1) | bits[i];
+
+ return value;
+}
+
+int ternary_from_bits(int *bits, int nbits)
+{
+ int value = 0;
+ int i;
+
+ /* Loop through every ternary digit, from MSB to LSB. */
+ for (i = nbits - 1; i >= 0; i--)
+ value = (value * 3) + bits[i];
+
+ return value;
+}