diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2023-04-14 13:37:13 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-04-18 01:37:03 +0000 |
commit | a3f90cf79e0f06fa186e3afa28b542b0bc7b351d (patch) | |
tree | b1f17f748976b88e0684655783a3a73640e6c769 | |
parent | 3a5f279c036ea19ed315d2db34b94f103c30b763 (diff) | |
download | chrome-ec-a3f90cf79e0f06fa186e3afa28b542b0bc7b351d.tar.gz |
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 <dnojiri@chromium.org>
Change-Id: I1e2ebda63fa49aec88d703f31f7bb70730939b63
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4426802
Reviewed-by: Peter Marheine <pmarheine@chromium.org>
-rw-r--r-- | driver/tcpm/anx7406.c | 15 | ||||
-rw-r--r-- | driver/tcpm/anx7406.h | 15 |
2 files changed, 30 insertions, 0 deletions
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 */ |