summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTing Shen <phoenixshen@google.com>2022-04-11 17:31:19 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-04-12 07:42:20 +0000
commitfe2fd964dfbe6ed8e1b39b268b8b0784adfa5310 (patch)
treece75673d4af2e58d009ac7583b24b88df48099db
parent14b984a74aa5c707bd303e553c9b65c78ed92bf7 (diff)
downloadchrome-ec-fe2fd964dfbe6ed8e1b39b268b8b0784adfa5310.tar.gz
zephyr: add util header to hold common device-tree ops
Move duplicated macros to a common header file. BUG=b:220814055 TEST=zmake build herobrine BRANCH=none Signed-off-by: Ting Shen <phoenixshen@google.com> Change-Id: I437449592edd994b060908dacde1422a549565ec Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3580112 Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Ting Shen <phoenixshen@chromium.org> Tested-by: Ting Shen <phoenixshen@chromium.org>
-rw-r--r--zephyr/shim/include/usbc/ppc.h4
-rw-r--r--zephyr/shim/include/usbc/utils.h28
-rw-r--r--zephyr/shim/src/bc12.c3
-rw-r--r--zephyr/shim/src/bc12_pi3usb9201.c7
-rw-r--r--zephyr/shim/src/ppc.c2
-rw-r--r--zephyr/shim/src/tcpc.c3
6 files changed, 34 insertions, 13 deletions
diff --git a/zephyr/shim/include/usbc/ppc.h b/zephyr/shim/include/usbc/ppc.h
index cc989d7816..00c7c36c41 100644
--- a/zephyr/shim/include/usbc/ppc.h
+++ b/zephyr/shim/include/usbc/ppc.h
@@ -11,12 +11,12 @@
#include "usbc/ppc_rt1739.h"
#include "usbc/ppc_sn5s330.h"
#include "usbc/ppc_syv682x.h"
+#include "usbc/utils.h"
#include "usbc_ppc.h"
#define PPC_ID(id) DT_CAT(PPC_, id)
#define PPC_ID_WITH_COMMA(id) PPC_ID(id),
-#define PPC_USBC_PORT(id) DT_REG_ADDR(DT_PARENT(id))
-#define PPC_ALT_FOR(alt_id) PPC_USBC_PORT(DT_PHANDLE(alt_id, alternate_for))
+#define PPC_ALT_FOR(alt_id) USBC_PORT(DT_PHANDLE(alt_id, alternate_for))
#define PPC_ALT_ENUM(id) \
COND_CODE_1(DT_NODE_HAS_PROP(id, alternate_for), \
diff --git a/zephyr/shim/include/usbc/utils.h b/zephyr/shim/include/usbc/utils.h
new file mode 100644
index 0000000000..a2ad495ea9
--- /dev/null
+++ b/zephyr/shim/include/usbc/utils.h
@@ -0,0 +1,28 @@
+/* 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 __CROS_EC_ZEPHYR_SHIM_USBC_UTIL
+
+
+/*
+ * Enable interrupt from the `irq` property of an instance's node.
+ *
+ * @param inst: instance number
+ */
+#define BC12_GPIO_ENABLE_INTERRUPT(inst) \
+ IF_ENABLED(DT_INST_NODE_HAS_PROP(inst, irq), \
+ (gpio_enable_dt_interrupt( \
+ GPIO_INT_FROM_NODE(DT_INST_PHANDLE(inst, irq)));\
+ ) \
+ )
+
+/*
+ * Get the port number from a child of `named-usbc-port` node.
+ *
+ * @param id: node id
+ */
+#define USBC_PORT(id) DT_REG_ADDR(DT_PARENT(id))
+
+#endif /* __CROS_EC_ZEPHYR_SHIM_USBC_UTIL */
diff --git a/zephyr/shim/src/bc12.c b/zephyr/shim/src/bc12.c
index 408458365f..fc6dfb6aa9 100644
--- a/zephyr/shim/src/bc12.c
+++ b/zephyr/shim/src/bc12.c
@@ -7,14 +7,13 @@
#include "usbc/bc12_pi3usb9201.h"
#include "usbc/bc12_rt1739.h"
#include "usbc/bc12_rt9490.h"
+#include "usbc/utils.h"
#include "usb_charge.h"
#if DT_HAS_COMPAT_STATUS_OKAY(RT1739_BC12_COMPAT) || \
DT_HAS_COMPAT_STATUS_OKAY(RT9490_BC12_COMPAT) || \
DT_HAS_COMPAT_STATUS_OKAY(PI3USB9201_COMPAT)
-#define USBC_PORT(id) DT_REG_ADDR(DT_PARENT(id))
-
#define BC12_CHIP(id, fn) [USBC_PORT(id)] = fn(id)
/* Power Path Controller */
diff --git a/zephyr/shim/src/bc12_pi3usb9201.c b/zephyr/shim/src/bc12_pi3usb9201.c
index 49e6902e74..57e4ed7b61 100644
--- a/zephyr/shim/src/bc12_pi3usb9201.c
+++ b/zephyr/shim/src/bc12_pi3usb9201.c
@@ -12,6 +12,7 @@
#include "task.h"
#include "usb_charge.h"
#include "usb_pd.h"
+#include "usbc/utils.h"
#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT)
@@ -30,12 +31,6 @@ const struct pi3usb9201_config_t pi3usb9201_bc12_chips[] = {
DT_INST_FOREACH_STATUS_OKAY(USBC_PORT_BC12)
};
-#define BC12_GPIO_ENABLE_INTERRUPT(inst) \
- IF_ENABLED(DT_INST_NODE_HAS_PROP(inst, irq), \
- (gpio_enable_dt_interrupt( \
- GPIO_INT_FROM_NODE(DT_INST_PHANDLE(inst, irq)))) \
- );
-
static void bc12_enable_irqs(void)
{
DT_INST_FOREACH_STATUS_OKAY(BC12_GPIO_ENABLE_INTERRUPT)
diff --git a/zephyr/shim/src/ppc.c b/zephyr/shim/src/ppc.c
index b8c50f7a24..a77f7aa656 100644
--- a/zephyr/shim/src/ppc.c
+++ b/zephyr/shim/src/ppc.c
@@ -22,7 +22,7 @@
COND_CODE_1(DT_NODE_HAS_PROP(id, alternate_for), \
(PPC_CHIP_ELE_ALT(id, fn)), ())
-#define PPC_CHIP_ELE_PRIM(id, fn) [PPC_USBC_PORT(id)] = fn(id)
+#define PPC_CHIP_ELE_PRIM(id, fn) [USBC_PORT(id)] = fn(id)
#define PPC_CHIP_ELE_ALT(id, fn) [PPC_ID(id)] = fn(id)
diff --git a/zephyr/shim/src/tcpc.c b/zephyr/shim/src/tcpc.c
index 98f631757c..82f53d70d9 100644
--- a/zephyr/shim/src/tcpc.c
+++ b/zephyr/shim/src/tcpc.c
@@ -11,14 +11,13 @@
#include "usbc/tcpc_it8xxx2.h"
#include "usbc/tcpc_ps8xxx.h"
#include "usbc/tcpci.h"
+#include "usbc/utils.h"
#if DT_HAS_COMPAT_STATUS_OKAY(FUSB302_TCPC_COMPAT) || \
DT_HAS_COMPAT_STATUS_OKAY(IT8XXX2_TCPC_COMPAT) || \
DT_HAS_COMPAT_STATUS_OKAY(PS8XXX_COMPAT) || \
DT_HAS_COMPAT_STATUS_OKAY(TCPCI_COMPAT) \
-#define USBC_PORT(id) DT_REG_ADDR(DT_PARENT(id))
-
#define TCPC_CONFIG(id, fn) [USBC_PORT(id)] = fn(id)
#define MAYBE_CONST COND_CODE_1(CONFIG_PLATFORM_EC_USB_PD_TCPC_RUNTIME_CONFIG, \