1616#include <soc.h>
1717#include <fsl_tpm.h>
1818#include <fsl_clock.h>
19+ #include <drivers/pinctrl.h>
1920
2021#define LOG_LEVEL CONFIG_PWM_LOG_LEVEL
2122#include <logging/log.h>
@@ -31,6 +32,7 @@ struct mcux_tpm_config {
3132 tpm_clock_prescale_t prescale ;
3233 uint8_t channel_count ;
3334 tpm_pwm_mode_t mode ;
35+ const struct pinctrl_dev_config * pincfg ;
3436};
3537
3638struct mcux_tpm_data {
@@ -134,6 +136,7 @@ static int mcux_tpm_init(const struct device *dev)
134136 tpm_chnl_pwm_signal_param_t * channel = data -> channel ;
135137 tpm_config_t tpm_config ;
136138 int i ;
139+ int err ;
137140
138141 if (config -> channel_count > ARRAY_SIZE (data -> channel )) {
139142 LOG_ERR ("Invalid channel count" );
@@ -159,6 +162,11 @@ static int mcux_tpm_init(const struct device *dev)
159162 channel ++ ;
160163 }
161164
165+ err = pinctrl_apply_state (config -> pincfg , PINCTRL_STATE_DEFAULT );
166+ if (err ) {
167+ return err ;
168+ }
169+
162170 TPM_GetDefaultConfig (& tpm_config );
163171 tpm_config .prescale = config -> prescale ;
164172
@@ -173,6 +181,7 @@ static const struct pwm_driver_api mcux_tpm_driver_api = {
173181};
174182
175183#define TPM_DEVICE (n ) \
184+ PINCTRL_DT_INST_DEFINE(n); \
176185 static const struct mcux_tpm_config mcux_tpm_config_##n = { \
177186 .base = (TPM_Type *) \
178187 DT_INST_REG_ADDR(n), \
@@ -184,6 +193,7 @@ static const struct pwm_driver_api mcux_tpm_driver_api = {
184193 .channel_count = FSL_FEATURE_TPM_CHANNEL_COUNTn((TPM_Type *) \
185194 DT_INST_REG_ADDR(n)), \
186195 .mode = kTPM_EdgeAlignedPwm, \
196+ .pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
187197 }; \
188198 static struct mcux_tpm_data mcux_tpm_data_##n; \
189199 DEVICE_DT_INST_DEFINE(n, &mcux_tpm_init, NULL, \
0 commit comments