diff --git a/drivers/i2c/i2c_rv32m1_lpi2c.c b/drivers/i2c/i2c_rv32m1_lpi2c.c index 847ed78362..c6b54f5b51 100644 --- a/drivers/i2c/i2c_rv32m1_lpi2c.c +++ b/drivers/i2c/i2c_rv32m1_lpi2c.c @@ -14,6 +14,10 @@ #include #include #include +#ifdef CONFIG_PINCTRL +#include +#endif + LOG_MODULE_REGISTER(rv32m1_lpi2c); #include "i2c-priv.h" @@ -26,6 +30,9 @@ struct rv32m1_lpi2c_config { uint32_t clock_ip_src; uint32_t bitrate; void (*irq_config_func)(const struct device *dev); +#ifdef CONFIG_PINCTRL + const struct pinctrl_dev_config *pincfg; +#endif }; struct rv32m1_lpi2c_data { @@ -235,6 +242,12 @@ static int rv32m1_lpi2c_init(const struct device *dev) return err; } +#ifdef CONFIG_PINCTRL + err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); + if (err != 0) { + return err; + } +#endif config->irq_config_func(dev); return 0; @@ -245,7 +258,16 @@ static const struct i2c_driver_api rv32m1_lpi2c_driver_api = { .transfer = rv32m1_lpi2c_transfer, }; +#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 RV32M1_LPI2C_DEVICE(id) \ + PINCTRL_DEFINE(id) \ static void rv32m1_lpi2c_irq_config_func_##id(const struct device *dev); \ static const struct rv32m1_lpi2c_config rv32m1_lpi2c_##id##_config = { \ .base = \ @@ -257,6 +279,7 @@ static const struct i2c_driver_api rv32m1_lpi2c_driver_api = { .clock_ip_src = kCLOCK_IpSrcFircAsync, \ .bitrate = DT_INST_PROP(id, clock_frequency), \ .irq_config_func = rv32m1_lpi2c_irq_config_func_##id, \ + PINCTRL_INIT(id) \ }; \ static struct rv32m1_lpi2c_data rv32m1_lpi2c_##id##_data = { \ .transfer_sync = Z_SEM_INITIALIZER( \ diff --git a/dts/bindings/i2c/openisa,rv32m1-lpi2c.yaml b/dts/bindings/i2c/openisa,rv32m1-lpi2c.yaml index 53fbf75ffa..cf57502460 100644 --- a/dts/bindings/i2c/openisa,rv32m1-lpi2c.yaml +++ b/dts/bindings/i2c/openisa,rv32m1-lpi2c.yaml @@ -5,7 +5,7 @@ description: OpenISA LPI2C controller compatible: "openisa,rv32m1-lpi2c" -include: i2c-controller.yaml +include: [i2c-controller.yaml, pinctrl-device.yaml] properties: reg: