summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Short <keithshort@chromium.org>2020-05-01 15:04:12 -0600
committerCommit Bot <commit-bot@chromium.org>2020-07-02 02:40:18 +0000
commit07833a0fc114e28c200fcee5691c082534344bfe (patch)
tree4eff0da4cc6309f1e1d54c1a5ed659de0b3b740f
parent0d0158ea48e25ac4042d7142db1985e5a6a3472f (diff)
downloadchrome-ec-07833a0fc114e28c200fcee5691c082534344bfe.tar.gz
volteer: create common FW_CONFIG layout
Create a common FW_CONFIG layout and access functions for Volteer boards. BUG=b:155497872 BRANCH=none TEST=make buildall TEST=verify FW_CONFIG data on Volteer Signed-off-by: Keith Short <keithshort@chromium.org> Change-Id: I1ec14db6c816d82115caa5e6179e0258f2904ec4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2247616 Reviewed-by: caveh jalali <caveh@chromium.org>
-rw-r--r--baseboard/volteer/baseboard.c54
-rw-r--r--baseboard/volteer/baseboard.h36
-rw-r--r--baseboard/volteer/build.mk1
-rw-r--r--baseboard/volteer/cbi_ec_fw_config.c49
-rw-r--r--baseboard/volteer/cbi_ec_fw_config.h83
-rw-r--r--board/delbin/board.c12
-rw-r--r--board/malefor/board.c7
-rw-r--r--board/volteer/board.c12
8 files changed, 163 insertions, 91 deletions
diff --git a/baseboard/volteer/baseboard.c b/baseboard/volteer/baseboard.c
index 1586c759f6..78d720eedc 100644
--- a/baseboard/volteer/baseboard.c
+++ b/baseboard/volteer/baseboard.c
@@ -7,6 +7,7 @@
#include "adc_chip.h"
#include "bb_retimer.h"
#include "button.h"
+#include "cbi_ec_fw_config.h"
#include "charge_manager.h"
#include "charge_state.h"
#include "cros_board_info.h"
@@ -297,8 +298,6 @@ static const struct usb_mux mux_config_p1_usb3 = {
.next_mux = &usbc1_usb3_db_retimer,
};
-static enum usb_db_id usb_db_type = USB_DB_NONE;
-
/******************************************************************************/
/* USBC PPC configuration */
struct ppc_config_t ppc_chips[] = {
@@ -423,9 +422,11 @@ static void ps8815_reset(void)
void board_reset_pd_mcu(void)
{
+ enum ec_cfg_usb_db_type usb_db = ec_cfg_usb_db_type();
+
/* No reset available for TCPC on port 0 */
/* Daughterboard specific reset for port 1 */
- if (usb_db_type == USB_DB_USB3) {
+ if (usb_db == DB_USB3_ACTIVE) {
ps8815_reset();
usb_mux_hpd_update(USBC_PORT_C1, 0, 0);
}
@@ -585,32 +586,12 @@ static void config_db_usb3(void)
}
static uint8_t board_id;
-static uint32_t fw_config;
uint8_t get_board_id(void)
{
return board_id;
}
-enum usb_db_id get_usb_db_type(void)
-{
- return usb_db_type;
-}
-
-uint32_t get_fw_config(void)
-{
- return fw_config;
-}
-
-/*
- * ec_config_has_tablet_mode() will return 1 is present or 0
- */
-enum ec_cfg_tablet_mode_type ec_config_has_tablet_mode(void)
-{
- return ((get_fw_config() & EC_CFG_TABLET_MODE_MASK)
- >> EC_CFG_TABLET_MODE_L);
-}
-
__overridable void config_volteer_gpios(void)
{
}
@@ -625,7 +606,7 @@ static const char *db_type_prefix = "USB DB type: ";
static void cbi_init(void)
{
uint32_t cbi_val;
- uint32_t usb_db_val;
+ enum ec_cfg_usb_db_type usb_db;
/* Board ID */
if (cbi_get_board_version(&cbi_val) != EC_SUCCESS ||
@@ -639,32 +620,25 @@ static void cbi_init(void)
config_volteer_gpios();
/* FW config */
- if (cbi_get_fw_config(&cbi_val) != EC_SUCCESS) {
- CPRINTS("CBI: Read FW config failed, assuming USB4");
- usb_db_val = USB_DB_USB4_GEN2;
- } else {
- fw_config = cbi_val;
- usb_db_val = CBI_FW_CONFIG_USB_DB_TYPE(cbi_val);
- }
+ init_fw_config();
+ usb_db = ec_cfg_usb_db_type();
- switch (usb_db_val) {
- case USB_DB_NONE:
+ switch (usb_db) {
+ case DB_USB_ABSENT:
CPRINTS("%sNone", db_type_prefix);
break;
- case USB_DB_USB4_GEN2:
+ case DB_USB4_GEN2:
CPRINTS("%sUSB4 Gen1/2", db_type_prefix);
break;
- case USB_DB_USB4_GEN3:
+ case DB_USB4_GEN3:
CPRINTS("%sUSB4 Gen3", db_type_prefix);
break;
- case USB_DB_USB3:
+ case DB_USB3_ACTIVE:
config_db_usb3();
- CPRINTS("%sUSB3", db_type_prefix);
+ CPRINTS("%sUSB3 Active", db_type_prefix);
break;
default:
- CPRINTS("%sID %d not supported", db_type_prefix, usb_db_val);
- usb_db_val = USB_DB_NONE;
+ CPRINTS("%sID %d not supported", db_type_prefix, usb_db);
}
- usb_db_type = usb_db_val;
}
DECLARE_HOOK(HOOK_INIT, cbi_init, HOOK_PRIO_FIRST);
diff --git a/baseboard/volteer/baseboard.h b/baseboard/volteer/baseboard.h
index 80dac9f1ae..a134c9ced8 100644
--- a/baseboard/volteer/baseboard.h
+++ b/baseboard/volteer/baseboard.h
@@ -266,39 +266,6 @@ enum usbc_port {
USBC_PORT_COUNT
};
-/*
- * Daughterboard type is encoded in the lower 4 bits
- * of the FW_CONFIG CBI tag.
- */
-
-enum usb_db_id {
- USB_DB_NONE = 0,
- USB_DB_USB4_GEN2 = 1,
- USB_DB_USB3 = 2,
- USB_DB_USB4_GEN3 = 3,
- USB_DB_COUNT
-};
-
-#define CBI_FW_CONFIG_USB_DB_MASK 0x0f
-#define CBI_FW_CONFIG_USB_DB_SHIFT 0
-#define CBI_FW_CONFIG_USB_DB_TYPE(bits) \
- (((bits) & CBI_FW_CONFIG_USB_DB_MASK) >> CBI_FW_CONFIG_USB_DB_SHIFT)
-
-/*
- * Tablet Mode (1 bit)
- *
- * ec_config_has_tablet_mode() will return 1 is present or 0
- */
-enum ec_cfg_tablet_mode_type {
- TABLET_MODE_NO = 0,
- TABLET_MODE_YES = 1,
-};
-#define EC_CFG_TABLET_MODE_L 11
-#define EC_CFG_TABLET_MODE_H 11
-#define EC_CFG_TABLET_MODE_MASK \
- GENMASK(EC_CFG_TABLET_MODE_H,\
- EC_CFG_TABLET_MODE_L)
-
extern enum gpio_signal ps8xxx_rst_odl;
void board_reset_pd_mcu(void);
@@ -309,7 +276,6 @@ void tcpc_alert_event(enum gpio_signal signal);
void bc12_interrupt(enum gpio_signal signal);
unsigned char get_board_id(void);
-enum usb_db_id get_usb_db_type(void);
/**
* Configure GPIOs based on the CBI board version. Boards in the Volteer
@@ -318,8 +284,6 @@ enum usb_db_id get_usb_db_type(void);
*/
__override_proto void config_volteer_gpios(void);
-enum ec_cfg_tablet_mode_type ec_config_has_tablet_mode(void);
-
#endif /* !__ASSEMBLER__ */
#endif /* __CROS_EC_BASEBOARD_H */
diff --git a/baseboard/volteer/build.mk b/baseboard/volteer/build.mk
index cae1d5aac8..662f3abdee 100644
--- a/baseboard/volteer/build.mk
+++ b/baseboard/volteer/build.mk
@@ -9,3 +9,4 @@
baseboard-y=baseboard.o
baseboard-y+=battery_presence.o
baseboard-y+=usb_pd_policy.o
+baseboard-y+=cbi_ec_fw_config.o
diff --git a/baseboard/volteer/cbi_ec_fw_config.c b/baseboard/volteer/cbi_ec_fw_config.c
new file mode 100644
index 0000000000..145115e930
--- /dev/null
+++ b/baseboard/volteer/cbi_ec_fw_config.c
@@ -0,0 +1,49 @@
+/* Copyright 2020 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 volteer_cbi_fw_config fw_config;
+BUILD_ASSERT(sizeof(fw_config) == sizeof(uint32_t));
+
+/*
+ * TODO in separate CL. Update FW_CONFIG default for all Volteer projects
+ */
+union volteer_cbi_fw_config fw_config_defaults = {
+ .usb_db = DB_USB4_GEN2,
+};
+
+/****************************************************************************
+ * Volteer 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;
+ }
+}
+
+union volteer_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;
+}
+
+bool ec_cfg_has_tabletmode(void)
+{
+ return (fw_config.tabletmode == TABLETMODE_ENABLED);
+}
+
+
diff --git a/baseboard/volteer/cbi_ec_fw_config.h b/baseboard/volteer/cbi_ec_fw_config.h
new file mode 100644
index 0000000000..c3632e4cda
--- /dev/null
+++ b/baseboard/volteer/cbi_ec_fw_config.h
@@ -0,0 +1,83 @@
+/* Copyright 2020 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 __VOLTEER_CBI_EC_FW_CONFIG_H_
+#define __VOLTEER_CBI_EC_FW_CONFIG_H_
+
+#include "stdbool.h"
+
+/****************************************************************************
+ * CBI FW_CONFIG layout shared by all Volteer boards
+ *
+ * Source of truth is the program/volteer/program.star configuration file.
+ */
+
+enum ec_cfg_usb_db_type {
+ DB_USB_ABSENT = 0,
+ DB_USB4_GEN2 = 1,
+ DB_USB3_ACTIVE = 2,
+ DB_USB4_GEN3 = 3,
+ DB_USB3_PASSIVE = 4,
+ DB_USB3_NO_A = 5,
+ DB_USB_COUNT
+};
+
+/*
+ * Tablet Mode (1 bit), shared by all Volteer boards
+ */
+enum ec_cfg_tabletmode_type {
+ TABLETMODE_DISABLED = 0,
+ TABLETMODE_ENABLED = 1,
+};
+
+union volteer_cbi_fw_config {
+ struct {
+ enum ec_cfg_usb_db_type usb_db : 4;
+ uint32_t thermal : 4;
+ uint32_t audio : 3;
+ enum ec_cfg_tabletmode_type tabletmode : 1;
+ uint32_t lte_db : 2;
+ uint32_t reserved_1 : 2;
+ uint32_t sd_db : 4;
+ uint32_t reserved_2 : 12;
+ };
+ uint32_t raw_value;
+};
+
+/*
+ * Each Volteer board must define the default FW_CONFIG options to use
+ * if the CBI data has not been initialized.
+ */
+extern union volteer_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 volteer_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);
+
+/**
+ * Check if the FW_CONFIG has enabled tablet mode operation.
+ *
+ * @return true if board supports tablet mode, false if the board supports
+ * clamshell operation only.
+ */
+bool ec_cfg_has_tabletmode(void);
+
+#endif /* __VOLTEER_CBI_EC_FW_CONFIG_H_ */
diff --git a/board/delbin/board.c b/board/delbin/board.c
index 06f4797e8b..150c72a7f1 100644
--- a/board/delbin/board.c
+++ b/board/delbin/board.c
@@ -8,6 +8,7 @@
#include "button.h"
#include "common.h"
#include "accelgyro.h"
+#include "cbi_ec_fw_config.h"
#include "driver/accel_bma2x2.h"
#include "driver/accelgyro_bmi260.h"
#include "driver/retimer/bb_retimer.h"
@@ -51,17 +52,17 @@ DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
__override enum tbt_compat_cable_speed board_get_max_tbt_speed(int port)
{
- enum usb_db_id usb_db_type = get_usb_db_type();
+ enum ec_cfg_usb_db_type usb_db = ec_cfg_usb_db_type();
if (port == USBC_PORT_C1) {
- if (usb_db_type == USB_DB_USB4_GEN2) {
+ if (usb_db == DB_USB4_GEN2) {
/*
* Older boards violate 205mm trace length prior
* to connection to the re-timer and only support up
* to GEN2 speeds.
*/
return TBT_SS_U32_GEN1_GEN2;
- } else if (usb_db_type == USB_DB_USB4_GEN3) {
+ } else if (usb_db == DB_USB4_GEN3) {
return TBT_SS_TBT_GEN3;
}
}
@@ -77,7 +78,7 @@ __override enum tbt_compat_cable_speed board_get_max_tbt_speed(int port)
__override bool board_is_tbt_usb4_port(int port)
{
- enum usb_db_id usb_db_type = get_usb_db_type();
+ enum ec_cfg_usb_db_type usb_db = ec_cfg_usb_db_type();
/*
* Volteer reference design only supports TBT & USB4 on port 1
@@ -87,8 +88,7 @@ __override bool board_is_tbt_usb4_port(int port)
* features. Need to fix once USB-C feature set is known for Volteer.
*/
return ((port == USBC_PORT_C1)
- && ((usb_db_type == USB_DB_USB4_GEN2)
- || (usb_db_type == USB_DB_USB4_GEN3)));
+ && ((usb_db == DB_USB4_GEN2) || (usb_db == DB_USB4_GEN3)));
}
/******************************************************************************/
diff --git a/board/malefor/board.c b/board/malefor/board.c
index 43fe41e27b..88268f637c 100644
--- a/board/malefor/board.c
+++ b/board/malefor/board.c
@@ -6,6 +6,7 @@
/* Malefor board-specific configuration */
#include "button.h"
+#include "cbi_ec_fw_config.h"
#include "common.h"
#include "driver/accel_lis2dh.h"
#include "driver/accelgyro_lsm6dsm.h"
@@ -35,7 +36,7 @@
static void board_init(void)
{
- if (ec_config_has_tablet_mode()) {
+ if (ec_cfg_has_tabletmode()) {
/* Enable gpio interrupt for base accelgyro sensor */
gpio_enable_interrupt(GPIO_EC_IMU_INT_L);
} else {
@@ -58,14 +59,14 @@ DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
int board_is_lid_angle_tablet_mode(void)
{
- return ec_config_has_tablet_mode();
+ return ec_cfg_has_tabletmode();
}
/* Enable or disable input devices, based on tablet mode or chipset state */
#ifndef TEST_BUILD
void lid_angle_peripheral_enable(int enable)
{
- if (ec_config_has_tablet_mode()) {
+ if (ec_cfg_has_tabletmode()) {
if (chipset_in_state(CHIPSET_STATE_ANY_OFF) ||
tablet_get_mode())
enable = 0;
diff --git a/board/volteer/board.c b/board/volteer/board.c
index 77685650a5..ad1c6006b4 100644
--- a/board/volteer/board.c
+++ b/board/volteer/board.c
@@ -8,6 +8,7 @@
#include "button.h"
#include "common.h"
#include "accelgyro.h"
+#include "cbi_ec_fw_config.h"
#include "driver/accel_bma2x2.h"
#include "driver/accelgyro_bmi260.h"
#include "driver/als_tcs3400.h"
@@ -63,17 +64,17 @@ DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
__override enum tbt_compat_cable_speed board_get_max_tbt_speed(int port)
{
- enum usb_db_id usb_db_type = get_usb_db_type();
+ enum ec_cfg_usb_db_type usb_db = ec_cfg_usb_db_type();
if (port == USBC_PORT_C1) {
- if (usb_db_type == USB_DB_USB4_GEN2) {
+ if (usb_db == DB_USB4_GEN2) {
/*
* Older boards violate 205mm trace length prior
* to connection to the re-timer and only support up
* to GEN2 speeds.
*/
return TBT_SS_U32_GEN1_GEN2;
- } else if (usb_db_type == USB_DB_USB4_GEN3) {
+ } else if (usb_db == DB_USB4_GEN3) {
return TBT_SS_TBT_GEN3;
}
}
@@ -89,7 +90,7 @@ __override enum tbt_compat_cable_speed board_get_max_tbt_speed(int port)
__override bool board_is_tbt_usb4_port(int port)
{
- enum usb_db_id usb_db_type = get_usb_db_type();
+ enum ec_cfg_usb_db_type usb_db = ec_cfg_usb_db_type();
/*
* Volteer reference design only supports TBT & USB4 on port 1
@@ -99,8 +100,7 @@ __override bool board_is_tbt_usb4_port(int port)
* features. Need to fix once USB-C feature set is known for Volteer.
*/
return ((port == USBC_PORT_C1)
- && ((usb_db_type == USB_DB_USB4_GEN2)
- || (usb_db_type == USB_DB_USB4_GEN3)));
+ && ((usb_db == DB_USB4_GEN2) || (usb_db == DB_USB4_GEN3)));
}
/******************************************************************************/