diff options
author | Abe Levkoy <alevkoy@chromium.org> | 2021-11-09 12:05:17 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-11-11 22:19:52 +0000 |
commit | 6743e47d6f34d1467c379383f968dc68b092897d (patch) | |
tree | ecd5c5041b0f095730cdfe9eb68ce7fb43875513 | |
parent | e05d0947c3c3617ea24ed7b66abeb3e518882df1 (diff) | |
download | chrome-ec-6743e47d6f34d1467c379383f968dc68b092897d.tar.gz |
zephyr test: Verify SYV682 FRS_EN signal
In the SYV682 emulator, only assert FRS status when FRS is enabled via
GPIO. In the test, check that FRS enable and disable updates the GPIO.
BUG=b:190519131
TEST=zmake configure --test zephyr/test/drivers
BRANCH=none
Signed-off-by: Abe Levkoy <alevkoy@chromium.org>
Change-Id: I50f640882f7e59a0e609614c400e93c75fe34e0c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3271350
Reviewed-by: Keith Short <keithshort@chromium.org>
Commit-Queue: Keith Short <keithshort@chromium.org>
-rw-r--r-- | zephyr/dts/bindings/emul/zephyr,syv682x.yaml | 6 | ||||
-rw-r--r-- | zephyr/emul/emul_syv682x.c | 38 | ||||
-rw-r--r-- | zephyr/test/drivers/overlay.dts | 8 | ||||
-rw-r--r-- | zephyr/test/drivers/src/ppc.c | 11 | ||||
-rw-r--r-- | zephyr/test/drivers/src/stubs.c | 2 |
5 files changed, 52 insertions, 13 deletions
diff --git a/zephyr/dts/bindings/emul/zephyr,syv682x.yaml b/zephyr/dts/bindings/emul/zephyr,syv682x.yaml index 75de7cf743..e1ce84e85d 100644 --- a/zephyr/dts/bindings/emul/zephyr,syv682x.yaml +++ b/zephyr/dts/bindings/emul/zephyr,syv682x.yaml @@ -7,3 +7,9 @@ description: Zephyr SYV682X Emulator compatible: "zephyr,syv682x-emul" include: base.yaml + +properties: + frs_en_gpio: + type: phandle + description: The GPIO that controls FRS enable on this device + required: true diff --git a/zephyr/emul/emul_syv682x.c b/zephyr/emul/emul_syv682x.c index 2a181fea23..b9d2dc57c7 100644 --- a/zephyr/emul/emul_syv682x.c +++ b/zephyr/emul/emul_syv682x.c @@ -6,6 +6,8 @@ #define DT_DRV_COMPAT zephyr_syv682x_emul #include <device.h> +#include <devicetree/gpio.h> +#include <drivers/gpio/gpio_emul.h> #include <emul.h> #include <drivers/i2c.h> #include <drivers/i2c_emul.h> @@ -25,6 +27,8 @@ struct syv682x_emul_data { struct i2c_emul emul; /** Smart battery device being emulated */ const struct device *i2c; + const struct device *frs_en_gpio_port; + gpio_pin_t frs_en_gpio_pin; /** Configuration information */ const struct syv682x_emul_cfg *cfg; /** Current state of all emulated SYV682x registers */ @@ -62,9 +66,16 @@ int syv682x_emul_set_reg(struct i2c_emul *emul, int reg, uint8_t val) void syv682x_emul_set_status(struct i2c_emul *emul, uint8_t val) { - struct syv682x_emul_data *data; + struct syv682x_emul_data *data = + CONTAINER_OF(emul, struct syv682x_emul_data, emul); + int frs_en_gpio = gpio_emul_output_get(data->frs_en_gpio_port, + data->frs_en_gpio_pin); + + /* Only assert FRS status if FRS is enabled. */ + __ASSERT_NO_MSG(frs_en_gpio >= 0); + if (!frs_en_gpio) + val &= ~SYV682X_STATUS_FRS; - data = CONTAINER_OF(emul, struct syv682x_emul_data, emul); data->status_cond = val; data->reg[SYV682X_STATUS_REG] |= val; @@ -79,7 +90,7 @@ void syv682x_emul_set_status(struct i2c_emul *emul, uint8_t val) * the power path off when either of these conditions occurs, and they * should quickly dissipate. If they somehow stay set, the device should * interrupt continuously. Relatedly, the emulator should only generate - * an FRS alert if the EC is asserting the FRS GPIO. + * an interrupt based on FRS status if the FRS enable pin was asserted. */ } @@ -257,14 +268,19 @@ static int syv682x_emul_init(const struct emul *emul, return ret; } -#define SYV682X_EMUL(n) \ - static struct syv682x_emul_data syv682x_emul_data_##n = {}; \ - static const struct syv682x_emul_cfg syv682x_emul_cfg_##n = { \ - .i2c_label = DT_INST_BUS_LABEL(n), \ - .data = &syv682x_emul_data_##n, \ - .addr = DT_INST_REG_ADDR(n), \ - }; \ - EMUL_DEFINE(syv682x_emul_init, DT_DRV_INST(n), &syv682x_emul_cfg_##n, \ +#define SYV682X_EMUL(n) \ + static struct syv682x_emul_data syv682x_emul_data_##n = { \ + .frs_en_gpio_port = DEVICE_DT_GET(DT_GPIO_CTLR( \ + DT_INST_PROP(n, frs_en_gpio), gpios)), \ + .frs_en_gpio_pin = DT_GPIO_PIN( \ + DT_INST_PROP(n, frs_en_gpio), gpios), \ + }; \ + static const struct syv682x_emul_cfg syv682x_emul_cfg_##n = { \ + .i2c_label = DT_INST_BUS_LABEL(n), \ + .data = &syv682x_emul_data_##n, \ + .addr = DT_INST_REG_ADDR(n), \ + }; \ + EMUL_DEFINE(syv682x_emul_init, DT_DRV_INST(n), &syv682x_emul_cfg_##n, \ &syv682x_emul_data_##n) DT_INST_FOREACH_STATUS_OKAY(SYV682X_EMUL) diff --git a/zephyr/test/drivers/overlay.dts b/zephyr/test/drivers/overlay.dts index a8b5dec4d1..c247caab05 100644 --- a/zephyr/test/drivers/overlay.dts +++ b/zephyr/test/drivers/overlay.dts @@ -59,6 +59,11 @@ enum-name = "GPIO_USB_C1_RT_RST_ODL"; label = "USB_C1_RT_RST_ODL"; }; + gpio_usb_c1_frs_en: usb_c1_frs_en { + gpios = <&gpio0 8 (GPIO_OUT_LOW)>; + enum-name = "GPIO_USB_C1_FRS_EN"; + label = "USB_C1_FRS_EN"; + }; }; named-i2c-ports { compatible = "named-i2c-ports"; @@ -473,6 +478,7 @@ compatible = "zephyr,syv682x-emul"; reg = <0x41>; label = "SYV682X_EMUL"; + frs_en_gpio = <&gpio_usb_c1_frs_en>; }; usb_c1_bb_retimer_emul: bbretimer@42 { @@ -512,7 +518,7 @@ }; &gpio0 { - ngpios = <8>; + ngpios = <9>; }; &i2c0 { diff --git a/zephyr/test/drivers/src/ppc.c b/zephyr/test/drivers/src/ppc.c index 95c8abf564..740c7a0aea 100644 --- a/zephyr/test/drivers/src/ppc.c +++ b/zephyr/test/drivers/src/ppc.c @@ -3,6 +3,9 @@ * found in the LICENSE file. */ +#include <device.h> +#include <devicetree/gpio.h> +#include <drivers/gpio/gpio_emul.h> #include <zephyr.h> #include <ztest.h> #include <ztest_assert.h> @@ -15,6 +18,8 @@ #include "usbc_ppc.h" #define SYV682X_ORD DT_DEP_ORD(DT_NODELABEL(syv682x_emul)) +#define GPIO_USB_C1_FRS_EN_PATH DT_PATH(named_gpios, usb_c1_frs_en) +#define GPIO_USB_C1_FRS_EN_PORT DT_GPIO_PIN(GPIO_USB_C1_FRS_EN_PATH, gpios) static const int syv682x_port = 1; @@ -200,6 +205,8 @@ static void test_ppc_syv682x_interrupt(void) static void test_ppc_syv682x_frs(void) { struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); + const struct device *gpio_dev = + DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_USB_C1_FRS_EN_PATH, gpios)); uint8_t reg; /* @@ -211,6 +218,8 @@ static void test_ppc_syv682x_frs(void) "PPC is sourcing VBUS after sink enabled"); ppc_set_polarity(syv682x_port, 0 /* CC1 */); ppc_set_frs_enable(syv682x_port, true); + zassert_equal(gpio_emul_output_get(gpio_dev, GPIO_USB_C1_FRS_EN_PORT), + 1, "FRS enabled, but FRS GPIO not asserted"); zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_4_REG, ®), "Reading CONTROL_4 failed"); zassert_equal(reg & @@ -219,6 +228,8 @@ static void test_ppc_syv682x_frs(void) "FRS enabled with CC1 polarity, but CONTROL_4 is 0x%x", reg); ppc_set_frs_enable(syv682x_port, false); + zassert_equal(gpio_emul_output_get(gpio_dev, GPIO_USB_C1_FRS_EN_PORT), + 0, "FRS disabled, but FRS GPIO not deasserted"); zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_4_REG, ®), "Reading CONTROL_4 failed"); zassert_equal(reg & diff --git a/zephyr/test/drivers/src/stubs.c b/zephyr/test/drivers/src/stubs.c index a8a478a86f..93a4d06623 100644 --- a/zephyr/test/drivers/src/stubs.c +++ b/zephyr/test/drivers/src/stubs.c @@ -227,7 +227,7 @@ struct ppc_config_t ppc_chips[] = { [USBC_PORT_C1] = { .i2c_port = I2C_PORT_USB_C1, .i2c_addr_flags = SYV682X_ADDR1_FLAGS, - /* TODO(b/190519131): Add FRS GPIO, test FRS */ + .frs_en = GPIO_USB_C1_FRS_EN, .drv = &syv682x_drv, }, }; |