summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhuohao Lee <zhuohao@chromium.org>2022-03-09 19:37:55 +0800
committerCommit Bot <commit-bot@chromium.org>2022-03-10 13:39:52 +0000
commitf9eac9a5654611b29e94a496284cb9c79a28d6fa (patch)
treefbfde0b91018b479eb37d9470e04d1bfa7f1ef4f
parent31950eb9061587c09e8fd01f71f8c5cbb965a7be (diff)
downloadchrome-ec-f9eac9a5654611b29e94a496284cb9c79a28d6fa.tar.gz
brask: separate fw_config from the board.*
Currently, we put the fw_config control in the board.* and it would be better to separate it from the board.* and put it into the fw_config.*. Besides, we redefine the fw_config assignment. The new assignment are: 1. 3 bits for audio (0-2) 2. 2 bits for barreljack (3-4) BUG=b:205646582 TEST=run on the DUT and checked the fw_config value. Change-Id: I25a5fd8d25919b7a40f5ee4ace5d41f7df5fb757 Signed-off-by: Zhuohao Lee <zhuohao@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3513273 Reviewed-by: caveh jalali <caveh@chromium.org>
-rw-r--r--board/brask/board.c39
-rw-r--r--board/brask/board.h10
-rw-r--r--board/brask/build.mk1
-rw-r--r--board/brask/fw_config.c65
-rw-r--r--board/brask/fw_config.h47
5 files changed, 116 insertions, 46 deletions
diff --git a/board/brask/board.c b/board/brask/board.c
index 43d7939e2d..4353e8b0e9 100644
--- a/board/brask/board.c
+++ b/board/brask/board.c
@@ -22,6 +22,7 @@
#include "usbc_config.h"
#include "usbc_ppc.h"
#include "driver/tcpm/tcpci.h"
+#include "fw_config.h"
/* Console output macros */
#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args)
@@ -202,36 +203,6 @@ static void port_ocp_interrupt(enum gpio_signal signal)
* only do that if the system is off since it might still brown out.
*/
-/*
- * Barrel-jack power adapter ratings.
- */
-static const struct {
- int voltage;
- int current;
-} bj_power[] = {
- { /* 0 - 135W (also default) */
- .voltage = 19500,
- .current = 6920
- },
- { /* 1 - 230W */
- .voltage = 19500,
- .current = 11800
- },
-};
-
-static unsigned int ec_config_get_bj_power(void)
-{
- uint32_t fw_config;
- unsigned int bj;
-
- cbi_get_fw_config(&fw_config);
- bj = (fw_config & EC_CFG_BJ_POWER_MASK) >> EC_CFG_BJ_POWER_L;
- /* Out of range value defaults to 0 */
- if (bj >= ARRAY_SIZE(bj_power))
- bj = 0;
- return bj;
-}
-
#define ADP_DEBOUNCE_MS 1000 /* Debounce time for BJ plug/unplug */
/* Debounced connection state of the barrel jack */
static int8_t adp_connected = -1;
@@ -243,12 +214,8 @@ static void adp_connect_deferred(void)
/* Debounce */
if (connected == adp_connected)
return;
- if (connected) {
- unsigned int bj = ec_config_get_bj_power();
-
- pi.voltage = bj_power[bj].voltage;
- pi.current = bj_power[bj].current;
- }
+ if (connected)
+ ec_bj_power(&pi.voltage, &pi.current);
charge_manager_update_charge(CHARGE_SUPPLIER_DEDICATED,
DEDICATED_CHARGE_PORT, &pi);
adp_connected = connected;
diff --git a/board/brask/board.h b/board/brask/board.h
index ca794a6eb2..a19af9d0a3 100644
--- a/board/brask/board.h
+++ b/board/brask/board.h
@@ -200,16 +200,6 @@ enum mft_channel {
MFT_CH_COUNT
};
-/*
- * firmware config fields
- */
-/*
- * Barrel-jack power (4 bits).
- */
-#define EC_CFG_BJ_POWER_L 0
-#define EC_CFG_BJ_POWER_H 3
-#define EC_CFG_BJ_POWER_MASK GENMASK(EC_CFG_BJ_POWER_H, EC_CFG_BJ_POWER_L)
-
extern void adp_connect_interrupt(enum gpio_signal signal);
#endif /* !__ASSEMBLER__ */
diff --git a/board/brask/build.mk b/board/brask/build.mk
index 81ecfa4164..f92c283725 100644
--- a/board/brask/build.mk
+++ b/board/brask/build.mk
@@ -14,6 +14,7 @@ BASEBOARD:=brask
board-y=
board-y+=board.o
board-y+=fans.o
+board-y+=fw_config.o
board-y+=i2c.o
board-y+=led.o
board-y+=pwm.o
diff --git a/board/brask/fw_config.c b/board/brask/fw_config.c
new file mode 100644
index 0000000000..a5857ef48f
--- /dev/null
+++ b/board/brask/fw_config.c
@@ -0,0 +1,65 @@
+/* Copyright 2022 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.h"
+#include "common.h"
+#include "compile_time_macros.h"
+#include "console.h"
+#include "cros_board_info.h"
+#include "fw_config.h"
+
+#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args)
+
+static union brask_cbi_fw_config fw_config;
+BUILD_ASSERT(sizeof(fw_config) == sizeof(uint32_t));
+
+/*
+ * FW_CONFIG defaults for brask if the CBI.FW_CONFIG data is not
+ * initialized.
+ */
+static const union brask_cbi_fw_config fw_config_defaults = {
+ .audio = DB_NAU88L25B_I2S,
+ .bj_power = BJ_135W,
+};
+
+/*
+ * Barrel-jack power adapter ratings.
+ */
+static const struct {
+ int voltage;
+ int current;
+} bj_power[] = {
+ [BJ_135W] = { /* 0 - 135W (also default) */
+ .voltage = 19500,
+ .current = 6920
+ },
+ [BJ_230W] = { /* 1 - 230W */
+ .voltage = 19500,
+ .current = 11800
+ }
+};
+
+/****************************************************************************
+ * Brask FW_CONFIG access
+ */
+void board_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;
+ }
+}
+
+void ec_bj_power(uint32_t *voltage, uint32_t *current)
+{
+ unsigned int bj;
+
+ bj = fw_config.bj_power;
+ /* Out of range value defaults to 0 */
+ if (bj >= ARRAY_SIZE(bj_power))
+ bj = 0;
+ *voltage = bj_power[bj].voltage;
+ *current = bj_power[bj].current;
+}
diff --git a/board/brask/fw_config.h b/board/brask/fw_config.h
new file mode 100644
index 0000000000..5ddb3b02a1
--- /dev/null
+++ b/board/brask/fw_config.h
@@ -0,0 +1,47 @@
+/* Copyright 2022 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 __BOARD_BRASK_FW_CONFIG_H_
+#define __BOARD_BRASK_FW_CONFIG_H_
+
+#include <stdint.h>
+
+/****************************************************************************
+ * CBI FW_CONFIG layout for Brask board.
+ *
+ * Source of truth is the project/brask/brask/config.star configuration file.
+ */
+enum ec_cfg_audio_type {
+ DB_AUDIO_UNKNOWN = 0,
+ DB_NAU88L25B_I2S = 1
+};
+
+enum ec_cfg_bj_power {
+ BJ_135W = 0,
+ BJ_230W = 1
+};
+
+union brask_cbi_fw_config {
+ struct {
+ uint32_t audio : 3;
+ uint32_t bj_power : 2;
+ uint32_t reserved_1 : 27;
+ };
+ uint32_t raw_value;
+};
+
+/**
+ * Read the cached FW_CONFIG. Guaranteed to have valid values.
+ *
+ * @return the FW_CONFIG for the board.
+ */
+union brask_cbi_fw_config get_fw_config(void);
+
+/**
+ * Get the barrel-jack power from FW_CONFIG.
+ */
+void ec_bj_power(uint32_t *voltage, uint32_t *current);
+
+#endif /* __BOARD_BRASK_FW_CONFIG_H_ */