summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Barnes <robbarnes@google.com>2021-02-26 08:16:25 -0700
committerCommit Bot <commit-bot@chromium.org>2021-04-08 01:13:30 +0000
commit974b3d7e4621a449672df5267007c7aeb2d7af68 (patch)
treedd27510aa5367e653ce04550a21e3543eb7b3c02
parent51cf9f6619f2979a43e7ef5c6e9824b4bd715966 (diff)
downloadchrome-ec-974b3d7e4621a449672df5267007c7aeb2d7af68.tar.gz
guybrush: Add guybrush fw_configstabilize-glibc-13901.B-main
Each guybrush variant may have a different fw_config schema. Defining a schema agnostic fw_config interface at baseboard. Each guybrush variant must implement the interface. Fields that are not applicable outside a specific variant do not need to be exposed in the baseboard interface. BUG=b:178215011 TEST=Build and run on Guybrush B2 BRANCH=None Change-Id: I41d24ffddfc41d3148ba6d3685f728f6ec962919 Signed-off-by: Rob Barnes <robbarnes@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2722982 Reviewed-by: Diana Z <dzigterman@chromium.org>
-rw-r--r--baseboard/guybrush/base_fw_config.h50
-rw-r--r--baseboard/guybrush/baseboard.c16
-rw-r--r--board/guybrush/board_fw_config.c35
-rw-r--r--board/guybrush/board_fw_config.h38
-rw-r--r--board/guybrush/build.mk1
5 files changed, 140 insertions, 0 deletions
diff --git a/baseboard/guybrush/base_fw_config.h b/baseboard/guybrush/base_fw_config.h
new file mode 100644
index 0000000000..25463384af
--- /dev/null
+++ b/baseboard/guybrush/base_fw_config.h
@@ -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.
+ */
+
+#ifndef _GUYBRUSH_BASE_FW_CONFIG__H_
+#define _GUYBRUSH_BASE_FW_CONFIG__H_
+
+#define UNINITIALIZED_FW_CONFIG 0xFFFFFFFF
+
+#include <stdbool.h>
+#include <stdint.h>
+
+/*
+ * Takes a bit offset and bit width and returns the fw_config field at that
+ * offset and width. Returns -1 if an error occurs.
+ */
+int get_fw_config_field(uint8_t offset, uint8_t width);
+
+/*
+ * Each Guybrush board variant will define a board specific fw_config schema.
+ * Below is the schema agnostic interface for fw_config fields.
+ * Fields that are not applicable outside a specific Guybrush variant do not
+ * need to be included here.
+ */
+
+enum board_usb_a1_retimer {
+ USB_A1_RETIMER_UNKNOWN,
+ USB_A1_RETIMER_PS8811,
+ USB_A1_RETIMER_ANX7491
+};
+
+enum board_usb_c1_mux {
+ USB_C1_MUX_UNKNOWN,
+ USB_C1_MUX_PS8818,
+ USB_C1_MUX_ANX7451
+};
+
+enum board_form_factor {
+ FORM_FACTOR_UNKNOWN,
+ FORM_FACTOR_CLAMSHELL,
+ FORM_FACTOR_CONVERTIBLE
+};
+
+bool board_has_kblight(void);
+enum board_usb_a1_retimer board_get_usb_a1_retimer(void);
+enum board_usb_c1_mux board_get_usb_c1_mux(void);
+enum board_form_factor board_get_form_factor(void);
+
+#endif /* _GUYBRUSH_BASE_FW_CONFIG__H_ */
diff --git a/baseboard/guybrush/baseboard.c b/baseboard/guybrush/baseboard.c
index 5c517be91e..b8f37025eb 100644
--- a/baseboard/guybrush/baseboard.c
+++ b/baseboard/guybrush/baseboard.c
@@ -7,6 +7,8 @@
#include "adc.h"
#include "adc_chip.h"
+#include "cros_board_info.h"
+#include "base_fw_config.h"
#include "battery_fuel_gauge.h"
#include "charge_manager.h"
#include "charge_ramp.h"
@@ -955,3 +957,17 @@ void baseboard_en_pwr_s0(enum gpio_signal signal)
/* Now chain off to the normal power signal interrupt handler. */
power_signal_interrupt(signal);
}
+
+int get_fw_config_field(uint8_t offset, uint8_t width)
+{
+ static uint32_t cached_fw_config = UNINITIALIZED_FW_CONFIG;
+
+ if (cached_fw_config == UNINITIALIZED_FW_CONFIG) {
+ uint32_t val;
+
+ if (cbi_get_fw_config(&val) != EC_SUCCESS)
+ return -1;
+ cached_fw_config = val;
+ }
+ return (cached_fw_config >> offset) & ((1 << width) - 1);
+}
diff --git a/board/guybrush/board_fw_config.c b/board/guybrush/board_fw_config.c
new file mode 100644
index 0000000000..b971ad7301
--- /dev/null
+++ b/board/guybrush/board_fw_config.c
@@ -0,0 +1,35 @@
+/* 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 "base_fw_config.h"
+#include "board_fw_config.h"
+
+bool board_has_kblight(void)
+{
+ return (get_fw_config_field(FW_CONFIG_KBLIGHT_OFFSET,
+ FW_CONFIG_KBLIGHT_WIDTH) == FW_CONFIG_KBLIGHT_YES);
+}
+
+enum board_usb_c1_mux board_get_usb_c1_mux(void)
+{
+ int usb_db = get_fw_config_field(FW_CONFIG_USB_DB_OFFSET,
+ FW_CONFIG_USB_DB_WIDTH);
+ if (usb_db == FW_CONFIG_USB_DB_A1_PS8811_C1_PS8818)
+ return USB_C1_MUX_PS8818;
+ if (usb_db == FW_CONFIG_USB_DB_A1_ANX7491_C1_ANX7451)
+ return USB_C1_MUX_ANX7451;
+ return USB_C1_MUX_UNKNOWN;
+};
+
+enum board_usb_a1_retimer board_get_usb_a1_retimer(void)
+{
+ int usb_db = get_fw_config_field(FW_CONFIG_USB_DB_OFFSET,
+ FW_CONFIG_USB_DB_WIDTH);
+ if (usb_db == FW_CONFIG_USB_DB_A1_PS8811_C1_PS8818)
+ return USB_A1_RETIMER_PS8811;
+ if (usb_db == FW_CONFIG_USB_DB_A1_ANX7491_C1_ANX7451)
+ return USB_A1_RETIMER_ANX7491;
+ return USB_A1_RETIMER_UNKNOWN;
+};
diff --git a/board/guybrush/board_fw_config.h b/board/guybrush/board_fw_config.h
new file mode 100644
index 0000000000..80098d8eff
--- /dev/null
+++ b/board/guybrush/board_fw_config.h
@@ -0,0 +1,38 @@
+/* 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 _GUYBRUSH_BOARD_FW_CONFIG__H_
+#define _GUYBRUSH_BOARD_FW_CONFIG__H_
+
+/****************************************************************************
+ * Guybrush CBI FW Configuration
+ */
+
+/*
+ * USB Daughter Board (2 bits)
+ */
+#define FW_CONFIG_USB_DB_OFFSET 0
+#define FW_CONFIG_USB_DB_WIDTH 2
+#define FW_CONFIG_USB_DB_A1_PS8811_C1_PS8818 0
+#define FW_CONFIG_USB_DB_A1_ANX7491_C1_ANX7451 1
+
+/*
+ * Form Factor (1 bits)
+ */
+#define FW_CONFIG_FORM_FACTOR_OFFSET 2
+#define FW_CONFIG_FORM_FACTOR_WIDTH 1
+#define FW_CONFIG_FORM_FACTOR_CLAMSHELL 0
+#define FW_CONFIG_FORM_FACTOR_CONVERTIABLE 1
+
+/*
+ * Keyboard Backlight (1 bit)
+ */
+#define FW_CONFIG_KBLIGHT_OFFSET 3
+#define FW_CONFIG_KBLIGHT_WIDTH 1
+#define FW_CONFIG_KBLIGHT_NO 0
+#define FW_CONFIG_KBLIGHT_YES 1
+
+
+#endif /* _GUYBRUSH_CBI_FW_CONFIG__H_ */
diff --git a/board/guybrush/build.mk b/board/guybrush/build.mk
index c76e04a0b7..1e79b1895e 100644
--- a/board/guybrush/build.mk
+++ b/board/guybrush/build.mk
@@ -9,3 +9,4 @@
BASEBOARD:=guybrush
board-y=board.o
+board-y+=board_fw_config.o