summaryrefslogtreecommitdiff
path: root/zephyr/shim/src
diff options
context:
space:
mode:
authorJason Yuan <jasonyuan@google.com>2023-02-15 15:56:56 -0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-03-24 21:50:09 +0000
commit38f07aec87e712f99393ebcfc362e56501027be0 (patch)
tree5d4aebfd2f54686b1bbd456fbac3e3c509aa7d23 /zephyr/shim/src
parent4ac59af42a864d29e5172426c1b533973e0d14ee (diff)
downloadchrome-ec-38f07aec87e712f99393ebcfc362e56501027be0.tar.gz
zephyr: move tcpc_get_alert_status to shim
tcpc_get_alert_status is similar between multiple different projects. They have been now merged into common code. BUG=b:254148652 TEST=twister, usbc charging on villager, lazor BRANCH=none LOW_COVERAGE_REASON=the change from hardcoding to rst-gpios in board specific code is uncovered. The common code is 100% covered. This CL increases the absolute coverage. Change-Id: I3136bd5b600dbb385547e06490dcbf8815b85b85 Signed-off-by: Jason Yuan <jasonyuan@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4257651 Commit-Queue: zhi cheng yuan <jasonyuan@chromium.org> Auto-Submit: zhi cheng yuan <jasonyuan@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org> Tested-by: zhi cheng yuan <jasonyuan@chromium.org>
Diffstat (limited to 'zephyr/shim/src')
-rw-r--r--zephyr/shim/src/tcpc.c39
1 files changed, 32 insertions, 7 deletions
diff --git a/zephyr/shim/src/tcpc.c b/zephyr/shim/src/tcpc.c
index 1deb808505..bea9f80cb8 100644
--- a/zephyr/shim/src/tcpc.c
+++ b/zephyr/shim/src/tcpc.c
@@ -85,6 +85,36 @@ MAYBE_CONST struct tcpc_config_t tcpc_config[] = { DT_FOREACH_STATUS_OKAY(
BUILD_ASSERT(ARRAY_SIZE(tcpc_config) == CONFIG_USB_PD_PORT_MAX_COUNT);
+uint16_t tcpc_get_alert_status(void)
+{
+ uint16_t status = 0;
+ uint16_t alert_mask[] = { PD_STATUS_TCPC_ALERT_0,
+ PD_STATUS_TCPC_ALERT_1,
+ PD_STATUS_TCPC_ALERT_2,
+ PD_STATUS_TCPC_ALERT_3 };
+
+ /*
+ * Check which port has the ALERT line set and ignore if that TCPC has
+ * its reset line active.
+ */
+ for (int i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++) {
+ /*
+ * if the interrupt port exists and the interrupt is active
+ */
+ if (tcpc_config[i].irq_gpio.port &&
+ gpio_pin_get_dt(&tcpc_config[i].irq_gpio))
+ /*
+ * if the reset line does not exist or exists but is
+ * not active.
+ */
+ if (!tcpc_config[i].rst_gpio.port ||
+ !gpio_pin_get_dt(&tcpc_config[i].rst_gpio))
+ status |= alert_mask[i];
+ }
+
+ return status;
+}
+
struct gpio_callback int_gpio_cb[CONFIG_USB_PD_PORT_MAX_COUNT];
static void tcpc_int_gpio_callback(const struct device *dev,
@@ -107,8 +137,6 @@ static void tcpc_int_gpio_callback(const struct device *dev,
*/
void tcpc_enable_interrupt(void)
{
- gpio_flags_t flags;
-
for (int i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++) {
/*
* Check whether the interrupt pin has been configured
@@ -139,12 +167,9 @@ void tcpc_enable_interrupt(void)
gpio_add_callback(tcpc_config[i].irq_gpio.port,
&int_gpio_cb[i]);
}
- flags = tcpc_config[i].flags & TCPC_FLAGS_ALERT_ACTIVE_HIGH ?
- GPIO_INT_EDGE_RISING :
- GPIO_INT_EDGE_FALLING;
- flags = (flags | GPIO_INT_ENABLE) & ~GPIO_INT_DISABLE;
+
gpio_pin_interrupt_configure_dt(&tcpc_config[i].irq_gpio,
- flags);
+ GPIO_INT_EDGE_TO_ACTIVE);
}
}
/*