Skip to content

Commit c29b602

Browse files
danieldegrassecarlescufi
authored andcommitted
drivers: pwm: add pinctrl support to kinetis tpm driver
add pinctrl support for kinetis tpm driver Signed-off-by: Daniel DeGrasse <[email protected]>
1 parent 88fc9fb commit c29b602

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

drivers/pwm/Kconfig.mcux_tpm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
config PWM_MCUX_TPM
77
bool "MCUX TPM PWM driver"
88
depends on HAS_MCUX_TPM && CLOCK_CONTROL
9+
select PINCTRL
910
help
1011
Enable the MCUX TPM PWM driver.

drivers/pwm/pwm_mcux_tpm.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
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

3638
struct 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, \

dts/bindings/pwm/nxp,kinetis-tpm.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: MCUX Timer/PWM Module (TPM)
55

66
compatible: "nxp,kinetis-tpm"
77

8-
include: [pwm-controller.yaml, base.yaml]
8+
include: [pwm-controller.yaml, base.yaml, pinctrl-device.yaml]
99

1010
properties:
1111
reg:

0 commit comments

Comments
 (0)