summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2021-10-21 22:55:24 +0000
committerCommit Bot <commit-bot@chromium.org>2021-10-27 21:28:06 +0000
commitec524d7ca0af4bfd7f851cf244bd992c50013499 (patch)
tree5c5247f07750dd88d7c86c809ed5f50b5016d7d8
parent072f84102c198c9c86af673e4171060311825f27 (diff)
downloadchrome-ec-ec524d7ca0af4bfd7f851cf244bd992c50013499.tar.gz
board/metaknight: Fix compilation error when using clang
clang warns: board/metaknight/board.c:787:10: error: array index 1 is past the end of the array (which contains 1 element) [-Werror,-Warray-bounds] if (!(tcpc_config[1].flags & TCPC_FLAGS_TCPCI_REV2_0)) ^ ~ board/metaknight/board.c:741:1: note: array 'tcpc_config' declared here const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = { ^ BRANCH=none BUG=b:172020503 TEST=CC=clang make BOARD=metaknight Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I510d6ec4343f258d734834f2d1e3b6760fca7761 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3238248 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r--board/metaknight/board.c38
-rw-r--r--include/usb_pd_tcpm.h1
2 files changed, 15 insertions, 24 deletions
diff --git a/board/metaknight/board.c b/board/metaknight/board.c
index 76a962e085..9b583503fe 100644
--- a/board/metaknight/board.c
+++ b/board/metaknight/board.c
@@ -737,6 +737,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = {
},
.flags = TCPC_FLAGS_TCPCI_REV2_0,
.drv = &raa489000_tcpm_drv,
+ .alert_signal = GPIO_USB_C0_INT_ODL,
},
};
@@ -753,33 +754,22 @@ uint16_t tcpc_get_alert_status(void)
{
uint16_t status = 0;
int regval;
+ int p;
/*
- * The interrupt line is shared between the TCPC and BC1.2 detector IC.
- * Therefore, go out and actually read the alert registers to report the
- * alert status.
+ * The interrupt line is shared between the TCPC and BC1.2
+ * detector IC. Therefore, go out and actually read the alert
+ * registers to report the alert status.
*/
- if (!gpio_get_level(GPIO_USB_C0_INT_ODL)) {
- if (!tcpc_read16(0, TCPC_REG_ALERT, &regval)) {
- /* The TCPCI Rev 1.0 spec says to ignore bits 14:12. */
- if (!(tcpc_config[0].flags & TCPC_FLAGS_TCPCI_REV2_0))
- regval &= ~((1 << 14) | (1 << 13) | (1 << 12));
-
- if (regval)
- status |= PD_STATUS_TCPC_ALERT_0;
- }
- }
-
- if (board_get_usb_pd_port_count() > 1 &&
- !gpio_get_level(GPIO_SUB_C1_INT_EN_RAILS_ODL)) {
- if (!tcpc_read16(1, TCPC_REG_ALERT, &regval)) {
- /* TCPCI spec Rev 1.0 says to ignore bits 14:12. */
- if (!(tcpc_config[1].flags & TCPC_FLAGS_TCPCI_REV2_0))
- regval &= ~((1 << 14) | (1 << 13) | (1 << 12));
-
- if (regval)
- status |= PD_STATUS_TCPC_ALERT_1;
- }
+ for (p = 0; p < board_get_usb_pd_port_count(); p++) {
+ if (gpio_get_level(tcpc_config[p].alert_signal) ||
+ tcpc_read16(p, TCPC_REG_ALERT, &regval))
+ continue;
+ /* The TCPCI Rev 1.0 spec says to ignore bits 14:12. */
+ if (!(tcpc_config[p].flags & TCPC_FLAGS_TCPCI_REV2_0))
+ regval &= ~(BIT(14) | BIT(13) | BIT(12));
+ if (regval)
+ status |= (PD_STATUS_TCPC_ALERT_0 << p);
}
return status;
diff --git a/include/usb_pd_tcpm.h b/include/usb_pd_tcpm.h
index 08c332efa2..6fe8336123 100644
--- a/include/usb_pd_tcpm.h
+++ b/include/usb_pd_tcpm.h
@@ -503,6 +503,7 @@ struct tcpc_config_t {
const struct tcpm_drv *drv;
/* See TCPC_FLAGS_* above */
uint32_t flags;
+ enum gpio_signal alert_signal;
};
#ifndef CONFIG_USB_PD_TCPC_RUNTIME_CONFIG