diff options
author | Wealian Liao <whliao@nuvoton.corp-partner.google.com> | 2021-11-03 17:24:40 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-12-02 18:48:57 +0000 |
commit | 87e264525163f00eb98ab89446d82e41d19e98de (patch) | |
tree | bda7b827720a45126489a3ae34aecb3468718bdc /driver | |
parent | 13434ee2724c1bd11a575bc6d06a163aba9d2d84 (diff) | |
download | chrome-ec-87e264525163f00eb98ab89446d82e41d19e98de.tar.gz |
zephyr: Shim nct38xx io expander alert
Zephyr upstream added NCT38XX GPIO support except for TCPC
functionality. The NCT38XX GPIO & TCPC share the same alert pin. The
alert should be handled at the same position.
This CL adds nct38xx_get_gpio_device_from_port() for Cros NCT38XX alert
handler. It can connect Cros TCPC alert & Zephyr NCT38XX GPIO alter
handler. So we can process the GPIO & TCPC alert at Cros task. The
following is the TCPC binding example:
usbc {
compatible = "named-usbc-ports";
#address-cells = <1>;
#size-cells = <0>;
port0: usbc-port@0 {
reg = <0>;
tcpc {
compatible = "nuvoton,nct38xx";
gpio-dev = <&nct3807_gpio>;
};
};
};
BUG=b:203672150
BRANCH=none
TEST=test GPIO interrupt on NCT38XX
Cq-Depend: chromium:3297249
Signed-off-by: Wealian Liao <whliao@nuvoton.corp-partner.google.com>
Change-Id: Iec355ccb581590d24cc9fcc809449b3654014a40
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3271801
Reviewed-by: Keith Short <keithshort@chromium.org>
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Commit-Queue: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r-- | driver/tcpm/nct38xx.c | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/driver/tcpm/nct38xx.c b/driver/tcpm/nct38xx.c index 00240516e5..0d45c8aa9f 100644 --- a/driver/tcpm/nct38xx.c +++ b/driver/tcpm/nct38xx.c @@ -14,6 +14,17 @@ #include "tcpm/tcpci.h" #include "usb_common.h" +#ifdef CONFIG_ZEPHYR +#include <device.h> +#include <drivers/gpio/gpio_nct38xx.h> +#include "usbc/tcpc_nct38xx.h" +#endif + +#if defined(CONFIG_ZEPHYR) && defined(CONFIG_IO_EXPANDER_NCT38XX) +#error CONFIG_IO_EXPANDER_NCT38XX cannot be used with Zephyr. +#error Enable the Zephyr driver CONFIG_GPIO_NCT38XX instead. +#endif + #if !defined(CONFIG_USB_PD_TCPM_TCPCI) #error "NCT38XX is using part of standard TCPCI control" #error "Please upgrade your board configuration" @@ -134,8 +145,19 @@ static int nct38xx_init(int port) * Enable the Vendor Define alert event only when the IO expander * feature is defined */ - if (IS_ENABLED(CONFIG_IO_EXPANDER_NCT38XX)) + if (IS_ENABLED(CONFIG_IO_EXPANDER_NCT38XX) || + IS_ENABLED(CONFIG_GPIO_NCT38XX)) { +#ifdef CONFIG_ZEPHYR + const struct device *dev = + nct38xx_get_gpio_device_from_port(port); + + if (!device_is_ready(dev)) { + CPRINTS("C%d: device is not ready", port); + return EC_ERROR_BUSY; + } +#endif /* CONFIG_ZEPHYR */ reg |= TCPC_REG_ALERT_VENDOR_DEF; + } rv = tcpc_update16(port, TCPC_REG_ALERT_MASK, @@ -244,6 +266,20 @@ __overridable int board_map_nct38xx_tcpc_port_to_ioex(int port) return port; } +static inline void nct38xx_tcpc_vendor_defined_alert(int port) +{ +#ifdef CONFIG_ZEPHYR + const struct device *dev = nct38xx_get_gpio_device_from_port(port); + + nct38xx_gpio_alert_handler(dev); +#else + int ioexport; + + ioexport = board_map_nct38xx_tcpc_port_to_ioex(port); + nct38xx_ioex_event_handler(ioexport); +#endif /* CONFIG_ZEPHYR */ +} + static void nct38xx_tcpc_alert(int port) { int alert, rv; @@ -274,12 +310,10 @@ static void nct38xx_tcpc_alert(int port) * tcpci_tcpc_alert(). Check the Vendor Defined Alert bit to * handle the IOEX IO's interrupt event. */ - if (IS_ENABLED(CONFIG_IO_EXPANDER_NCT38XX) && - rv == EC_SUCCESS && (alert & TCPC_REG_ALERT_VENDOR_DEF)) { - int ioexport; - - ioexport = board_map_nct38xx_tcpc_port_to_ioex(port); - nct38xx_ioex_event_handler(ioexport); + if ((IS_ENABLED(CONFIG_IO_EXPANDER_NCT38XX) || + IS_ENABLED(CONFIG_GPIO_NCT38XX)) && + rv == EC_SUCCESS && (alert & TCPC_REG_ALERT_VENDOR_DEF)) { + nct38xx_tcpc_vendor_defined_alert(port); } } |