drivers: pwm: rv32m1: tpm: add pinctrl support
Add pinctrl support to the OpenISA RV32M1 TPM PWM driver. Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
This commit is contained in:
parent
c83a0d5d1f
commit
64c9fadc7c
2 changed files with 27 additions and 1 deletions
|
@ -15,6 +15,9 @@
|
|||
#include <soc.h>
|
||||
#include <fsl_tpm.h>
|
||||
#include <fsl_clock.h>
|
||||
#ifdef CONFIG_PINCTRL
|
||||
#include <drivers/pinctrl.h>
|
||||
#endif
|
||||
|
||||
#define LOG_LEVEL CONFIG_PWM_LOG_LEVEL
|
||||
#include <logging/log.h>
|
||||
|
@ -30,6 +33,9 @@ struct rv32m1_tpm_config {
|
|||
tpm_clock_prescale_t prescale;
|
||||
uint8_t channel_count;
|
||||
tpm_pwm_mode_t mode;
|
||||
#ifdef CONFIG_PINCTRL
|
||||
const struct pinctrl_dev_config *pincfg;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct rv32m1_tpm_data {
|
||||
|
@ -131,6 +137,9 @@ static int rv32m1_tpm_init(const struct device *dev)
|
|||
struct rv32m1_tpm_data *data = dev->data;
|
||||
tpm_chnl_pwm_signal_param_t *channel = data->channel;
|
||||
tpm_config_t tpm_config;
|
||||
#ifdef CONFIG_PINCTRL
|
||||
int err;
|
||||
#endif
|
||||
int i;
|
||||
|
||||
if (config->channel_count > ARRAY_SIZE(data->channel)) {
|
||||
|
@ -157,6 +166,13 @@ static int rv32m1_tpm_init(const struct device *dev)
|
|||
channel++;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PINCTRL
|
||||
err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
TPM_GetDefaultConfig(&tpm_config);
|
||||
tpm_config.prescale = config->prescale;
|
||||
|
||||
|
@ -170,7 +186,16 @@ static const struct pwm_driver_api rv32m1_tpm_driver_api = {
|
|||
.get_cycles_per_sec = rv32m1_tpm_get_cycles_per_sec,
|
||||
};
|
||||
|
||||
#ifdef CONFIG_PINCTRL
|
||||
#define PINCTRL_INIT(n) .pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n),
|
||||
#define PINCTRL_DEFINE(n) PINCTRL_DT_INST_DEFINE(n);
|
||||
#else
|
||||
#define PINCTRL_DEFINE(n)
|
||||
#define PINCTRL_INIT(n)
|
||||
#endif
|
||||
|
||||
#define TPM_DEVICE(n) \
|
||||
PINCTRL_DEFINE(n) \
|
||||
static const struct rv32m1_tpm_config rv32m1_tpm_config_##n = { \
|
||||
.base = (TPM_Type *) \
|
||||
DT_INST_REG_ADDR(n), \
|
||||
|
@ -182,6 +207,7 @@ static const struct pwm_driver_api rv32m1_tpm_driver_api = {
|
|||
.channel_count = FSL_FEATURE_TPM_CHANNEL_COUNTn((TPM_Type *) \
|
||||
DT_INST_REG_ADDR(n)), \
|
||||
.mode = kTPM_EdgeAlignedPwm, \
|
||||
PINCTRL_INIT(n) \
|
||||
}; \
|
||||
static struct rv32m1_tpm_data rv32m1_tpm_data_##n; \
|
||||
DEVICE_DT_INST_DEFINE(n, &rv32m1_tpm_init, NULL, \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue