summaryrefslogtreecommitdiff
path: root/zephyr/shim/src/tcpc_nct38xx.c
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/shim/src/tcpc_nct38xx.c')
-rw-r--r--zephyr/shim/src/tcpc_nct38xx.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/zephyr/shim/src/tcpc_nct38xx.c b/zephyr/shim/src/tcpc_nct38xx.c
index f8c73d1aa0..9580759a6c 100644
--- a/zephyr/shim/src/tcpc_nct38xx.c
+++ b/zephyr/shim/src/tcpc_nct38xx.c
@@ -1,4 +1,4 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+/* 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.
*/
@@ -8,20 +8,27 @@
#include "config.h"
#include "usbc/tcpc_nct38xx.h"
-
-#define TCPC_PORT(id) DT_REG_ADDR(DT_PARENT(id))
+#include "usbc/utils.h"
#define GPIO_DEV_WITH_COMMA(id) DEVICE_DT_GET(DT_PHANDLE(id, gpio_dev)),
-#define GPIO_DEV_BINDING(id) \
- COND_CODE_1(DT_NODE_HAS_PROP(id, gpio_dev), \
- ([TCPC_PORT(id)] = GPIO_DEV_WITH_COMMA(id)), ())
+#define GPIO_DEV_BINDING(usbc_id, tcpc_id) \
+ COND_CODE_1(DT_NODE_HAS_PROP(tcpc_id, gpio_dev), \
+ ([USBC_PORT_NEW(usbc_id)] = GPIO_DEV_WITH_COMMA(tcpc_id)), \
+ ())
+
+#define NCT38XX_CHECK(usbc_id, tcpc_id) \
+ COND_CODE_1(DT_NODE_HAS_COMPAT(tcpc_id, nuvoton_nct38xx), \
+ (GPIO_DEV_BINDING(usbc_id, tcpc_id)), ())
+
+#define NCT38XX_GPIO(usbc_id) \
+ COND_CODE_1(DT_NODE_HAS_PROP(usbc_id, tcpc), \
+ (NCT38XX_CHECK(usbc_id, DT_PHANDLE(usbc_id, tcpc))), ())
/* NCT38XX GPIO device pool for binding the TCPC port and NCT38XX GPIO device */
-static const struct device
- *nct38xx_gpio_devices[CONFIG_USB_PD_PORT_MAX_COUNT] = {
- DT_FOREACH_STATUS_OKAY(nuvoton_nct38xx, GPIO_DEV_BINDING)
- };
+static const struct device *nct38xx_gpio_devices[CONFIG_USB_PD_PORT_MAX_COUNT] = {
+ DT_FOREACH_STATUS_OKAY(named_usbc_port, NCT38XX_GPIO)
+};
const struct device *nct38xx_get_gpio_device_from_port(const int port)
{