drivers: i2c: add pinctrl driver support
Replace soc-specific pin functions with Zephyr pinctrl api functions for pin-mux configuration in i2c driver. Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
This commit is contained in:
parent
8efc935288
commit
a4b07c396d
7 changed files with 45 additions and 23 deletions
|
@ -31,6 +31,7 @@
|
|||
#include <assert.h>
|
||||
#include <zephyr/drivers/clock_control.h>
|
||||
#include <zephyr/drivers/i2c.h>
|
||||
#include <zephyr/drivers/pinctrl.h>
|
||||
#include <zephyr/dt-bindings/i2c/i2c.h>
|
||||
#include <soc.h>
|
||||
|
||||
|
@ -42,12 +43,11 @@ LOG_MODULE_REGISTER(i2c_npcx_port, LOG_LEVEL_ERR);
|
|||
|
||||
/* Device config */
|
||||
struct i2c_npcx_port_config {
|
||||
/* pinmux configuration */
|
||||
const uint8_t alts_size;
|
||||
const struct npcx_alt *alts_list;
|
||||
uint32_t bitrate;
|
||||
uint8_t port;
|
||||
const struct device *i2c_ctrl;
|
||||
/* pinmux configuration */
|
||||
const struct pinctrl_dev_config *pcfg;
|
||||
};
|
||||
|
||||
/* I2C api functions */
|
||||
|
@ -131,7 +131,12 @@ static int i2c_npcx_port_init(const struct device *dev)
|
|||
int ret;
|
||||
|
||||
/* Configure pin-mux for I2C device */
|
||||
npcx_pinctrl_mux_configure(config->alts_list, config->alts_size, 1);
|
||||
ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("I2C pinctrl setup failed (%d)", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* Setup initial i2c configuration */
|
||||
i2c_config = (I2C_MODE_MASTER | i2c_map_dt_bitrate(config->bitrate));
|
||||
|
@ -151,15 +156,13 @@ static const struct i2c_driver_api i2c_port_npcx_driver_api = {
|
|||
|
||||
/* I2C port init macro functions */
|
||||
#define NPCX_I2C_PORT_INIT(inst) \
|
||||
static const struct npcx_alt i2c_port_alts##inst[] = \
|
||||
NPCX_DT_ALT_ITEMS_LIST(inst); \
|
||||
PINCTRL_DT_INST_DEFINE(inst); \
|
||||
\
|
||||
static const struct i2c_npcx_port_config i2c_npcx_port_cfg_##inst = { \
|
||||
.port = DT_INST_PROP(inst, port), \
|
||||
.bitrate = DT_INST_PROP(inst, clock_frequency), \
|
||||
.alts_size = ARRAY_SIZE(i2c_port_alts##inst), \
|
||||
.alts_list = i2c_port_alts##inst, \
|
||||
.i2c_ctrl = DEVICE_DT_GET(DT_INST_PHANDLE(inst, controller)), \
|
||||
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
|
||||
}; \
|
||||
\
|
||||
DEVICE_DT_INST_DEFINE(inst, \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue