drivers: i2c: i2c_dw: added pinctrl support

added pinctrl support for designware i2c driver

Signed-off-by: Andrei-Edward Popa <andrei_edward.popa@upb.ro>
This commit is contained in:
Andrei-Edward Popa 2022-02-08 12:49:50 +02:00 committed by Anas Nashif
commit e1f91db622
2 changed files with 30 additions and 2 deletions

View file

@ -2,6 +2,7 @@
/*
* Copyright (c) 2015 Intel Corporation
* Copyright (c) 2022 Andrei-Edward Popa
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -17,6 +18,10 @@
#include <arch/cpu.h>
#include <string.h>
#if defined(CONFIG_PINCTRL)
#include <drivers/pinctrl.h>
#endif
#include <soc.h>
#include <errno.h>
#include <sys/sys_io.h>
@ -615,6 +620,14 @@ static int i2c_dw_initialize(const struct device *dev)
struct i2c_dw_dev_config * const dw = dev->data;
union ic_con_register ic_con;
uint32_t reg_base = get_regs(dev);
int ret = 0;
#if defined(CONFIG_PINCTRL)
ret = pinctrl_apply_state(rom->pcfg, PINCTRL_STATE_DEFAULT);
if (ret) {
return ret;
}
#endif
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(pcie)
if (rom->pcie) {
@ -669,9 +682,17 @@ static int i2c_dw_initialize(const struct device *dev)
dw->state = I2C_DW_STATE_READY;
return 0;
return ret;
}
#if defined(CONFIG_PINCTRL)
#define PINCTRL_DW_DEFINE(n) PINCTRL_DT_INST_DEFINE(n)
#define PINCTRL_DW_CONFIG(n) .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n),
#else
#define PINCTRL_DW_DEFINE(n)
#define PINCTRL_DW_CONFIG(n)
#endif
#define I2C_DW_INIT_PCIE0(n)
#define I2C_DW_INIT_PCIE1(n) \
.pcie = true, \
@ -721,15 +742,17 @@ static int i2c_dw_initialize(const struct device *dev)
_CONCAT(I2C_DW_IRQ_CONFIG_PCIE, DT_INST_ON_BUS(n, pcie))(n)
#define I2C_DEVICE_INIT_DW(n) \
PINCTRL_DW_DEFINE(n); \
static void i2c_config_##n(const struct device *port); \
static const struct i2c_dw_rom_config i2c_config_dw_##n = { \
DEVICE_MMIO_ROM_INIT(DT_DRV_INST(n)), \
.config_func = i2c_config_##n, \
.bitrate = DT_INST_PROP(n, clock_frequency), \
PINCTRL_DW_CONFIG(n) \
I2C_DW_INIT_PCIE(n) \
}; \
static struct i2c_dw_dev_config i2c_##n##_runtime; \
I2C_DEVICE_DT_INST_DEFINE(n, i2c_dw_initialize, NULL, \
I2C_DEVICE_DT_INST_DEFINE(n, i2c_dw_initialize, NULL, \
&i2c_##n##_runtime, &i2c_config_dw_##n, \
POST_KERNEL, CONFIG_I2C_INIT_PRIORITY, \
&funcs); \

View file

@ -89,6 +89,11 @@ struct i2c_dw_rom_config {
DEVICE_MMIO_ROM;
i2c_isr_cb_t config_func;
uint32_t bitrate;
#if defined(CONFIG_PINCTRL)
const struct pinctrl_dev_config *pcfg;
#endif
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(pcie)
bool pcie;
pcie_bdf_t pcie_bdf;