From a3f90cf79e0f06fa186e3afa28b542b0bc7b351d Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Fri, 14 Apr 2023 13:37:13 -0700 Subject: ANX7406: Add API to control GPIO0 This CL adds an API which controls GPIO0 of ANX7406. BUG=b:269790564 BRANCH=None TEST=make BOARD=hades Signed-off-by: Daisuke Nojiri Change-Id: I1e2ebda63fa49aec88d703f31f7bb70730939b63 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4426802 Reviewed-by: Peter Marheine --- driver/tcpm/anx7406.c | 15 +++++++++++++++ driver/tcpm/anx7406.h | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/driver/tcpm/anx7406.c b/driver/tcpm/anx7406.c index 1e3d2285cf..52f73a9c2f 100644 --- a/driver/tcpm/anx7406.c +++ b/driver/tcpm/anx7406.c @@ -31,6 +31,21 @@ const struct anx7406_i2c_addr anx7406_i2c_addrs_flags[] = { static struct anx7406_i2c_addr i2c_peripheral[CONFIG_USB_PD_PORT_MAX_COUNT]; +enum ec_error_list anx7406_set_gpio(int port, uint8_t gpio, bool value) +{ + if (gpio != 0) { + CPRINTS("C%d: Setting GPIO%d not supported", port, gpio); + return EC_ERROR_INVAL; + } + + CPRINTS("C%d: Setting GPIO%u %s", port, gpio, value ? "high" : "low"); + + return i2c_write8(tcpc_config[port].i2c_info.port, + i2c_peripheral[port].top_addr_flags, + ANX7406_REG_GPIO0, + value ? GPIO0_OUTPUT_HIGH : GPIO0_OUTPUT_LOW); +} + static int anx7406_set_hpd(int port, int hpd_lvl) { int val; diff --git a/driver/tcpm/anx7406.h b/driver/tcpm/anx7406.h index 83651b9573..b32a657da9 100644 --- a/driver/tcpm/anx7406.h +++ b/driver/tcpm/anx7406.h @@ -6,6 +6,7 @@ #ifndef __CROS_EC_USB_PD_TCPM_ANX7406_H #define __CROS_EC_USB_PD_TCPM_ANX7406_H +#include "stdbool.h" #include "usb_mux.h" struct anx7406_i2c_addr { @@ -68,6 +69,10 @@ struct anx7406_i2c_addr { #define ANX7406_REG_HPD_OEN BIT(6) #define HPD_DEGLITCH_TIME 0x0D +#define ANX7406_REG_GPIO0 0xCA +#define GPIO0_OUTPUT_HIGH (BIT(0) | BIT(1)) +#define GPIO0_OUTPUT_LOW BIT(0) + #define EXT_I2C_OP_DELAY 1000 /* Internal I2C0 master */ /* External I2C0 address & offset */ @@ -132,4 +137,14 @@ int anx7406_hpd_reset(const int port); void anx7406_update_hpd_status(const struct usb_mux *mux, mux_state_t mux_state); +/** + * Set/clear GPIO + * + * @param port USB-C port + * @param gpio GPIO number + * @param value true:high false:low + * @return enum ec_error_list + */ +enum ec_error_list anx7406_set_gpio(int port, uint8_t gpio, bool value); + #endif /* __CROS_EC_USB_PD_TCPM_ANX7406_H */ -- cgit v1.2.1