From 99e07709ffcacf509e6dce84b3c8975a61cd5120 Mon Sep 17 00:00:00 2001 From: Sam Hurst Date: Sat, 14 May 2022 11:54:31 -0700 Subject: [PATCH] boards: arm: Update STM32 UCPD nodes with pin control Assign the pins for the STM32G071b and STM32G081b STM32 UCPD peripherals so the UCPD driver can properly configure the device. Signed-off-by: Sam Hurst --- boards/arm/stm32g071b_disco/stm32g071b_disco.dts | 2 ++ boards/arm/stm32g081b_eval/stm32g081b_eval.dts | 2 ++ drivers/usb_c/tcpc/ucpd_stm32.c | 11 ++++++++++- drivers/usb_c/tcpc/ucpd_stm32_priv.h | 3 +++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/boards/arm/stm32g071b_disco/stm32g071b_disco.dts b/boards/arm/stm32g071b_disco/stm32g071b_disco.dts index e96f97e2cbe..1668c353c4d 100644 --- a/boards/arm/stm32g071b_disco/stm32g071b_disco.dts +++ b/boards/arm/stm32g071b_disco/stm32g071b_disco.dts @@ -177,6 +177,8 @@ */ psc-ucpdclk = <1>; hbitclkdiv = <27>; + pinctrl-0 = <&ucpd1_cc1_pa8 &ucpd1_cc2_pb15>; + pinctrl-names = "default"; }; &iwdg { diff --git a/boards/arm/stm32g081b_eval/stm32g081b_eval.dts b/boards/arm/stm32g081b_eval/stm32g081b_eval.dts index 796290a4138..2b92deedaac 100644 --- a/boards/arm/stm32g081b_eval/stm32g081b_eval.dts +++ b/boards/arm/stm32g081b_eval/stm32g081b_eval.dts @@ -156,6 +156,8 @@ */ psc-ucpdclk = <1>; hbitclkdiv = <27>; + pinctrl-0 = <&ucpd2_cc1_pd0 &ucpd2_cc2_pd2>; + pinctrl-names = "default"; }; &iwdg { diff --git a/drivers/usb_c/tcpc/ucpd_stm32.c b/drivers/usb_c/tcpc/ucpd_stm32.c index 46b27a7e49a..1f46c09bef0 100644 --- a/drivers/usb_c/tcpc/ucpd_stm32.c +++ b/drivers/usb_c/tcpc/ucpd_stm32.c @@ -15,7 +15,7 @@ LOG_MODULE_REGISTER(ucpd_stm32, CONFIG_USBC_LOG_LEVEL); #include #include #include -#include +#include #include #include "ucpd_stm32_priv.h" @@ -1375,6 +1375,13 @@ static int ucpd_init(const struct device *dev) uint32_t cfg1; int ret; + LOG_DBG("Pinctrl signals configuration"); + ret = pinctrl_apply_state(config->ucpd_pcfg, PINCTRL_STATE_DEFAULT); + if (ret < 0) { + LOG_ERR("USB pinctrl setup failed (%d)", ret); + return ret; + } + /* * The UCPD port is disabled in the LL_UCPD_Init function * @@ -1459,8 +1466,10 @@ BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) > 0, "No compatible STM32 TCPC instance found"); #define TCPC_DRIVER_INIT(inst) \ + PINCTRL_DT_INST_DEFINE(inst); \ static struct tcpc_data drv_data_##inst; \ static const struct tcpc_config drv_config_##inst = { \ + .ucpd_pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \ .ucpd_port = (UCPD_TypeDef *)DT_INST_REG_ADDR(inst), \ .ucpd_params.psc_ucpdclk = ilog2(DT_INST_PROP(inst, psc_ucpdclk)), \ .ucpd_params.transwin = DT_INST_PROP(inst, transwin) - 1, \ diff --git a/drivers/usb_c/tcpc/ucpd_stm32_priv.h b/drivers/usb_c/tcpc/ucpd_stm32_priv.h index 58f70b6faaf..29f743dca2d 100644 --- a/drivers/usb_c/tcpc/ucpd_stm32_priv.h +++ b/drivers/usb_c/tcpc/ucpd_stm32_priv.h @@ -9,6 +9,7 @@ #include #include +#include #include /** @@ -251,6 +252,8 @@ struct alert_info { * @brief Driver config */ struct tcpc_config { + /* STM32 UCPC CC pin control */ + const struct pinctrl_dev_config *ucpd_pcfg; /* STM32 UCPD port */ UCPD_TypeDef *ucpd_port; /* STM32 UCPD parameters */