diff --git a/drivers/usb_c/tcpc/ucpd_stm32.c b/drivers/usb_c/tcpc/ucpd_stm32.c index 75ee619bef7..45c514e7bf8 100644 --- a/drivers/usb_c/tcpc/ucpd_stm32.c +++ b/drivers/usb_c/tcpc/ucpd_stm32.c @@ -1382,6 +1382,20 @@ static int ucpd_init(const struct device *dev) /* Enable UCPD port */ LL_UCPD_Enable(config->ucpd_port); + /* Enable Dead Battery Support */ + if (config->ucpd_dead_battery) { +#ifdef CONFIG_SOC_SERIES_STM32G0X + uint32_t cr; + + cr = LL_UCPD_ReadReg(config->ucpd_port, CR); + cr |= UCPD_CR_DBATTEN; + LL_UCPD_WriteReg(config->ucpd_port, CR, cr); + update_stm32g0x_cc_line(config->ucpd_port); +#else + CLEAR_BIT(PWR->CR3, PWR_CR3_UCPD_DBDIS); +#endif + } + /* Initialize the isr */ ucpd_isr_init(dev); } else { @@ -1445,6 +1459,7 @@ BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) > 0, .ucpd_params.transwin = DT_INST_PROP(inst, transwin) - 1, \ .ucpd_params.IfrGap = DT_INST_PROP(inst, ifrgap) - 1, \ .ucpd_params.HbitClockDiv = DT_INST_PROP(inst, hbitclkdiv) - 1, \ + .ucpd_dead_battery = DT_INST_PROP(inst, dead_battery), \ }; \ DEVICE_DT_INST_DEFINE(inst, \ &ucpd_init, \ diff --git a/drivers/usb_c/tcpc/ucpd_stm32_priv.h b/drivers/usb_c/tcpc/ucpd_stm32_priv.h index c1c8c8633ed..727524c1519 100644 --- a/drivers/usb_c/tcpc/ucpd_stm32_priv.h +++ b/drivers/usb_c/tcpc/ucpd_stm32_priv.h @@ -84,6 +84,12 @@ UCPD_ICR_TXMSGSENTCF | \ UCPD_ICR_TXMSGDISCCF) +/** + * @brief For STM32G0X devices, this macro enables + * Dead Battery functionality + */ +#define UCPD_CR_DBATTEN BIT(15) + /** * @brief Map UCPD ANASUB value to TCPC RP value * @@ -259,6 +265,8 @@ struct tcpc_config { UCPD_TypeDef *ucpd_port; /* STM32 UCPD parameters */ LL_UCPD_InitTypeDef ucpd_params; + /* STM32 UCPD dead battery support */ + bool ucpd_dead_battery; }; /** diff --git a/dts/bindings/tcpc/st,stm32-ucpd.yaml b/dts/bindings/tcpc/st,stm32-ucpd.yaml index 0e0104a5e89..8d49b78a31a 100644 --- a/dts/bindings/tcpc/st,stm32-ucpd.yaml +++ b/dts/bindings/tcpc/st,stm32-ucpd.yaml @@ -63,6 +63,12 @@ properties: half-bit clock (hbit_clk) Valid range: 1 - 64 + dead-battery: + type: boolean + description: | + Determine if USB-C Dead Battery pull-down's should be + applied to the CC lines. + pinctrl-0: required: true