summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaveh Jalali <caveh@chromium.org>2021-02-19 02:31:24 -0800
committerCommit Bot <commit-bot@chromium.org>2021-02-27 04:04:56 +0000
commit16a6024a7a38acf9d3eac7e304f30db23b169ff6 (patch)
treeb0efca130645a49e9433596c5074133a3cb1981f
parent924d0cad36a6a6a1d87df5926a0af8c77ddb244b (diff)
downloadchrome-ec-stabilize-13821.B-main.tar.gz
brya: Add CBI and FW_CONFIG supportstabilize-13821.B-main
This adds support for CBI and the first USB DB type field in FW_CONFIG. BUG=b:173575131,b:180434685 BRANCH=none TEST=buildall succeeds Signed-off-by: Caveh Jalali <caveh@chromium.org> Change-Id: If1d27fc100db9b814f90a9378d8dd19530a92bf4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2706964 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Sooraj Govindan <sooraj.govindan@intel.com>
-rw-r--r--baseboard/brya/baseboard.h18
-rw-r--r--baseboard/brya/build.mk2
-rw-r--r--baseboard/brya/cbi.c47
-rw-r--r--baseboard/brya/cbi_ec_fw_config.c50
-rw-r--r--baseboard/brya/cbi_ec_fw_config.h66
-rw-r--r--board/brya/board.c9
-rw-r--r--board/brya/board.h2
7 files changed, 194 insertions, 0 deletions
diff --git a/baseboard/brya/baseboard.h b/baseboard/brya/baseboard.h
index 189f7f5e26..b70b9de734 100644
--- a/baseboard/brya/baseboard.h
+++ b/baseboard/brya/baseboard.h
@@ -22,6 +22,11 @@
*/
#define NPCX_UART_MODULE2 1 /* 1:GPIO64/65 for UART1 */
+/* EC Defines */
+#define CONFIG_CROS_BOARD_INFO
+#define CONFIG_BOARD_VERSION_CBI
+#define CONFIG_CRC8
+
#define CONFIG_EXTPOWER_GPIO
/* Common Keyboard Defines */
@@ -69,6 +74,14 @@
#include "baseboard_usbc_config.h"
#include "extpower.h"
+/**
+ * Configure run-time data structures and operation based on CBI data. This
+ * typically includes customization for changes in the BOARD_VERSION and
+ * FW_CONFIG fields in CBI. This routine is called from the baseboard after
+ * the CBI data has been initialized.
+ */
+__override_proto void board_cbi_init(void);
+
/*
* Check battery disconnect state.
* This function will return if battery is initialized or not.
@@ -76,6 +89,11 @@
*/
__override_proto bool board_battery_is_initialized(void);
+/*
+ * Return the board revision number.
+ */
+uint8_t get_board_id(void);
+
#endif /* !__ASSEMBLER__ */
#endif /* __CROS_EC_BASEBOARD_H */
diff --git a/baseboard/brya/build.mk b/baseboard/brya/build.mk
index bb5f023c02..e584ac342c 100644
--- a/baseboard/brya/build.mk
+++ b/baseboard/brya/build.mk
@@ -8,3 +8,5 @@
baseboard-y=
baseboard-y+=battery_presence.o
+baseboard-y+=cbi_ec_fw_config.o
+baseboard-y+=cbi.o
diff --git a/baseboard/brya/cbi.c b/baseboard/brya/cbi.c
new file mode 100644
index 0000000000..295dea26a3
--- /dev/null
+++ b/baseboard/brya/cbi.c
@@ -0,0 +1,47 @@
+/* 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.
+ */
+
+#include "cbi_ec_fw_config.h"
+#include "common.h"
+#include "cros_board_info.h"
+#include "hooks.h"
+#include "system.h"
+
+#define CPRINTS(format, args...) cprints(CC_CHIPSET, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_CHIPSET, format, ## args)
+
+static uint8_t board_id;
+
+uint8_t get_board_id(void)
+{
+ return board_id;
+}
+
+__overridable void board_cbi_init(void)
+{
+}
+
+/*
+ * Read CBI from I2C EEPROM and initialize variables for board variants.
+ */
+static void cbi_init(void)
+{
+ uint32_t cbi_val;
+
+ /* Board ID */
+ if (cbi_get_board_version(&cbi_val) != EC_SUCCESS ||
+ cbi_val > UINT8_MAX)
+ CPRINTS("CBI: Read Board ID failed");
+ else
+ board_id = cbi_val;
+
+ CPRINTS("Board ID: %d", board_id);
+
+ init_fw_config();
+
+ /* Allow the board project to make runtime changes based on CBI data */
+ board_cbi_init();
+}
+DECLARE_HOOK(HOOK_INIT, cbi_init, HOOK_PRIO_FIRST);
diff --git a/baseboard/brya/cbi_ec_fw_config.c b/baseboard/brya/cbi_ec_fw_config.c
new file mode 100644
index 0000000000..d81ef4b4e8
--- /dev/null
+++ b/baseboard/brya/cbi_ec_fw_config.c
@@ -0,0 +1,50 @@
+/* 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.
+ */
+
+#include "common.h"
+#include "console.h"
+#include "cbi_ec_fw_config.h"
+#include "cros_board_info.h"
+
+#define CPRINTS(format, args...) cprints(CC_CHIPSET, format, ## args)
+
+static union brya_cbi_fw_config fw_config;
+BUILD_ASSERT(sizeof(fw_config) == sizeof(uint32_t));
+
+/****************************************************************************
+ * Brya FW_CONFIG access
+ */
+void init_fw_config(void)
+{
+ if (cbi_get_fw_config(&fw_config.raw_value)) {
+ CPRINTS("CBI: Read FW_CONFIG failed, using board defaults");
+ fw_config = fw_config_defaults;
+ }
+
+ if (get_board_id() == 0) {
+ /*
+ * Early boards have a zero'd out FW_CONFIG, so replace
+ * it with a sensible default value. If DB_USB_ABSENT2
+ * was used as an alternate encoding of DB_USB_ABSENT to
+ * avoid the zero check, then fix it.
+ */
+ if (fw_config.raw_value == 0) {
+ CPRINTS("CBI: FW_CONFIG is zero, using board defaults");
+ fw_config = fw_config_defaults;
+ } else if (fw_config.usb_db == DB_USB_ABSENT2) {
+ fw_config.usb_db = DB_USB_ABSENT;
+ }
+ }
+}
+
+union brya_cbi_fw_config get_fw_config(void)
+{
+ return fw_config;
+}
+
+enum ec_cfg_usb_db_type ec_cfg_usb_db_type(void)
+{
+ return fw_config.usb_db;
+}
diff --git a/baseboard/brya/cbi_ec_fw_config.h b/baseboard/brya/cbi_ec_fw_config.h
new file mode 100644
index 0000000000..fd56ced869
--- /dev/null
+++ b/baseboard/brya/cbi_ec_fw_config.h
@@ -0,0 +1,66 @@
+/* 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.
+ */
+
+#ifndef __BRYA_CBI_EC_FW_CONFIG_H_
+#define __BRYA_CBI_EC_FW_CONFIG_H_
+
+#include "stdint.h"
+
+/****************************************************************************
+ * CBI FW_CONFIG layout shared by all Brya boards
+ *
+ * Source of truth is the program/brya/program.star configuration file.
+ */
+
+/*
+ * TODO(b/180434685): are these right?
+ * also, remove DB_USB_ABSENT2 after all existing boards have been
+ * set up correctly.
+ */
+
+enum ec_cfg_usb_db_type {
+ DB_USB_ABSENT = 0,
+ DB_USB3_PS8815 = 1,
+ DB_USB_ABSENT2 = 15
+};
+
+union brya_cbi_fw_config {
+ struct {
+ /*
+ * TODO(b/180434685): 4 bits?
+ */
+ enum ec_cfg_usb_db_type usb_db : 4;
+ uint32_t reserved_1 : 28;
+ };
+ uint32_t raw_value;
+};
+
+/*
+ * Each Brya board must define the default FW_CONFIG options to use
+ * if the CBI data has not been initialized.
+ */
+extern const union brya_cbi_fw_config fw_config_defaults;
+
+/**
+ * Initialize the FW_CONFIG from CBI data. If the CBI data is not valid, set the
+ * FW_CONFIG to the board specific defaults.
+ */
+void init_fw_config(void);
+
+/**
+ * Read the cached FW_CONFIG. Guaranteed to have valid values.
+ *
+ * @return the FW_CONFIG for the board.
+ */
+union brya_cbi_fw_config get_fw_config(void);
+
+/**
+ * Get the USB daughter board type from FW_CONFIG.
+ *
+ * @return the USB daughter board type.
+ */
+enum ec_cfg_usb_db_type ec_cfg_usb_db_type(void);
+
+#endif /* __BRYA_CBI_EC_FW_CONFIG_H_ */
diff --git a/board/brya/board.c b/board/brya/board.c
index f1f905fe39..6d799b8bb6 100644
--- a/board/brya/board.c
+++ b/board/brya/board.c
@@ -5,6 +5,7 @@
#include "common.h"
+#include "cbi_ec_fw_config.h"
#include "power.h"
#include "switch.h"
#include "throttle_ap.h"
@@ -22,6 +23,14 @@ BUILD_ASSERT(ARRAY_SIZE(usb_port_enable) == USB_PORT_COUNT);
/******************************************************************************/
/*
+ * FW_CONFIG defaults for brya if the CBI.FW_CONFIG data is not
+ * initialized.
+ */
+const union brya_cbi_fw_config fw_config_defaults = {
+ .usb_db = DB_USB3_PS8815,
+};
+
+/*
* remove when we enable CONFIG_POWER_BUTTON
*/
diff --git a/board/brya/board.h b/board/brya/board.h
index 8a31003481..059d81d8ce 100644
--- a/board/brya/board.h
+++ b/board/brya/board.h
@@ -79,6 +79,8 @@
#define I2C_PORT_CHARGER NPCX_I2C_PORT7_0
#define I2C_PORT_EEPROM NPCX_I2C_PORT7_0
+#define I2C_ADDR_EEPROM_FLAGS 0x50
+
/* Thermal features */
#define CONFIG_THERMISTOR
#define CONFIG_TEMP_SENSOR