diff options
author | Dawid Niedzwiecki <dn@semihalf.com> | 2021-11-16 15:04:40 +0100 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-12-06 23:46:08 +0000 |
commit | 500068bff3ef725f2276a9c67b525d25df50f398 (patch) | |
tree | d50ea62986327734bbbf30a4d27775a8ed0b8a4f | |
parent | 4d368e0621d05ef2f539ad44eb136c135092bebf (diff) | |
download | chrome-ec-500068bff3ef725f2276a9c67b525d25df50f398.tar.gz |
zephyr: herbrine: move ppc replacement to a new file
Move replacement of alternate devices, ppc in this case, to a new
separate file. This will allow handling different chips based on
board versions, cbi fields, etc. in one place.
BUG=b:202451919
TEST=zmake testall & Make sure PD works on Herobrine on both ports
BRANCH=main
Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com>
Change-Id: I27fd01ee74523a18083f77a92c1051058cf7c814
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3289206
Commit-Queue: Keith Short <keithshort@chromium.org>
Reviewed-by: Keith Short <keithshort@chromium.org>
4 files changed, 38 insertions, 21 deletions
diff --git a/zephyr/projects/herobrine/herobrine_npcx9/CMakeLists.txt b/zephyr/projects/herobrine/herobrine_npcx9/CMakeLists.txt index dfccaf12c6..9b21ee77bd 100644 --- a/zephyr/projects/herobrine/herobrine_npcx9/CMakeLists.txt +++ b/zephyr/projects/herobrine/herobrine_npcx9/CMakeLists.txt @@ -17,3 +17,5 @@ zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_LED_COMMON "src/led.c") zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_I2C "src/i2c.c") +zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_USBC + "src/alt_dev_replacement.c") diff --git a/zephyr/projects/herobrine/herobrine_npcx9/src/alt_dev_replacement.c b/zephyr/projects/herobrine/herobrine_npcx9/src/alt_dev_replacement.c new file mode 100644 index 0000000000..fe3f06fca5 --- /dev/null +++ b/zephyr/projects/herobrine/herobrine_npcx9/src/alt_dev_replacement.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 <logging/log.h> +#include "usbc/ppc.h" +#include "hooks.h" +#include "cros_board_info.h" + +LOG_MODULE_REGISTER(alt_dev_replacement); + +#define BOARD_VERSION_UNKNOWN 0xffffffff + +/* Check board version to decide which ppc is used. */ +static bool board_has_syv_ppc(void) +{ + static uint32_t board_version = BOARD_VERSION_UNKNOWN; + + if (board_version == BOARD_VERSION_UNKNOWN) { + if (cbi_get_board_version(&board_version) != EC_SUCCESS) { + LOG_ERR("Failed to get board version."); + board_version = 0; + } + } + + return (board_version >= 1); +} + +static void check_alternate_devices(void) +{ + /* Configure the PPC driver */ + if (board_has_syv_ppc()) + PPC_ENABLE_ALTERNATE(ppc_port0_syv); +} +DECLARE_HOOK(HOOK_INIT, check_alternate_devices, HOOK_PRIO_DEFAULT); diff --git a/zephyr/projects/herobrine/herobrine_npcx9/src/usbc_config.c b/zephyr/projects/herobrine/herobrine_npcx9/src/usbc_config.c index 20536752f2..1bce0c51b3 100644 --- a/zephyr/projects/herobrine/herobrine_npcx9/src/usbc_config.c +++ b/zephyr/projects/herobrine/herobrine_npcx9/src/usbc_config.c @@ -62,23 +62,6 @@ void usba_oc_interrupt(enum gpio_signal signal) hook_call_deferred(&usba_oc_deferred_data, 0); } -#define BOARD_VERSION_UNKNOWN 0xffffffff - -/* Check board version to decide which ppc is used. */ -static bool board_has_syv_ppc(void) -{ - static uint32_t board_version = BOARD_VERSION_UNKNOWN; - - if (board_version == BOARD_VERSION_UNKNOWN) { - if (cbi_get_board_version(&board_version) != EC_SUCCESS) { - CPRINTS("Failed to get board version."); - board_version = 0; - } - } - - return (board_version >= 1); -} - void ppc_interrupt(enum gpio_signal signal) { switch (signal) { @@ -190,10 +173,6 @@ static void board_init_usbc(void) { /* Enable USB-A overcurrent interrupt */ gpio_enable_interrupt(GPIO_USB_A0_OC_ODL); - - /* Configure the PPC driver */ - if (board_has_syv_ppc()) - PPC_ENABLE_ALTERNATE(ppc_port0_syv); } DECLARE_HOOK(HOOK_INIT, board_init_usbc, HOOK_PRIO_DEFAULT); diff --git a/zephyr/shim/include/usbc/ppc.h b/zephyr/shim/include/usbc/ppc.h index a59436712b..65943a86da 100644 --- a/zephyr/shim/include/usbc/ppc.h +++ b/zephyr/shim/include/usbc/ppc.h @@ -10,6 +10,7 @@ #include <devicetree.h> #include "usbc/ppc_sn5s330.h" #include "usbc/ppc_syv682x.h" +#include "usbc_ppc.h" #define PPC_ID(id) DT_CAT(PPC_, id) #define PPC_ID_WITH_COMMA(id) PPC_ID(id), |