8
8
#include <zephyr/drivers/pwm.h>
9
9
#include <soc.h>
10
10
#include <device_imx.h>
11
+ #include <drivers/pinctrl.h>
11
12
12
13
#define LOG_LEVEL CONFIG_PWM_LOG_LEVEL
13
14
#include <zephyr/logging/log.h>
@@ -24,6 +25,7 @@ LOG_MODULE_REGISTER(pwm_imx);
24
25
struct imx_pwm_config {
25
26
PWM_Type * base ;
26
27
uint16_t prescaler ;
28
+ const struct pinctrl_dev_config * pincfg ;
27
29
};
28
30
29
31
struct imx_pwm_data {
@@ -140,9 +142,16 @@ static int imx_pwm_set_cycles(const struct device *dev, uint32_t channel,
140
142
141
143
static int imx_pwm_init (const struct device * dev )
142
144
{
145
+ const struct imx_pwm_config * config = dev -> config ;
143
146
struct imx_pwm_data * data = dev -> data ;
147
+ int err ;
144
148
PWM_Type * base = DEV_BASE (dev );
145
149
150
+ err = pinctrl_apply_state (config -> pincfg , PINCTRL_STATE_DEFAULT );
151
+ if (err ) {
152
+ return err ;
153
+ }
154
+
146
155
PWM_PWMPR_REG (base ) = data -> period_cycles ;
147
156
148
157
return 0 ;
@@ -154,9 +163,11 @@ static const struct pwm_driver_api imx_pwm_driver_api = {
154
163
};
155
164
156
165
#define PWM_IMX_INIT (n ) \
166
+ PINCTRL_DT_INST_DEFINE(n); \
157
167
static const struct imx_pwm_config imx_pwm_config_##n = { \
158
168
.base = (PWM_Type *)DT_INST_REG_ADDR(n), \
159
169
.prescaler = DT_INST_PROP(n, prescaler), \
170
+ .pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
160
171
}; \
161
172
\
162
173
static struct imx_pwm_data imx_pwm_data_##n; \
0 commit comments