summaryrefslogtreecommitdiff
path: root/common/cbi_gpio.c
diff options
context:
space:
mode:
authorPhilip Chen <philipchen@google.com>2021-07-01 17:03:20 -0700
committerCommit Bot <commit-bot@chromium.org>2021-07-14 18:06:31 +0000
commitc97cb76b816fc8e02fe3de0652794e85fe38f4c6 (patch)
treee0f3cad98aa4e6f1093374bc7f6fe5dd9e84eadd /common/cbi_gpio.c
parent5236e3b1af983a46fe79a14d353354640c0e89cc (diff)
downloadchrome-ec-c97cb76b816fc8e02fe3de0652794e85fe38f4c6.tar.gz
cbi: Introduce CONFIG_CBI_GPIO
For the boards where SKU_ID/BRD_ID comes from the strapping pins on EC, this new config enables AP to ask EC for those hardware configs using the CBI host command `EC_CMD_GET_CROS_BOARD_INFO`. BRANCH=None BUG=b:186264627 TEST=make buildall -j TEST=Enabled CONFIG_CBI_GPIO for lazor and manually verified with `ectool cbi get`. Change-Id: I7ec9097bab96d2076d9d42db2d003460db000113 Signed-off-by: Philip Chen <philipchen@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3002452 Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org>
Diffstat (limited to 'common/cbi_gpio.c')
-rw-r--r--common/cbi_gpio.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/common/cbi_gpio.c b/common/cbi_gpio.c
new file mode 100644
index 0000000000..7b9fb25ebb
--- /dev/null
+++ b/common/cbi_gpio.c
@@ -0,0 +1,72 @@
+/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Support Cros Board Info GPIO */
+
+#include "console.h"
+#include "cros_board_info.h"
+#include "gpio.h"
+#include "system.h"
+#include "util.h"
+
+#define CPRINTS(format, args...) cprints(CC_SYSTEM, "CBI " format, ## args)
+
+static int cbi_gpio_read(uint8_t offset, uint8_t *data, int len)
+{
+ int board_id;
+ int sku_id;
+ int rv;
+ int err = 0;
+
+ if (cbi_get_cache_status() == CBI_CACHE_STATUS_SYNCED)
+ return EC_SUCCESS;
+
+ cbi_create();
+
+ board_id = system_get_board_version();
+ if (board_id < 0) {
+ CPRINTS("Failed (%d) to get a valid board id", -board_id);
+ err++;
+ } else {
+ rv = cbi_set_board_info(CBI_TAG_BOARD_VERSION,
+ (uint8_t *)&board_id, sizeof(int));
+ if (rv) {
+ CPRINTS("Failed (%d) to set BOARD_VERSION tag", rv);
+ err++;
+ }
+ }
+
+ sku_id = system_get_sku_id();
+ rv = cbi_set_board_info(CBI_TAG_SKU_ID,
+ (uint8_t *)&sku_id, sizeof(int));
+ if (rv) {
+ CPRINTS("Failed (%d) to set SKU_ID tag", rv);
+ err++;
+ }
+
+ if (err > 0)
+ return EC_ERROR_UNKNOWN;
+
+ return EC_SUCCESS;
+}
+
+static int cbi_gpio_is_write_protected(void)
+{
+ /*
+ * When CBI comes from strapping pins, any attempts for updating CBI
+ * storage should be rejected.
+ */
+ return 1;
+}
+
+const struct cbi_storage_driver gpio_drv = {
+ .load = cbi_gpio_read,
+ .is_protected = cbi_gpio_is_write_protected,
+};
+
+const struct cbi_storage_config_t cbi_config = {
+ .storage_type = CBI_STORAGE_TYPE_GPIO,
+ .drv = &gpio_drv,
+};