drivers: i2c_imx: add pin control support
Add pin control support to i2c_imx driver. Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
This commit is contained in:
parent
c4a7985064
commit
7299a2994a
2 changed files with 11 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Diego Sueiro, <diego.sueiro@gmail.com>
|
* Copyright (c) 2018 Diego Sueiro, <diego.sueiro@gmail.com>
|
||||||
|
* Copyright 2022 NXP
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
@ -11,6 +12,7 @@
|
||||||
#include <soc.h>
|
#include <soc.h>
|
||||||
#include <i2c_imx.h>
|
#include <i2c_imx.h>
|
||||||
#include <zephyr/sys/util.h>
|
#include <zephyr/sys/util.h>
|
||||||
|
#include <zephyr/drivers/pinctrl.h>
|
||||||
|
|
||||||
#include <zephyr/logging/log.h>
|
#include <zephyr/logging/log.h>
|
||||||
LOG_MODULE_REGISTER(i2c_imx);
|
LOG_MODULE_REGISTER(i2c_imx);
|
||||||
|
@ -24,6 +26,7 @@ struct i2c_imx_config {
|
||||||
I2C_Type *base;
|
I2C_Type *base;
|
||||||
void (*irq_config_func)(const struct device *dev);
|
void (*irq_config_func)(const struct device *dev);
|
||||||
uint32_t bitrate;
|
uint32_t bitrate;
|
||||||
|
const struct pinctrl_dev_config *pincfg;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct i2c_master_transfer {
|
struct i2c_master_transfer {
|
||||||
|
@ -339,6 +342,11 @@ static int i2c_imx_init(const struct device *dev)
|
||||||
|
|
||||||
k_sem_init(&data->device_sync_sem, 0, K_SEM_MAX_LIMIT);
|
k_sem_init(&data->device_sync_sem, 0, K_SEM_MAX_LIMIT);
|
||||||
|
|
||||||
|
error = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT);
|
||||||
|
if (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
bitrate_cfg = i2c_map_dt_bitrate(config->bitrate);
|
bitrate_cfg = i2c_map_dt_bitrate(config->bitrate);
|
||||||
|
|
||||||
error = i2c_imx_configure(dev, I2C_MODE_MASTER | bitrate_cfg);
|
error = i2c_imx_configure(dev, I2C_MODE_MASTER | bitrate_cfg);
|
||||||
|
@ -357,12 +365,14 @@ static const struct i2c_driver_api i2c_imx_driver_api = {
|
||||||
};
|
};
|
||||||
|
|
||||||
#define I2C_IMX_INIT(n) \
|
#define I2C_IMX_INIT(n) \
|
||||||
|
PINCTRL_DT_INST_DEFINE(n); \
|
||||||
static void i2c_imx_config_func_##n(const struct device *dev); \
|
static void i2c_imx_config_func_##n(const struct device *dev); \
|
||||||
\
|
\
|
||||||
static const struct i2c_imx_config i2c_imx_config_##n = { \
|
static const struct i2c_imx_config i2c_imx_config_##n = { \
|
||||||
.base = (I2C_Type *)DT_INST_REG_ADDR(n), \
|
.base = (I2C_Type *)DT_INST_REG_ADDR(n), \
|
||||||
.irq_config_func = i2c_imx_config_func_##n, \
|
.irq_config_func = i2c_imx_config_func_##n, \
|
||||||
.bitrate = DT_INST_PROP(n, clock_frequency), \
|
.bitrate = DT_INST_PROP(n, clock_frequency), \
|
||||||
|
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
static struct i2c_imx_data i2c_imx_data_##n; \
|
static struct i2c_imx_data i2c_imx_data_##n; \
|
||||||
|
|
|
@ -5,7 +5,7 @@ description: i.MX I2C node
|
||||||
|
|
||||||
compatible: "fsl,imx21-i2c"
|
compatible: "fsl,imx21-i2c"
|
||||||
|
|
||||||
include: i2c-controller.yaml
|
include: [i2c-controller.yaml, pinctrl-device.yaml]
|
||||||
|
|
||||||
properties:
|
properties:
|
||||||
reg:
|
reg:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue