summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Short <keithshort@chromium.org>2023-03-20 09:12:27 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-03-22 16:45:27 +0000
commite4e7230d276a1a4dc76a8e827aa3b33e8e479f0d (patch)
tree8c3a7ebd5f02b8f648da47833c9c753e81f139f8
parent75ae0c48d943632741171fcda3d0a1860ab342a2 (diff)
downloadchrome-ec-e4e7230d276a1a4dc76a8e827aa3b33e8e479f0d.tar.gz
zephyr: ppc: Add support for multiple altnernates
Add support for multiple PPC altnernate on each USB-C port. PPC chips that are candidates for runtime selection must add the "is-alt" property to the PPC definition. ppc_port0_alt: sn5s330@40 { compatible = "ti,sn5s330"; status = "okay"; reg = <0x40>; is-alt; }; The board specific code then calls PPC_ENABLE_ALTERNATE_BY_NODELABEL, specifying both the USB-C port to update, and the nodelabel of the new PPC device. PPC_ENABLE_ALTERNATE_BY_NODELABEL(0, ppc_nx20p348x_alt); BUG=b:274126703 BRANCH=none TEST=./twister -s drivers/drivers.usbc_ppc Change-Id: I8fff03beac8dbb98fea5b574e2ad456721cefe98 Signed-off-by: Keith Short <keithshort@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4354880 Tested-by: Madhu 🌱 <mparuchuri@google.com> Reviewed-by: Fabio Baltieri <fabiobaltieri@google.com>
-rw-r--r--zephyr/dts/bindings/usbc/ppc-chip.yaml7
-rw-r--r--zephyr/shim/include/usbc/ppc.h56
-rw-r--r--zephyr/shim/src/ppc.c22
-rw-r--r--zephyr/test/drivers/boards/native_posix.overlay4
-rw-r--r--zephyr/test/drivers/testcase.yaml3
-rw-r--r--zephyr/test/drivers/usbc_ppc/CMakeLists.txt5
-rw-r--r--zephyr/test/drivers/usbc_ppc/ppc_alts.dts47
-rw-r--r--zephyr/test/drivers/usbc_ppc/src/ppc_shim.c60
8 files changed, 201 insertions, 3 deletions
diff --git a/zephyr/dts/bindings/usbc/ppc-chip.yaml b/zephyr/dts/bindings/usbc/ppc-chip.yaml
index 6829a98dc5..30f71c9d1a 100644
--- a/zephyr/dts/bindings/usbc/ppc-chip.yaml
+++ b/zephyr/dts/bindings/usbc/ppc-chip.yaml
@@ -10,3 +10,10 @@ properties:
required: false
description: |
GPIO interrupt from PPC
+
+ is-alt:
+ type: boolean
+ required: false
+ description: |
+ If present, this node refers to an altnerate PPC device. The PPC device
+ is not used by default, and must be manually enabled at runtime.
diff --git a/zephyr/shim/include/usbc/ppc.h b/zephyr/shim/include/usbc/ppc.h
index fa38145f66..98e9c3f728 100644
--- a/zephyr/shim/include/usbc/ppc.h
+++ b/zephyr/shim/include/usbc/ppc.h
@@ -6,6 +6,7 @@
#ifndef ZEPHYR_CHROME_USBC_PPC_H
#define ZEPHYR_CHROME_USBC_PPC_H
+#include "usbc/ppc_aoz1380.h"
#include "usbc/ppc_nx20p348x.h"
#include "usbc/ppc_rt1739.h"
#include "usbc/ppc_sn5s330.h"
@@ -16,6 +17,57 @@
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
+/**
+ * @brief Create a unique name based on a PPC altnernate node.
+ *
+ * ppc_syv682x_alt: syv682x@43 {
+ * compatible = "silergy,syv682x";
+ * status = "okay";
+ * reg = <0x43>;
+ * frs_en_gpio = <&ioex_usb_c0_frs_en>;
+ * is-alt;
+ * };
+ *
+ * Usage:
+ * PPC_ALT_NAME_GET(DT_NODELABEL(ppc_syv682x_alt))
+ *
+ * expands to "ppc_alt_DT_N_S_i2c_100_S_syv682x_43"
+ */
+#define PPC_ALT_NAME_GET(node_id) DT_CAT(ppc_alt_, node_id)
+
+/**
+ * @brief Get the PPC alternate entry based on a nodelabel.
+ *
+ * Usage:
+ * PPC_ALT_FROM_NODELABEL(ppc_syv682x_alt))
+ *
+ * expands to "ppc_alt_DT_N_S_i2c_100_S_syv682x_43"
+ */
+#define PPC_ALT_FROM_NODELABEL(lbl) (PPC_ALT_NAME_GET(DT_NODELABEL(lbl)))
+
+/**
+ * @brief - Forward declare a global struct ppc_config_t entry based on
+ * a single PPC altnerate from the devicetree.
+ */
+#define PPC_ALT_DECLARATION(node_id) \
+ extern const struct ppc_config_t PPC_ALT_NAME_GET(node_id)
+
+#define PPC_ALT_DECLARE(node_id) \
+ COND_CODE_1(DT_PROP_OR(node_id, is_alt, 0), \
+ (PPC_ALT_DECLARATION(node_id);), ())
+
+/*
+ * Forward declare a struct ppc_config_t for every PPC node in the tree with the
+ * "is-alt" property set.
+ */
+DT_FOREACH_STATUS_OKAY(AOZ1380_COMPAT, PPC_ALT_DECLARE)
+DT_FOREACH_STATUS_OKAY(NX20P348X_COMPAT, PPC_ALT_DECLARE)
+DT_FOREACH_STATUS_OKAY(RT1739_PPC_COMPAT, PPC_ALT_DECLARE)
+DT_FOREACH_STATUS_OKAY(SN5S330_COMPAT, PPC_ALT_DECLARE)
+DT_FOREACH_STATUS_OKAY(SN5S330_EMUL_COMPAT, PPC_ALT_DECLARE)
+DT_FOREACH_STATUS_OKAY(SYV682X_COMPAT, PPC_ALT_DECLARE)
+DT_FOREACH_STATUS_OKAY(SYV682X_EMUL_COMPAT, PPC_ALT_DECLARE)
+
extern struct ppc_config_t ppc_chips_alt[];
#define ALT_PPC_CHIP_CHK(usbc_id, usb_port_num) \
@@ -36,4 +88,8 @@ extern struct ppc_config_t ppc_chips_alt[];
sizeof(struct ppc_config_t)); \
} while (0)
+#define PPC_ENABLE_ALTERNATE_BY_NODELABEL(usb_port_num, nodelabel) \
+ memcpy(&ppc_chips[usb_port_num], &PPC_ALT_FROM_NODELABEL(nodelabel), \
+ sizeof(struct ppc_config_t))
+
#endif /* ZEPHYR_CHROME_USBC_PPC_H */
diff --git a/zephyr/shim/src/ppc.c b/zephyr/shim/src/ppc.c
index f86640540d..c25daf5392 100644
--- a/zephyr/shim/src/ppc.c
+++ b/zephyr/shim/src/ppc.c
@@ -54,4 +54,26 @@ unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips);
struct ppc_config_t ppc_chips_alt[] = { DT_FOREACH_STATUS_OKAY(named_usbc_port,
PPC_CHIP_ALT) };
+#define PPC_ALT_DEFINITION(node_id, config_fn) \
+ const struct ppc_config_t PPC_ALT_NAME_GET(node_id) = config_fn(node_id)
+
+#define PPC_ALT_DEFINE(node_id, config_fn) \
+ COND_CODE_1(DT_PROP_OR(node_id, is_alt, 0), \
+ (PPC_ALT_DEFINITION(node_id, config_fn);), ())
+
+/*
+ * Define a global struct ppc_config_t for every PPC node in the tree with the
+ * "is-alt" property set.
+ */
+DT_FOREACH_STATUS_OKAY_VARGS(AOZ1380_COMPAT, PPC_ALT_DEFINE, PPC_CHIP_AOZ1380)
+DT_FOREACH_STATUS_OKAY_VARGS(NX20P348X_COMPAT, PPC_ALT_DEFINE,
+ PPC_CHIP_NX20P348X)
+DT_FOREACH_STATUS_OKAY_VARGS(RT1739_PPC_COMPAT, PPC_ALT_DEFINE, PPC_CHIP_RT1739)
+DT_FOREACH_STATUS_OKAY_VARGS(SN5S330_COMPAT, PPC_ALT_DEFINE, PPC_CHIP_SN5S330)
+DT_FOREACH_STATUS_OKAY_VARGS(SN5S330_EMUL_COMPAT, PPC_ALT_DEFINE,
+ PPC_CHIP_SN5S330)
+DT_FOREACH_STATUS_OKAY_VARGS(SYV682X_COMPAT, PPC_ALT_DEFINE, PPC_CHIP_SYV682X)
+DT_FOREACH_STATUS_OKAY_VARGS(SYV682X_EMUL_COMPAT, PPC_ALT_DEFINE,
+ PPC_CHIP_SYV682X)
+
#endif /* #if DT_HAS_COMPAT_STATUS_OKAY */
diff --git a/zephyr/test/drivers/boards/native_posix.overlay b/zephyr/test/drivers/boards/native_posix.overlay
index ffd164ebe8..2ed86cd9c4 100644
--- a/zephyr/test/drivers/boards/native_posix.overlay
+++ b/zephyr/test/drivers/boards/native_posix.overlay
@@ -124,8 +124,8 @@
* unless the output gpio is also configured as an input gpio.
*
* One may also configure the gpio as an input in the test
- * itself instead of device tree.
- * /
+ * itself instead of device tree.
+ */
/* <&gpio0 1 x> is reserved as 'entering-rw' in
* src/platform/ec/zephyr/dts/board-overlays/native_posix.dts
diff --git a/zephyr/test/drivers/testcase.yaml b/zephyr/test/drivers/testcase.yaml
index 7f1d71fca2..b41629005b 100644
--- a/zephyr/test/drivers/testcase.yaml
+++ b/zephyr/test/drivers/testcase.yaml
@@ -318,8 +318,11 @@ tests:
extra_configs:
- CONFIG_LINK_TEST_SUITE_USBC_OCP=y
drivers.usbc_ppc:
+ extra_args: >
+ DTC_OVERLAY_FILE="default/boards/native_posix.overlay;./usbc_ppc/ppc_alts.dts"
extra_configs:
- CONFIG_LINK_TEST_SUITE_USBC_PPC=y
+ - CONFIG_PLATFORM_EC_BC12_SINGLE_DRIVER=n
drivers.usbc_retimer.anx7483:
extra_configs:
- CONFIG_LINK_TEST_SUITE_USBC_RETIMER_ANX7483=y
diff --git a/zephyr/test/drivers/usbc_ppc/CMakeLists.txt b/zephyr/test/drivers/usbc_ppc/CMakeLists.txt
index 01d280c3ad..47102a0628 100644
--- a/zephyr/test/drivers/usbc_ppc/CMakeLists.txt
+++ b/zephyr/test/drivers/usbc_ppc/CMakeLists.txt
@@ -3,4 +3,7 @@
# found in the LICENSE file.
# Add source files
-target_sources(app PRIVATE src/usbc_ppc.c)
+target_sources(app PRIVATE
+ src/usbc_ppc.c
+ src/ppc_shim.c
+) \ No newline at end of file
diff --git a/zephyr/test/drivers/usbc_ppc/ppc_alts.dts b/zephyr/test/drivers/usbc_ppc/ppc_alts.dts
new file mode 100644
index 0000000000..09488dc91e
--- /dev/null
+++ b/zephyr/test/drivers/usbc_ppc/ppc_alts.dts
@@ -0,0 +1,47 @@
+/* Copyright 2021 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+ /* Defint nodes with the "is-alt" property set. Used by the PPC shim
+ * test to validate the runtime replacement of the PPC driver.
+ */
+
+/ {
+ ppc_aoz1380_alt: ppc-aoz1380-alt{
+ compatible = "aoz,aoz1380";
+ status = "okay";
+ is-alt;
+ };
+};
+
+&i2c0 {
+ ppc_nx20p348x_alt: nx20p348x@77 {
+ compatible = "nxp,nx20p348x", "cros,i2c-mock";
+ status = "okay";
+ reg = <0x77>;
+ is-alt;
+ };
+
+ ppc_rt1739_alt: rt1739@70 {
+ compatible = "richtek,rt1739-ppc", "cros,i2c-mock";
+ status = "okay";
+ reg = <0x70>;
+ is-alt;
+ };
+
+ ppc_syv682x_alt: syv682x@43 {
+ compatible = "silergy,syv682x", "cros,i2c-mock";
+ status = "okay";
+ reg = <0x43>;
+ frs_en_gpio = <&gpio_usb_c1_frs_en>;
+ is-alt;
+ };
+
+ ppc_sn5s330_alt: sn5s330@49 {
+ compatible = "ti,sn5s330", "cros,i2c-mock";
+ status = "okay";
+ reg = <0x49>;
+ is-alt;
+ };
+};
diff --git a/zephyr/test/drivers/usbc_ppc/src/ppc_shim.c b/zephyr/test/drivers/usbc_ppc/src/ppc_shim.c
new file mode 100644
index 0000000000..9625a783f9
--- /dev/null
+++ b/zephyr/test/drivers/usbc_ppc/src/ppc_shim.c
@@ -0,0 +1,60 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "usbc/ppc.h"
+
+#include <zephyr/logging/log.h>
+#include <zephyr/ztest.h>
+
+LOG_MODULE_REGISTER(test_drivers_ppc, LOG_LEVEL_DBG);
+
+#define PPC_CHIP_STUB(node_id) {},
+
+static struct ppc_config_t ppc_chips_saved[] = { DT_FOREACH_STATUS_OKAY(
+ named_usbc_port, PPC_CHIP_STUB) };
+
+ZTEST(ppc_shim, test_ppc_alts_exist)
+{
+ /* Verify all PPC types are able to create an alternate PPC entry */
+ zassert_not_null(&PPC_ALT_FROM_NODELABEL(ppc_aoz1380_alt));
+ zassert_not_null(&PPC_ALT_FROM_NODELABEL(ppc_nx20p348x_alt));
+ zassert_not_null(&PPC_ALT_FROM_NODELABEL(ppc_rt1739_alt));
+ zassert_not_null(&PPC_ALT_FROM_NODELABEL(ppc_syv682x_alt));
+ zassert_not_null(&PPC_ALT_FROM_NODELABEL(ppc_sn5s330_alt));
+}
+
+ZTEST(ppc_shim, test_ppc_alt_enable)
+{
+ /* Enable an alternate PPC on each USB-C port */
+ PPC_ENABLE_ALTERNATE_BY_NODELABEL(0, ppc_syv682x_alt);
+ PPC_ENABLE_ALTERNATE_BY_NODELABEL(1, ppc_rt1739_alt);
+
+ zassert_mem_equal(&ppc_chips[0],
+ &PPC_ALT_FROM_NODELABEL(ppc_syv682x_alt),
+ sizeof(struct ppc_config_t));
+ zassert_mem_equal(&ppc_chips[1],
+ &PPC_ALT_FROM_NODELABEL(ppc_rt1739_alt),
+ sizeof(struct ppc_config_t));
+
+ PPC_ENABLE_ALTERNATE_BY_NODELABEL(0, ppc_nx20p348x_alt);
+ zassert_mem_equal(&ppc_chips[0],
+ &PPC_ALT_FROM_NODELABEL(ppc_nx20p348x_alt),
+ sizeof(struct ppc_config_t));
+}
+
+void ppc_shim_before_test(void *data)
+{
+ memcpy(ppc_chips_saved, ppc_chips,
+ sizeof(struct ppc_config_t) * ARRAY_SIZE(ppc_chips_saved));
+}
+
+void ppc_shim_after_test(void *data)
+{
+ memcpy(ppc_chips, ppc_chips_saved,
+ sizeof(struct ppc_config_t) * ARRAY_SIZE(ppc_chips_saved));
+}
+
+ZTEST_SUITE(ppc_shim, NULL, NULL, ppc_shim_before_test, ppc_shim_after_test,
+ NULL);