Skip to content

Commit 68dc1b5

Browse files
dnltzkartben
authored andcommitted
drivers: i2c: i2c_omap: Add pinctrl
Extend the I2c OMAP driver to automatically mux pins require by this interfaces. Signed-off-by: Daniel Schultz <d.schultz@phytec.de>
1 parent d7eab21 commit 68dc1b5

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

drivers/i2c/Kconfig.omap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ config I2C_OMAP
77
bool "TI OMAP I2C Driver"
88
default y
99
depends on DT_HAS_TI_OMAP_I2C_ENABLED
10+
select PINCTRL
1011
help
1112
Enable the I2C driver for TI OMAP SoCs.
1213

drivers/i2c/i2c_omap.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <zephyr/logging/log.h>
1313
#include <zephyr/irq.h>
1414
#include <zephyr/drivers/i2c.h>
15+
#include <zephyr/drivers/pinctrl.h>
1516

1617
#ifdef CONFIG_I2C_OMAP_BUS_RECOVERY
1718
#include "i2c_bitbang.h"
@@ -104,6 +105,7 @@ struct i2c_omap_cfg {
104105
DEVICE_MMIO_NAMED_ROM(base);
105106
uint32_t irq;
106107
uint32_t speed;
108+
const struct pinctrl_dev_config *pcfg;
107109
};
108110

109111
enum i2c_omap_speed {
@@ -680,6 +682,13 @@ static int i2c_omap_init(const struct device *dev)
680682
{
681683
struct i2c_omap_data *data = DEV_DATA(dev);
682684
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+
}
683692

684693
k_sem_init(&data->lock, 1, 1);
685694
/* Set the speed for I2C */
@@ -692,17 +701,24 @@ static int i2c_omap_init(const struct device *dev)
692701
}
693702

694703
#define I2C_OMAP_INIT(inst) \
704+
PINCTRL_DT_INST_DEFINE(inst); \
695705
LOG_INSTANCE_REGISTER(omap_i2c, inst, CONFIG_I2C_LOG_LEVEL); \
696706
static const struct i2c_omap_cfg i2c_omap_cfg_##inst = { \
697707
DEVICE_MMIO_NAMED_ROM_INIT(base, DT_DRV_INST(inst)), \
698708
.irq = DT_INST_IRQN(inst), \
699709
.speed = DT_INST_PROP(inst, clock_frequency), \
710+
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
700711
}; \
701712
\
702713
static struct i2c_omap_data i2c_omap_data_##inst; \
703714
\
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);
707723

708724
DT_INST_FOREACH_STATUS_OKAY(I2C_OMAP_INIT)

0 commit comments

Comments
 (0)