summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaveh Jalali <caveh@chromium.org>2020-01-13 18:20:33 -0800
committerCommit Bot <commit-bot@chromium.org>2020-01-24 09:22:49 +0000
commit1f04b10f37eb6e4da944fc73b7dfc301b9fad28f (patch)
tree0377c5e3d3f90d1592f9b7ba76332ef9604b7eb9
parentdf00f2c6857b73db36fe9082128422bb788bf1cb (diff)
downloadchrome-ec-1f04b10f37eb6e4da944fc73b7dfc301b9fad28f.tar.gz
volteer: use CBI for board ID and DB config
This adds support for reading the board ID and daughterboard ID from CBI. The FW_CONFIG CBI tag is used to determine which daughterboard is attached. Current boards do not have the FW_CONFIG tag set up, so we'll default to the USB4 board type when this tag is not found to preserve current behavior. BRANCH=none BUG=b:148117843 TEST=verified volteer can read daughterboard type from CBI Change-Id: Ie2f808a794e668f52497f041738e724e848016de Signed-off-by: Caveh Jalali <caveh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2013655 Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r--baseboard/volteer/baseboard.c53
-rw-r--r--baseboard/volteer/baseboard.h19
2 files changed, 72 insertions, 0 deletions
diff --git a/baseboard/volteer/baseboard.c b/baseboard/volteer/baseboard.c
index 0a0b6e526f..f8bba377b6 100644
--- a/baseboard/volteer/baseboard.c
+++ b/baseboard/volteer/baseboard.c
@@ -8,6 +8,7 @@
#include "bb_retimer.h"
#include "charge_manager.h"
#include "charge_state.h"
+#include "cros_board_info.h"
#include "driver/bc12/pi3usb9201.h"
#include "driver/ppc/sn5s330.h"
#include "driver/ppc/syv682x.h"
@@ -584,3 +585,55 @@ static void baseboard_init(void)
pwm_set_duty(PWM_CH_LED4_SIDESEL, 50);
}
DECLARE_HOOK(HOOK_INIT, baseboard_init, HOOK_PRIO_DEFAULT);
+
+static uint8_t board_id;
+static enum usb_db_id usb_db_type = USB_DB_NONE;
+
+uint8_t get_board_id(void)
+{
+ return board_id;
+}
+
+/*
+ * Read CBI from i2c eeprom and initialize variables for board variants
+ *
+ * Example for configuring for a USB3 DB:
+ * ectool cbi set 6 2 4 10
+ */
+static void cbi_init(void)
+{
+ uint32_t cbi_val;
+ uint32_t usb_db_val;
+
+ /* Board ID */
+ if (cbi_get_board_version(&cbi_val) != EC_SUCCESS ||
+ cbi_val > UINT8_MAX)
+ CPRINTS("CBI: Read Board ID failed");
+
+ board_id = cbi_val;
+
+ CPRINTS("Board ID: %d", board_id);
+
+ /* 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;
+ } else {
+ usb_db_val = CBI_FW_CONFIG_USB_DB_TYPE(cbi_val);
+ }
+
+ switch (usb_db_val) {
+ case USB_DB_NONE:
+ CPRINTS("Daughterboard type: None");
+ break;
+ case USB_DB_USB4:
+ CPRINTS("Daughterboard type: USB4");
+ break;
+ default:
+ CPRINTS("Daughterboard ID %d not supported", usb_db_val);
+ usb_db_val = USB_DB_NONE;
+ }
+ usb_db_type = usb_db_val;
+}
+DECLARE_HOOK(HOOK_INIT, cbi_init, HOOK_PRIO_INIT_I2C + 1);
diff --git a/baseboard/volteer/baseboard.h b/baseboard/volteer/baseboard.h
index 39cfc3d7aa..ff41a49ab4 100644
--- a/baseboard/volteer/baseboard.h
+++ b/baseboard/volteer/baseboard.h
@@ -278,6 +278,23 @@ enum sensor_id {
SENSOR_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 = 1,
+ USB_DB_USB3 = 2,
+ 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)
+
void board_reset_pd_mcu(void);
/* Common definition for the USB PD interrupt handlers. */
@@ -285,6 +302,8 @@ void ppc_interrupt(enum gpio_signal signal);
void tcpc_alert_event(enum gpio_signal signal);
void bc12_interrupt(enum gpio_signal signal);
+unsigned char get_board_id(void);
+
#endif /* !__ASSEMBLER__ */
#endif /* __CROS_EC_BASEBOARD_H */