From 38f07aec87e712f99393ebcfc362e56501027be0 Mon Sep 17 00:00:00 2001 From: Jason Yuan Date: Wed, 15 Feb 2023 15:56:56 -0800 Subject: zephyr: move tcpc_get_alert_status to shim tcpc_get_alert_status is similar between multiple different projects. They have been now merged into common code. BUG=b:254148652 TEST=twister, usbc charging on villager, lazor BRANCH=none LOW_COVERAGE_REASON=the change from hardcoding to rst-gpios in board specific code is uncovered. The common code is 100% covered. This CL increases the absolute coverage. Change-Id: I3136bd5b600dbb385547e06490dcbf8815b85b85 Signed-off-by: Jason Yuan Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4257651 Commit-Queue: zhi cheng yuan Auto-Submit: zhi cheng yuan Reviewed-by: Keith Short Tested-by: zhi cheng yuan --- board/brya/usbc_config.c | 5 +++ include/usb_pd_tcpm.h | 1 + zephyr/dts/bindings/emul/tcpci.yaml | 6 ++++ .../bindings/usbc/tcpc/analogix,anx7447-tcpc.yaml | 5 +++ zephyr/dts/bindings/usbc/tcpc/cypress,ccgxxf.yaml | 5 +++ .../dts/bindings/usbc/tcpc/fairchild,fusb302.yaml | 5 +++ zephyr/dts/bindings/usbc/tcpc/nuvoton,nct38xx.yaml | 6 ++++ zephyr/dts/bindings/usbc/tcpc/parade,ps8xxx.yaml | 5 +++ .../dts/bindings/usbc/tcpc/renesas,raa489000.yaml | 5 +++ zephyr/program/brya/gpio.dts | 4 +-- zephyr/program/brya/prj.conf | 2 +- zephyr/program/corsola/npcx_i2c.dtsi | 5 +++ zephyr/program/corsola/src/npcx_usbc.c | 21 ++---------- zephyr/program/herobrine/hoglin/project.overlay | 10 ++++++ zephyr/program/herobrine/i2c.dtsi | 10 ++++++ zephyr/program/herobrine/src/usbc_config.c | 24 +++---------- zephyr/program/rex/rex.dtsi | 10 ++++++ zephyr/program/rex/src/usbc_config.c | 32 ++---------------- zephyr/program/skyrim/i2c.dtsi | 10 ++++++ zephyr/program/skyrim/src/usbc_config.c | 27 ++------------- zephyr/program/trogdor/lazor/i2c.dts | 10 ++++++ zephyr/program/trogdor/lazor/src/usbc_config.c | 24 +++---------- zephyr/shim/include/usbc/tcpc_anx7447.h | 1 + zephyr/shim/include/usbc/tcpc_anx7447_emul.h | 1 + zephyr/shim/include/usbc/tcpc_ccgxxf.h | 3 +- zephyr/shim/include/usbc/tcpc_fusb302.h | 3 +- zephyr/shim/include/usbc/tcpc_generic_emul.h | 3 +- zephyr/shim/include/usbc/tcpc_nct38xx.h | 3 +- zephyr/shim/include/usbc/tcpc_ps8xxx.h | 3 +- zephyr/shim/include/usbc/tcpc_ps8xxx_emul.h | 3 +- zephyr/shim/src/tcpc.c | 39 ++++++++++++++++++---- zephyr/test/drivers/boards/native_posix.overlay | 10 +++--- zephyr/test/drivers/common/src/stubs.c | 18 +++++----- zephyr/test/krabby/src/stubs.c | 5 --- 34 files changed, 178 insertions(+), 146 deletions(-) diff --git a/board/brya/usbc_config.c b/board/brya/usbc_config.c index 03cf197569..fbec72f20b 100644 --- a/board/brya/usbc_config.c +++ b/board/brya/usbc_config.c @@ -398,11 +398,15 @@ static void board_tcpc_init(void) #ifndef CONFIG_ZEPHYR gpio_enable_interrupt(GPIO_USB_C1_TCPC_INT_ODL); gpio_enable_interrupt(GPIO_USB_C1_BC12_INT_ODL); +#else + } else { + tcpc_config[1].irq_gpio.port = NULL; #endif /* !CONFIG_ZEPHYR */ } } DECLARE_HOOK(HOOK_INIT, board_tcpc_init, HOOK_PRIO_INIT_CHIPSET); +#ifndef CONFIG_ZEPHYR uint16_t tcpc_get_alert_status(void) { uint16_t status = 0; @@ -416,6 +420,7 @@ uint16_t tcpc_get_alert_status(void) return status; } +#endif int ppc_get_alert_status(int port) { diff --git a/include/usb_pd_tcpm.h b/include/usb_pd_tcpm.h index 1888002a85..ed0b95478c 100644 --- a/include/usb_pd_tcpm.h +++ b/include/usb_pd_tcpm.h @@ -587,6 +587,7 @@ struct tcpc_config_t { uint32_t flags; #ifdef CONFIG_PLATFORM_EC_TCPC_INTERRUPT struct gpio_dt_spec irq_gpio; + struct gpio_dt_spec rst_gpio; #else enum gpio_signal alert_signal; #endif diff --git a/zephyr/dts/bindings/emul/tcpci.yaml b/zephyr/dts/bindings/emul/tcpci.yaml index 2a10209fdd..937aa51489 100644 --- a/zephyr/dts/bindings/emul/tcpci.yaml +++ b/zephyr/dts/bindings/emul/tcpci.yaml @@ -13,6 +13,12 @@ properties: description: | Interrupt from TCPC using shim driver + rst-gpios: + type: phandle-array + required: false + description: | + TCPC reset line using shim driver + int-pin: type: phandles required: false diff --git a/zephyr/dts/bindings/usbc/tcpc/analogix,anx7447-tcpc.yaml b/zephyr/dts/bindings/usbc/tcpc/analogix,anx7447-tcpc.yaml index ba25ccd683..028bcfb595 100644 --- a/zephyr/dts/bindings/usbc/tcpc/analogix,anx7447-tcpc.yaml +++ b/zephyr/dts/bindings/usbc/tcpc/analogix,anx7447-tcpc.yaml @@ -15,3 +15,8 @@ properties: required: false description: | Interrupt from TCPC + rst-gpios: + type: phandle-array + required: false + description: | + TCPC reset line diff --git a/zephyr/dts/bindings/usbc/tcpc/cypress,ccgxxf.yaml b/zephyr/dts/bindings/usbc/tcpc/cypress,ccgxxf.yaml index 89f1f78b63..2011c70662 100644 --- a/zephyr/dts/bindings/usbc/tcpc/cypress,ccgxxf.yaml +++ b/zephyr/dts/bindings/usbc/tcpc/cypress,ccgxxf.yaml @@ -19,6 +19,11 @@ properties: required: false description: | Interrupt from TCPC using shim driver + rst-gpios: + type: phandle-array + required: false + description: | + TCPC reset line while using shim driver int-pin: type: phandles required: false diff --git a/zephyr/dts/bindings/usbc/tcpc/fairchild,fusb302.yaml b/zephyr/dts/bindings/usbc/tcpc/fairchild,fusb302.yaml index c3f353cbf2..b6748a2f8b 100644 --- a/zephyr/dts/bindings/usbc/tcpc/fairchild,fusb302.yaml +++ b/zephyr/dts/bindings/usbc/tcpc/fairchild,fusb302.yaml @@ -15,6 +15,11 @@ properties: required: false description: | Interrupt from TCPC using shim driver + rst-gpios: + type: phandle-array + required: false + description: | + TCPC reset line while using shim driver int-pin: type: phandles required: false diff --git a/zephyr/dts/bindings/usbc/tcpc/nuvoton,nct38xx.yaml b/zephyr/dts/bindings/usbc/tcpc/nuvoton,nct38xx.yaml index cfbe5a748f..77dea4d348 100644 --- a/zephyr/dts/bindings/usbc/tcpc/nuvoton,nct38xx.yaml +++ b/zephyr/dts/bindings/usbc/tcpc/nuvoton,nct38xx.yaml @@ -27,6 +27,12 @@ properties: description: | Interrupt from TCPC using shim driver + rst-gpios: + type: phandle-array + required: false + description: | + TCPC reset line while using shim driver + int-pin: type: phandles required: false diff --git a/zephyr/dts/bindings/usbc/tcpc/parade,ps8xxx.yaml b/zephyr/dts/bindings/usbc/tcpc/parade,ps8xxx.yaml index e6c2a9bbcb..733b779726 100644 --- a/zephyr/dts/bindings/usbc/tcpc/parade,ps8xxx.yaml +++ b/zephyr/dts/bindings/usbc/tcpc/parade,ps8xxx.yaml @@ -15,3 +15,8 @@ properties: required: false description: | Interrupt from TCPC + rst-gpios: + type: phandle-array + required: false + description: | + TCPC reset line diff --git a/zephyr/dts/bindings/usbc/tcpc/renesas,raa489000.yaml b/zephyr/dts/bindings/usbc/tcpc/renesas,raa489000.yaml index de6402d4ee..6139db28cf 100644 --- a/zephyr/dts/bindings/usbc/tcpc/renesas,raa489000.yaml +++ b/zephyr/dts/bindings/usbc/tcpc/renesas,raa489000.yaml @@ -19,3 +19,8 @@ properties: required: false description: | Interrupt from TCPC + rst-gpios: + type: phandle-array + required: false + description: | + TCPC reset line diff --git a/zephyr/program/brya/gpio.dts b/zephyr/program/brya/gpio.dts index ff9f895ec1..b48077d96a 100644 --- a/zephyr/program/brya/gpio.dts +++ b/zephyr/program/brya/gpio.dts @@ -208,11 +208,11 @@ enum-name = "GPIO_VOLUME_UP_L"; }; gpio_usb_c0_c2_tcpc_int_odl: usb_c0_c2_tcpc_int_odl { - gpios = <&gpioe 0 GPIO_INPUT>; + gpios = <&gpioe 0 (GPIO_INPUT | GPIO_ACTIVE_LOW)>; enum-name = "GPIO_USB_C0_C2_TCPC_INT_ODL"; }; gpio_usb_c1_tcpc_int_odl: usb_c1_tcpc_int_odl { - gpios = <&gpioa 2 GPIO_INPUT>; + gpios = <&gpioa 2 (GPIO_INPUT | GPIO_ACTIVE_LOW)>; enum-name = "GPIO_USB_C1_TCPC_INT_ODL"; }; gpio_usb_c0_ppc_int_odl: usb_c0_ppc_int_odl { diff --git a/zephyr/program/brya/prj.conf b/zephyr/program/brya/prj.conf index 2929175360..8c4c04c3e6 100644 --- a/zephyr/program/brya/prj.conf +++ b/zephyr/program/brya/prj.conf @@ -133,7 +133,7 @@ CONFIG_PLATFORM_EC_USB_PD_TCPM_TCPCI=y CONFIG_PLATFORM_EC_USBC_PPC_DEDICATED_INT=y CONFIG_PLATFORM_EC_CONSOLE_CMD_PPC_DUMP=n CONFIG_PLATFORM_EC_CONSOLE_CMD_TCPC_DUMP=n -CONFIG_PLATFORM_EC_USB_PD_TCPC_RUNTIME_CONFIG=n +CONFIG_PLATFORM_EC_USB_PD_TCPC_RUNTIME_CONFIG=y CONFIG_PLATFORM_EC_USB_PD_REQUIRE_AP_MODE_ENTRY=y CONFIG_PLATFORM_EC_USB_PD_INT_SHARED=y CONFIG_PLATFORM_EC_USB_PD_PORT_0_SHARED=y diff --git a/zephyr/program/corsola/npcx_i2c.dtsi b/zephyr/program/corsola/npcx_i2c.dtsi index 2fd56fab53..f41939fde0 100644 --- a/zephyr/program/corsola/npcx_i2c.dtsi +++ b/zephyr/program/corsola/npcx_i2c.dtsi @@ -82,6 +82,11 @@ * the "named-gpios" node will be dealt with at a later date. */ irq-gpios = <&gpio7 3 GPIO_ACTIVE_LOW>; + /* a duplicate of the <&gpio_usb_c0_tcpc_rst> node in + * "named-gpios". This is the Zephyr preferred style, + * the "named-gpios" node will be dealt with at a later date. + */ + rst-gpios = <&gpioc 0 GPIO_ACTIVE_HIGH>; }; ppc_port0: nx20p348x@72 { diff --git a/zephyr/program/corsola/src/npcx_usbc.c b/zephyr/program/corsola/src/npcx_usbc.c index 9c848b5cc7..0ee6a43dc1 100644 --- a/zephyr/program/corsola/src/npcx_usbc.c +++ b/zephyr/program/corsola/src/npcx_usbc.c @@ -136,9 +136,9 @@ void board_reset_pd_mcu(void) CPRINTS("Resetting TCPCs..."); /* reset C0 ANX3447 */ /* Assert reset */ - gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c0_tcpc_rst), 1); + gpio_pin_set_dt(&tcpc_config[0].rst_gpio, 1); msleep(1); - gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c0_tcpc_rst), 0); + gpio_pin_set_dt(&tcpc_config[0].rst_gpio, 0); /* After TEST_R release, anx7447/3447 needs 2ms to finish eFuse * loading. */ @@ -222,23 +222,6 @@ int board_set_active_charge_port(int port) return EC_SUCCESS; } -uint16_t tcpc_get_alert_status(void) -{ - uint16_t status = 0; - - if (gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c0_tcpc_int_odl))) { - if (!gpio_pin_get_dt( - GPIO_DT_FROM_NODELABEL(gpio_usb_c0_tcpc_rst))) { - status |= PD_STATUS_TCPC_ALERT_0; - } - } - - if (gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c1_tcpc_int_odl))) { - return status |= PD_STATUS_TCPC_ALERT_1; - } - return status; -} - void ppc_interrupt(enum gpio_signal signal) { switch (signal) { diff --git a/zephyr/program/herobrine/hoglin/project.overlay b/zephyr/program/herobrine/hoglin/project.overlay index dd192d22f9..fb2101d07f 100644 --- a/zephyr/program/herobrine/hoglin/project.overlay +++ b/zephyr/program/herobrine/hoglin/project.overlay @@ -47,6 +47,11 @@ * the "named-gpios" node will be dealt with at a later date. */ irq-gpios = <&gpioe 0 GPIO_ACTIVE_LOW>; + /* a duplicate of the <&gpio_usb_c0_pd_rst_l> node in + * "named-gpios". This is the Zephyr preferred style, + * the "named-gpios" node will be dealt with at a later date. + */ + rst-gpios = <&gpiof 1 GPIO_ACTIVE_LOW>; }; }; @@ -60,5 +65,10 @@ * the "named-gpios" node will be dealt with at a later date. */ irq-gpios = <&gpiof 5 GPIO_ACTIVE_LOW>; + /* a duplicate of the <&gpio_usb_c1_pd_rst_l> node in + * "named-gpios". This is the Zephyr preferred style, + * the "named-gpios" node will be dealt with at a later date. + */ + rst-gpios = <&gpioe 4 GPIO_ACTIVE_LOW>; }; }; diff --git a/zephyr/program/herobrine/i2c.dtsi b/zephyr/program/herobrine/i2c.dtsi index fa4c1c2960..c0c904b2c9 100644 --- a/zephyr/program/herobrine/i2c.dtsi +++ b/zephyr/program/herobrine/i2c.dtsi @@ -100,6 +100,11 @@ * the "named-gpios" node will be dealt with at a later date. */ irq-gpios = <&gpioe 0 GPIO_ACTIVE_LOW>; + /* a duplicate of the <&gpio_usb_c0_pd_rst_l> node in + * "named-gpios". This is the Zephyr preferred style, + * the "named-gpios" node will be dealt with at a later date. + */ + rst-gpios = <&gpiof 1 GPIO_ACTIVE_LOW>; }; }; @@ -129,6 +134,11 @@ * the "named-gpios" node will be dealt with at a later date. */ irq-gpios = <&gpiof 5 GPIO_ACTIVE_LOW>; + /* a duplicate of the <&gpio_usb_c1_pd_rst_l> node in + * "named-gpios". This is the Zephyr preferred style, + * the "named-gpios" node will be dealt with at a later date. + */ + rst-gpios = <&gpioe 4 GPIO_ACTIVE_LOW>; }; }; diff --git a/zephyr/program/herobrine/src/usbc_config.c b/zephyr/program/herobrine/src/usbc_config.c index c9ee477cef..5928d88d3d 100644 --- a/zephyr/program/herobrine/src/usbc_config.c +++ b/zephyr/program/herobrine/src/usbc_config.c @@ -145,11 +145,11 @@ void board_reset_pd_mcu(void) cprints(CC_USB, "Resetting TCPCs..."); cflush(); - gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c0_pd_rst_l), 1); - gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c1_pd_rst_l), 1); + gpio_pin_set_dt(&tcpc_config[0].rst_gpio, 1); + gpio_pin_set_dt(&tcpc_config[1].rst_gpio, 1); msleep(PS8XXX_RESET_DELAY_MS); - gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c0_pd_rst_l), 0); - gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c1_pd_rst_l), 0); + gpio_pin_set_dt(&tcpc_config[0].rst_gpio, 0); + gpio_pin_set_dt(&tcpc_config[1].rst_gpio, 0); msleep(PS8805_FW_INIT_DELAY_MS); } @@ -248,19 +248,3 @@ __override void board_set_charge_limit(int port, int supplier, int charge_ma, charge_set_input_current_limit(charge_ma, charge_mv); } - -uint16_t tcpc_get_alert_status(void) -{ - uint16_t status = 0; - - if (gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c0_pd_int_odl))) - if (!gpio_pin_get_dt( - GPIO_DT_FROM_NODELABEL(gpio_usb_c0_pd_rst_l))) - status |= PD_STATUS_TCPC_ALERT_0; - if (gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c1_pd_int_odl))) - if (!gpio_pin_get_dt( - GPIO_DT_FROM_NODELABEL(gpio_usb_c1_pd_rst_l))) - status |= PD_STATUS_TCPC_ALERT_1; - - return status; -} diff --git a/zephyr/program/rex/rex.dtsi b/zephyr/program/rex/rex.dtsi index 7ce5194ada..28f719d356 100644 --- a/zephyr/program/rex/rex.dtsi +++ b/zephyr/program/rex/rex.dtsi @@ -146,6 +146,11 @@ * the "named-gpios" node will be dealt with at a later date. */ irq-gpios = <&gpioe 0 GPIO_ACTIVE_LOW>; + /* a duplicate of the <&gpio_usb_c0_tcpc_rst_odl> node in + * "named-gpios". This is the Zephyr preferred style, + * the "named-gpios" node will be dealt with at a later date. + */ + rst-gpios = <&gpio6 7 (GPIO_OPEN_DRAIN | GPIO_ACTIVE_LOW)>; }; nct3807_C0: nct3807_C0@70 { @@ -242,6 +247,11 @@ * the "named-gpios" node will be dealt with at a later date. */ irq-gpios = <&gpio3 4 GPIO_ACTIVE_LOW>; + /* a duplicate of the <&gpio_usb_c1_rt_rst_r_odl> node in + * "named-gpios". This is the Zephyr preferred style, + * the "named-gpios" node will be dealt with at a later date. + */ + rst-gpios = <&gpio7 4 (GPIO_OPEN_DRAIN | GPIO_ACTIVE_LOW)>; }; }; diff --git a/zephyr/program/rex/src/usbc_config.c b/zephyr/program/rex/src/usbc_config.c index 13a2fde86b..9efa848205 100644 --- a/zephyr/program/rex/src/usbc_config.c +++ b/zephyr/program/rex/src/usbc_config.c @@ -86,7 +86,7 @@ static void reset_nct38xx_port(int port) /* TODO(b/225189538): Save and restore ioex signals */ if (port == USBC_PORT_C0) { - reset_gpio_l = GPIO_DT_FROM_NODELABEL(gpio_usb_c0_tcpc_rst_odl); + reset_gpio_l = &tcpc_config[0].rst_gpio; ioex_port0 = DEVICE_DT_GET(DT_NODELABEL(ioex_c0_port0)); ioex_port1 = DEVICE_DT_GET(DT_NODELABEL(ioex_c0_port1)); } else { @@ -113,38 +113,12 @@ void board_reset_pd_mcu(void) reset_nct38xx_port(USBC_PORT_C0); /* Reset TCPC1 */ - gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c1_rt_rst_r_odl), 1); + gpio_pin_set_dt(&tcpc_config[1].rst_gpio, 1); msleep(PS8XXX_RESET_DELAY_MS); - gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c1_rt_rst_r_odl), 0); + gpio_pin_set_dt(&tcpc_config[1].rst_gpio, 0); msleep(PS8815_FW_INIT_DELAY_MS); } -uint16_t tcpc_get_alert_status(void) -{ - uint16_t status = 0; - const struct gpio_dt_spec *tcpc_c0_rst_l; - const struct gpio_dt_spec *tcpc_c1_rst_l; - - tcpc_c0_rst_l = GPIO_DT_FROM_NODELABEL(gpio_usb_c0_tcpc_rst_odl); - tcpc_c1_rst_l = GPIO_DT_FROM_NODELABEL(gpio_usb_c1_rt_rst_r_odl); - - /* - * Check which port has the ALERT line set and ignore if that TCPC has - * its reset line active. - */ - if (gpio_pin_get_dt(&tcpc_config[0].irq_gpio) && - !gpio_pin_get_dt(tcpc_c0_rst_l)) { - status |= PD_STATUS_TCPC_ALERT_0; - } - - if (gpio_pin_get_dt(&tcpc_config[1].irq_gpio) && - !gpio_pin_get_dt(tcpc_c1_rst_l)) { - status |= PD_STATUS_TCPC_ALERT_1; - } - - return status; -} - void ppc_interrupt(enum gpio_signal signal) { switch (signal) { diff --git a/zephyr/program/skyrim/i2c.dtsi b/zephyr/program/skyrim/i2c.dtsi index c1f3d2d0f6..6bffc60e65 100644 --- a/zephyr/program/skyrim/i2c.dtsi +++ b/zephyr/program/skyrim/i2c.dtsi @@ -89,6 +89,11 @@ * the "named-gpios" node will be dealt with at a later date. */ irq-gpios = <&gpioe 0 GPIO_ACTIVE_LOW>; + /* a duplicate of the <&gpio_usb_c0_tcpc_rst_l> node in + * "named-gpios". This is the Zephyr preferred style, + * the "named-gpios" node will be dealt with at a later date. + */ + rst-gpios = <&gpio3 4 GPIO_ACTIVE_LOW>; }; nct3807_C0: nct3807_C0@70 { @@ -168,6 +173,11 @@ * the "named-gpios" node will be dealt with at a later date. */ irq-gpios = <&gpioc 7 GPIO_ACTIVE_LOW>; + /* a duplicate of the <&gpio_usb_c1_tcpc_rst_l> node in + * "named-gpios". This is the Zephyr preferred style, + * the "named-gpios" node will be dealt with at a later date. + */ + rst-gpios = <&gpio3 7 GPIO_ACTIVE_LOW>; }; nct3807_C1: nct3807_C1@70 { diff --git a/zephyr/program/skyrim/src/usbc_config.c b/zephyr/program/skyrim/src/usbc_config.c index 3953b11f41..ab1d444df8 100644 --- a/zephyr/program/skyrim/src/usbc_config.c +++ b/zephyr/program/skyrim/src/usbc_config.c @@ -256,11 +256,11 @@ static void reset_nct38xx_port(int port) gpio_flags_t saved_port1_flags[8] = { 0 }; if (port == USBC_PORT_C0) { - reset_gpio_l = GPIO_DT_FROM_NODELABEL(gpio_usb_c0_tcpc_rst_l); + reset_gpio_l = &tcpc_config[0].rst_gpio; ioex_port0 = DEVICE_DT_GET(DT_NODELABEL(ioex_c0_port0)); ioex_port1 = DEVICE_DT_GET(DT_NODELABEL(ioex_c0_port1)); } else if (port == USBC_PORT_C1) { - reset_gpio_l = GPIO_DT_FROM_NODELABEL(gpio_usb_c1_tcpc_rst_l); + reset_gpio_l = &tcpc_config[1].rst_gpio; ioex_port0 = DEVICE_DT_GET(DT_NODELABEL(ioex_c1_port0)); ioex_port1 = DEVICE_DT_GET(DT_NODELABEL(ioex_c1_port1)); } else { @@ -307,29 +307,6 @@ void board_reset_pd_mcu(void) reset_nct38xx_port(USBC_PORT_C1); } -uint16_t tcpc_get_alert_status(void) -{ - uint16_t status = 0; - - /* - * Check which port has the ALERT line set and ignore if that TCPC has - * its reset line active. - */ - if (gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c0_tcpc_int_odl))) { - if (!gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL( - gpio_usb_c0_tcpc_rst_l)) != 0) - status |= PD_STATUS_TCPC_ALERT_0; - } - - if (gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c1_tcpc_int_odl))) { - if (!gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL( - gpio_usb_c1_tcpc_rst_l)) != 0) - status |= PD_STATUS_TCPC_ALERT_1; - } - - return status; -} - #ifdef CONFIG_PLATFORM_EC_USB_CHARGER void bc12_interrupt(enum gpio_signal signal) { diff --git a/zephyr/program/trogdor/lazor/i2c.dts b/zephyr/program/trogdor/lazor/i2c.dts index 595bae59c7..e10ed04a0e 100644 --- a/zephyr/program/trogdor/lazor/i2c.dts +++ b/zephyr/program/trogdor/lazor/i2c.dts @@ -81,6 +81,11 @@ * the "named-gpios" node will be dealt with at a later date. */ irq-gpios = <&gpioe 0 GPIO_ACTIVE_LOW>; + /* a duplicate of the <&gpio_usb_c0_pd_rst_l> node in + * "named-gpios". This is the Zephyr preferred style, + * the "named-gpios" node will be dealt with at a later date. + */ + rst-gpios = <&gpiof 1 (GPIO_OPEN_DRAIN | GPIO_ACTIVE_LOW)>; }; }; @@ -109,6 +114,11 @@ * the "named-gpios" node will be dealt with at a later date. */ irq-gpios = <&gpiof 5 GPIO_ACTIVE_LOW>; + /* a duplicate of the <&gpio_usb_c1_pd_rst_l> node in + * "named-gpios". This is the Zephyr preferred style, + * the "named-gpios" node will be dealt with at a later date. + */ + rst-gpios = <&gpioe 4 (GPIO_OPEN_DRAIN | GPIO_ACTIVE_LOW)>; }; }; diff --git a/zephyr/program/trogdor/lazor/src/usbc_config.c b/zephyr/program/trogdor/lazor/src/usbc_config.c index 720d768d9e..80d2cebdf0 100644 --- a/zephyr/program/trogdor/lazor/src/usbc_config.c +++ b/zephyr/program/trogdor/lazor/src/usbc_config.c @@ -191,11 +191,11 @@ void board_reset_pd_mcu(void) cprints(CC_USB, "Resetting TCPCs..."); cflush(); - gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c0_pd_rst_l), 1); - gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c1_pd_rst_l), 1); + gpio_pin_set_dt(&tcpc_config[0].rst_gpio, 1); + gpio_pin_set_dt(&tcpc_config[1].rst_gpio, 1); msleep(PS8XXX_RESET_DELAY_MS); - gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c0_pd_rst_l), 0); - gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c1_pd_rst_l), 0); + gpio_pin_set_dt(&tcpc_config[0].rst_gpio, 0); + gpio_pin_set_dt(&tcpc_config[1].rst_gpio, 0); } void board_set_tcpc_power_mode(int port, int mode) @@ -293,19 +293,3 @@ __override void board_set_charge_limit(int port, int supplier, int charge_ma, charge_set_input_current_limit(charge_ma, charge_mv); } - -uint16_t tcpc_get_alert_status(void) -{ - uint16_t status = 0; - - if (gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c0_pd_int_odl))) - if (!gpio_pin_get_dt( - GPIO_DT_FROM_NODELABEL(gpio_usb_c0_pd_rst_l))) - status |= PD_STATUS_TCPC_ALERT_0; - if (gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c1_pd_int_odl))) - if (!gpio_pin_get_dt( - GPIO_DT_FROM_NODELABEL(gpio_usb_c1_pd_rst_l))) - status |= PD_STATUS_TCPC_ALERT_1; - - return status; -} diff --git a/zephyr/shim/include/usbc/tcpc_anx7447.h b/zephyr/shim/include/usbc/tcpc_anx7447.h index f8abb3760e..4da2e223ce 100644 --- a/zephyr/shim/include/usbc/tcpc_anx7447.h +++ b/zephyr/shim/include/usbc/tcpc_anx7447.h @@ -20,5 +20,6 @@ .drv = &anx7447_tcpm_drv, \ .flags = DT_PROP(id, tcpc_flags), \ .irq_gpio = GPIO_DT_SPEC_GET_OR(id, irq_gpios, {}), \ + .rst_gpio = GPIO_DT_SPEC_GET_OR(id, rst_gpios, {}), \ } /* clang-format on */ diff --git a/zephyr/shim/include/usbc/tcpc_anx7447_emul.h b/zephyr/shim/include/usbc/tcpc_anx7447_emul.h index 51ef11416d..0472479b5a 100644 --- a/zephyr/shim/include/usbc/tcpc_anx7447_emul.h +++ b/zephyr/shim/include/usbc/tcpc_anx7447_emul.h @@ -19,5 +19,6 @@ }, \ .drv = &anx7447_tcpm_drv, \ .irq_gpio = GPIO_DT_SPEC_GET_OR(id, irq_gpios, {}), \ + .rst_gpio = GPIO_DT_SPEC_GET_OR(id, rst_gpios, {}), \ } /* clang-format on */ diff --git a/zephyr/shim/include/usbc/tcpc_ccgxxf.h b/zephyr/shim/include/usbc/tcpc_ccgxxf.h index cb41d3a60e..1f1360b185 100644 --- a/zephyr/shim/include/usbc/tcpc_ccgxxf.h +++ b/zephyr/shim/include/usbc/tcpc_ccgxxf.h @@ -20,7 +20,8 @@ .drv = &ccgxxf_tcpm_drv, \ .flags = TCPC_FLAGS_TCPCI_REV2_0, \ COND_CODE_1(CONFIG_PLATFORM_EC_TCPC_INTERRUPT, \ - (.irq_gpio = GPIO_DT_SPEC_GET_OR(id, irq_gpios, {})), \ + (.irq_gpio = GPIO_DT_SPEC_GET_OR(id, irq_gpios, {}), \ + .rst_gpio = GPIO_DT_SPEC_GET_OR(id, rst_gpios, {})), \ (.alert_signal = COND_CODE_1( \ DT_NODE_HAS_PROP(id, int_pin), \ (GPIO_SIGNAL(DT_PHANDLE(id, int_pin))), \ diff --git a/zephyr/shim/include/usbc/tcpc_fusb302.h b/zephyr/shim/include/usbc/tcpc_fusb302.h index 36533ffc19..9ac651fa10 100644 --- a/zephyr/shim/include/usbc/tcpc_fusb302.h +++ b/zephyr/shim/include/usbc/tcpc_fusb302.h @@ -20,7 +20,8 @@ }, \ .drv = &fusb302_tcpm_drv, \ COND_CODE_1(CONFIG_PLATFORM_EC_TCPC_INTERRUPT, \ - (.irq_gpio = GPIO_DT_SPEC_GET_OR(id, irq_gpios, {})), \ + (.irq_gpio = GPIO_DT_SPEC_GET_OR(id, irq_gpios, {}), \ + .rst_gpio = GPIO_DT_SPEC_GET_OR(id, rst_gpios, {})), \ (.alert_signal = COND_CODE_1( \ DT_NODE_HAS_PROP(id, int_pin), \ (GPIO_SIGNAL(DT_PHANDLE(id, int_pin))), \ diff --git a/zephyr/shim/include/usbc/tcpc_generic_emul.h b/zephyr/shim/include/usbc/tcpc_generic_emul.h index bbb85f9829..1ce29fd2e5 100644 --- a/zephyr/shim/include/usbc/tcpc_generic_emul.h +++ b/zephyr/shim/include/usbc/tcpc_generic_emul.h @@ -19,7 +19,8 @@ }, \ .drv = &tcpci_tcpm_drv, \ COND_CODE_1(CONFIG_PLATFORM_EC_TCPC_INTERRUPT, \ - (.irq_gpio = GPIO_DT_SPEC_GET_OR(id, irq_gpios, {})), \ + (.irq_gpio = GPIO_DT_SPEC_GET_OR(id, irq_gpios, {}), \ + .rst_gpio = GPIO_DT_SPEC_GET_OR(id, rst_gpios, {})), \ (.alert_signal = COND_CODE_1( \ DT_NODE_HAS_PROP(id, int_pin), \ (GPIO_SIGNAL(DT_PHANDLE(id, int_pin))), \ diff --git a/zephyr/shim/include/usbc/tcpc_nct38xx.h b/zephyr/shim/include/usbc/tcpc_nct38xx.h index b1b0d07b4d..2381a4f7db 100644 --- a/zephyr/shim/include/usbc/tcpc_nct38xx.h +++ b/zephyr/shim/include/usbc/tcpc_nct38xx.h @@ -23,7 +23,8 @@ .drv = &nct38xx_tcpm_drv, \ .flags = DT_PROP(id, tcpc_flags), \ COND_CODE_1(CONFIG_PLATFORM_EC_TCPC_INTERRUPT, \ - (.irq_gpio = GPIO_DT_SPEC_GET_OR(id, irq_gpios, {})), \ + (.irq_gpio = GPIO_DT_SPEC_GET_OR(id, irq_gpios, {}), \ + .rst_gpio = GPIO_DT_SPEC_GET_OR(id, rst_gpios, {})), \ (.alert_signal = COND_CODE_1( \ DT_NODE_HAS_PROP(id, int_pin), \ (GPIO_SIGNAL(DT_PHANDLE(id, int_pin))), \ diff --git a/zephyr/shim/include/usbc/tcpc_ps8xxx.h b/zephyr/shim/include/usbc/tcpc_ps8xxx.h index 6e9d572eda..5132184920 100644 --- a/zephyr/shim/include/usbc/tcpc_ps8xxx.h +++ b/zephyr/shim/include/usbc/tcpc_ps8xxx.h @@ -21,7 +21,8 @@ .drv = &ps8xxx_tcpm_drv, \ .flags = DT_PROP(id, tcpc_flags), \ COND_CODE_1(CONFIG_PLATFORM_EC_TCPC_INTERRUPT, \ - (.irq_gpio = GPIO_DT_SPEC_GET_OR(id, irq_gpios, {})), \ + (.irq_gpio = GPIO_DT_SPEC_GET_OR(id, irq_gpios, {}), \ + .rst_gpio = GPIO_DT_SPEC_GET_OR(id, rst_gpios, {})), \ (.alert_signal = COND_CODE_1( \ DT_NODE_HAS_PROP(id, int_pin), \ (GPIO_SIGNAL(DT_PHANDLE(id, int_pin))), \ diff --git a/zephyr/shim/include/usbc/tcpc_ps8xxx_emul.h b/zephyr/shim/include/usbc/tcpc_ps8xxx_emul.h index 7a1f773a24..493150ebaa 100644 --- a/zephyr/shim/include/usbc/tcpc_ps8xxx_emul.h +++ b/zephyr/shim/include/usbc/tcpc_ps8xxx_emul.h @@ -19,7 +19,8 @@ }, \ .drv = &ps8xxx_tcpm_drv, \ COND_CODE_1(CONFIG_PLATFORM_EC_TCPC_INTERRUPT, \ - (.irq_gpio = GPIO_DT_SPEC_GET_OR(id, irq_gpios, {})), \ + (.irq_gpio = GPIO_DT_SPEC_GET_OR(id, irq_gpios, {}), \ + .rst_gpio = GPIO_DT_SPEC_GET_OR(id, rst_gpios, {})), \ (.alert_signal = COND_CODE_1( \ DT_NODE_HAS_PROP(id, int_pin), \ (GPIO_SIGNAL(DT_PHANDLE(id, int_pin))), \ diff --git a/zephyr/shim/src/tcpc.c b/zephyr/shim/src/tcpc.c index 1deb808505..bea9f80cb8 100644 --- a/zephyr/shim/src/tcpc.c +++ b/zephyr/shim/src/tcpc.c @@ -85,6 +85,36 @@ MAYBE_CONST struct tcpc_config_t tcpc_config[] = { DT_FOREACH_STATUS_OKAY( BUILD_ASSERT(ARRAY_SIZE(tcpc_config) == CONFIG_USB_PD_PORT_MAX_COUNT); +uint16_t tcpc_get_alert_status(void) +{ + uint16_t status = 0; + uint16_t alert_mask[] = { PD_STATUS_TCPC_ALERT_0, + PD_STATUS_TCPC_ALERT_1, + PD_STATUS_TCPC_ALERT_2, + PD_STATUS_TCPC_ALERT_3 }; + + /* + * Check which port has the ALERT line set and ignore if that TCPC has + * its reset line active. + */ + for (int i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++) { + /* + * if the interrupt port exists and the interrupt is active + */ + if (tcpc_config[i].irq_gpio.port && + gpio_pin_get_dt(&tcpc_config[i].irq_gpio)) + /* + * if the reset line does not exist or exists but is + * not active. + */ + if (!tcpc_config[i].rst_gpio.port || + !gpio_pin_get_dt(&tcpc_config[i].rst_gpio)) + status |= alert_mask[i]; + } + + return status; +} + struct gpio_callback int_gpio_cb[CONFIG_USB_PD_PORT_MAX_COUNT]; static void tcpc_int_gpio_callback(const struct device *dev, @@ -107,8 +137,6 @@ static void tcpc_int_gpio_callback(const struct device *dev, */ void tcpc_enable_interrupt(void) { - gpio_flags_t flags; - for (int i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++) { /* * Check whether the interrupt pin has been configured @@ -139,12 +167,9 @@ void tcpc_enable_interrupt(void) gpio_add_callback(tcpc_config[i].irq_gpio.port, &int_gpio_cb[i]); } - flags = tcpc_config[i].flags & TCPC_FLAGS_ALERT_ACTIVE_HIGH ? - GPIO_INT_EDGE_RISING : - GPIO_INT_EDGE_FALLING; - flags = (flags | GPIO_INT_ENABLE) & ~GPIO_INT_DISABLE; + gpio_pin_interrupt_configure_dt(&tcpc_config[i].irq_gpio, - flags); + GPIO_INT_EDGE_TO_ACTIVE); } } /* diff --git a/zephyr/test/drivers/boards/native_posix.overlay b/zephyr/test/drivers/boards/native_posix.overlay index 2ed86cd9c4..f577b2b618 100644 --- a/zephyr/test/drivers/boards/native_posix.overlay +++ b/zephyr/test/drivers/boards/native_posix.overlay @@ -161,16 +161,16 @@ gpios = <&gpio0 8 (GPIO_OUTPUT_LOW)>; }; usb_c0_tcpc_int_odl: usb_c0_tcpc_int_odl { - gpios = <&gpio0 9 GPIO_INPUT>; + gpios = <&gpio0 9 (GPIO_INPUT | GPIO_ACTIVE_LOW)>; }; usb_c1_tcpc_int_odl: usb_c1_tcpc_int_odl { - gpios = <&gpio0 10 GPIO_INPUT>; + gpios = <&gpio0 10 (GPIO_INPUT | GPIO_ACTIVE_LOW)>; }; usb_c0_tcpc_rst_l: usb_c0_tcpc_rst_l { - gpios = <&gpio0 11 (GPIO_OUTPUT_HIGH | GPIO_INPUT)>; + gpios = <&gpio0 11 (GPIO_OUTPUT_HIGH | GPIO_INPUT | GPIO_ACTIVE_LOW)>; }; usb_c1_tcpc_rst_l: usb_c1_tcpc_rst_l { - gpios = <&gpio0 12 (GPIO_OUTPUT_HIGH | GPIO_INPUT)>; + gpios = <&gpio0 12 (GPIO_OUTPUT_HIGH | GPIO_INPUT | GPIO_ACTIVE_LOW)>; }; gpio_usb_c1_ppc_int: usb_c1_ppc_int { gpios = <&gpio0 13 GPIO_INPUT>; @@ -894,6 +894,7 @@ status = "okay"; reg = <0x82>; irq-gpios = <&gpio0 9 GPIO_ACTIVE_LOW>; + rst-gpios = <&gpio0 11 GPIO_ACTIVE_LOW>; }; }; @@ -939,6 +940,7 @@ compatible = "cros,ps8xxx-emul"; reg = <0xb>; irq-gpios = <&gpio0 10 GPIO_ACTIVE_LOW>; + rst-gpios = <&gpio0 12 GPIO_ACTIVE_LOW>; p0-i2c-addr = <0x8>; p1-i2c-addr = <0x9>; gpio-i2c-addr = <0x1a>; diff --git a/zephyr/test/drivers/common/src/stubs.c b/zephyr/test/drivers/common/src/stubs.c index 9943164417..cdb1a0f6a4 100644 --- a/zephyr/test/drivers/common/src/stubs.c +++ b/zephyr/test/drivers/common/src/stubs.c @@ -146,6 +146,7 @@ DEFINE_FAKE_VOID_FUNC(system_hibernate, uint32_t, uint32_t); DEFINE_FAKE_VOID_FUNC(board_reset_pd_mcu); +#ifndef CONFIG_PLATFORM_EC_TCPC_INTERRUPT uint16_t tcpc_get_alert_status(void) { uint16_t status = 0; @@ -154,20 +155,21 @@ uint16_t tcpc_get_alert_status(void) * Check which port has the ALERT line set and ignore if that TCPC has * its reset line active. */ - if (!gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(usb_c0_tcpc_int_odl))) { + if (gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(usb_c0_tcpc_int_odl))) { if (gpio_pin_get_dt( - GPIO_DT_FROM_NODELABEL(usb_c0_tcpc_rst_l)) != 0) + GPIO_DT_FROM_NODELABEL(usb_c0_tcpc_rst_l)) == 0) status |= PD_STATUS_TCPC_ALERT_0; } - if (!gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(usb_c1_tcpc_int_odl))) { + if (gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(usb_c1_tcpc_int_odl))) { if (gpio_pin_get_dt( - GPIO_DT_FROM_NODELABEL(usb_c1_tcpc_rst_l)) != 0) + GPIO_DT_FROM_NODELABEL(usb_c1_tcpc_rst_l)) == 0) status |= PD_STATUS_TCPC_ALERT_1; } return status; } +#endif void ppc_alert(enum gpio_signal signal) { @@ -198,14 +200,14 @@ static void stubs_interrupt_init(void) #endif /* Reset generic TCPCI on port 0. */ - gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(usb_c0_tcpc_rst_l), 0); - msleep(1); gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(usb_c0_tcpc_rst_l), 1); + msleep(1); + gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(usb_c0_tcpc_rst_l), 0); /* Reset PS8XXX on port 1. */ - gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(usb_c1_tcpc_rst_l), 0); - msleep(PS8XXX_RESET_DELAY_MS); gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(usb_c1_tcpc_rst_l), 1); + msleep(PS8XXX_RESET_DELAY_MS); + gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(usb_c1_tcpc_rst_l), 0); /* Enable PPC interrupts. */ gpio_enable_dt_interrupt(GPIO_INT_FROM_NODELABEL(int_usb_c0_ppc)); diff --git a/zephyr/test/krabby/src/stubs.c b/zephyr/test/krabby/src/stubs.c index c5cdf50b44..df1613528d 100644 --- a/zephyr/test/krabby/src/stubs.c +++ b/zephyr/test/krabby/src/stubs.c @@ -22,8 +22,3 @@ int board_get_adjusted_usb_pd_port_count(int port) { return 2; } - -uint16_t tcpc_get_alert_status(void) -{ - return 0; -} -- cgit v1.2.1