12
12
#include <zephyr/logging/log.h>
13
13
#include <zephyr/irq.h>
14
14
#include <zephyr/drivers/i2c.h>
15
+ #include <zephyr/drivers/pinctrl.h>
15
16
16
17
#ifdef CONFIG_I2C_OMAP_BUS_RECOVERY
17
18
#include "i2c_bitbang.h"
@@ -104,6 +105,7 @@ struct i2c_omap_cfg {
104
105
DEVICE_MMIO_NAMED_ROM (base );
105
106
uint32_t irq ;
106
107
uint32_t speed ;
108
+ const struct pinctrl_dev_config * pcfg ;
107
109
};
108
110
109
111
enum i2c_omap_speed {
@@ -680,6 +682,13 @@ static int i2c_omap_init(const struct device *dev)
680
682
{
681
683
struct i2c_omap_data * data = DEV_DATA (dev );
682
684
const struct i2c_omap_cfg * cfg = DEV_CFG (dev );
685
+ int ret ;
686
+
687
+ ret = pinctrl_apply_state (cfg -> pcfg , PINCTRL_STATE_DEFAULT );
688
+ if (ret < 0 ) {
689
+ LOG_ERR ("failed to apply pinctrl" );
690
+ return ret ;
691
+ }
683
692
684
693
k_sem_init (& data -> lock , 1 , 1 );
685
694
/* Set the speed for I2C */
@@ -692,17 +701,24 @@ static int i2c_omap_init(const struct device *dev)
692
701
}
693
702
694
703
#define I2C_OMAP_INIT (inst ) \
704
+ PINCTRL_DT_INST_DEFINE(inst); \
695
705
LOG_INSTANCE_REGISTER(omap_i2c, inst, CONFIG_I2C_LOG_LEVEL); \
696
706
static const struct i2c_omap_cfg i2c_omap_cfg_##inst = { \
697
707
DEVICE_MMIO_NAMED_ROM_INIT(base, DT_DRV_INST(inst)), \
698
708
.irq = DT_INST_IRQN(inst), \
699
709
.speed = DT_INST_PROP(inst, clock_frequency), \
710
+ .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
700
711
}; \
701
712
\
702
713
static struct i2c_omap_data i2c_omap_data_##inst; \
703
714
\
704
- I2C_DEVICE_DT_INST_DEFINE(inst, i2c_omap_init, NULL, &i2c_omap_data_##inst, \
705
- &i2c_omap_cfg_##inst, POST_KERNEL, CONFIG_I2C_INIT_PRIORITY, \
706
- &i2c_omap_api);
715
+ I2C_DEVICE_DT_INST_DEFINE(inst, \
716
+ i2c_omap_init, \
717
+ NULL, \
718
+ &i2c_omap_data_##inst, \
719
+ &i2c_omap_cfg_##inst, \
720
+ POST_KERNEL, \
721
+ CONFIG_I2C_INIT_PRIORITY, \
722
+ &i2c_omap_api);
707
723
708
724
DT_INST_FOREACH_STATUS_OKAY (I2C_OMAP_INIT )
0 commit comments