diff options
author | Matt Wang <matt_wang@compal.corp-partner.google.com> | 2022-03-17 16:05:48 +0800 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-03-29 02:45:00 +0000 |
commit | e4cc9a89d063d295dad5d6caae5d251fe79073ef (patch) | |
tree | 2efd7b19b982c8f4041a3fe707529fa1eb446217 /board/kinox | |
parent | 4083e801c674a04309c1f6be0d2c21272208ea90 (diff) | |
download | chrome-ec-e4cc9a89d063d295dad5d6caae5d251fe79073ef.tar.gz |
kinox: separate fw_config from the board
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.
BUG=b:223380935
BRANCH=none
TEST=make BOARD=kinox pass
Signed-off-by: Matt Wang <matt_wang@compal.corp-partner.google.com>
Change-Id: I5e5ada0516d83fb00a2da14f9a4687183acc34ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3531869
Reviewed-by: Zhuohao Lee <zhuohao@chromium.org>
Diffstat (limited to 'board/kinox')
-rw-r--r-- | board/kinox/board.c | 39 | ||||
-rw-r--r-- | board/kinox/board.h | 10 | ||||
-rw-r--r-- | board/kinox/build.mk | 1 | ||||
-rw-r--r-- | board/kinox/fw_config.c | 65 | ||||
-rw-r--r-- | board/kinox/fw_config.h | 42 |
5 files changed, 111 insertions, 46 deletions
diff --git a/board/kinox/board.c b/board/kinox/board.c index 0349ea2cf3..3574784583 100644 --- a/board/kinox/board.c +++ b/board/kinox/board.c @@ -19,6 +19,7 @@ #include "switch.h" #include "throttle_ap.h" #include "usbc_config.h" +#include "fw_config.h" #include "gpio_list.h" /* Must come after other header files. */ @@ -116,36 +117,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, * 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; @@ -157,12 +128,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/kinox/board.h b/board/kinox/board.h index 9bc5af7abe..2c8bdcbfdc 100644 --- a/board/kinox/board.h +++ b/board/kinox/board.h @@ -199,16 +199,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/kinox/build.mk b/board/kinox/build.mk index 00fc2723cd..9c668e0e2a 100644 --- a/board/kinox/build.mk +++ b/board/kinox/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/kinox/fw_config.c b/board/kinox/fw_config.c new file mode 100644 index 0000000000..d4ae66ac17 --- /dev/null +++ b/board/kinox/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 kinox_cbi_fw_config fw_config; +BUILD_ASSERT(sizeof(fw_config) == sizeof(uint32_t)); + +/* + * FW_CONFIG defaults for kinox if the CBI.FW_CONFIG data is not + * initialized. + */ +static const union kinox_cbi_fw_config fw_config_defaults = { + .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 + } +}; + +/**************************************************************************** + * Kinox 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/kinox/fw_config.h b/board/kinox/fw_config.h new file mode 100644 index 0000000000..02e46e10b6 --- /dev/null +++ b/board/kinox/fw_config.h @@ -0,0 +1,42 @@ +/* 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_KINOX_FW_CONFIG_H_ +#define __BOARD_KINOX_FW_CONFIG_H_ + +#include <stdint.h> + +/**************************************************************************** + * CBI FW_CONFIG layout for kinox board. + * + * Source of truth is the project/brask/kinox/config.star configuration file. + */ + +enum ec_cfg_bj_power { + BJ_135W = 0, + BJ_230W = 1 +}; + +union kinox_cbi_fw_config { + struct { + uint32_t bj_power : 2; + uint32_t reserved_1 : 30; + }; + uint32_t raw_value; +}; + +/** + * Read the cached FW_CONFIG. Guaranteed to have valid values. + * + * @return the FW_CONFIG for the board. + */ +union kinox_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_KINOX_FW_CONFIG_H_ */ |